2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-10-21 11:03:54 +00:00
|
|
|
RSpec.configure do |config|
|
|
|
|
config.around(:each, :time_zone) do |example|
|
2021-02-15 13:55:00 +00:00
|
|
|
if example.metadata[:type] == :system
|
2021-07-06 18:40:09 +00:00
|
|
|
# RSpec System/Capybara tests use TZ variable to set timezone in browser
|
2021-02-15 13:55:00 +00:00
|
|
|
old_tz = ENV['TZ']
|
|
|
|
ENV['TZ'] = example.metadata[:time_zone]
|
2019-10-21 11:03:54 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
example.run
|
|
|
|
else
|
2021-07-06 18:40:09 +00:00
|
|
|
# Other RSpec tests run inside of the same process and don't take TZ into account.
|
|
|
|
# Mocking time zone via Time object is enough
|
2021-02-15 13:55:00 +00:00
|
|
|
Time.use_zone(example.metadata[:time_zone]) { example.run }
|
|
|
|
end
|
2019-10-21 11:03:54 +00:00
|
|
|
ensure
|
2021-02-15 13:55:00 +00:00
|
|
|
ENV['TZ'] = old_tz if example.metadata[:type] == :system
|
2019-10-21 11:03:54 +00:00
|
|
|
end
|
|
|
|
end
|