time_zone.rb 706 B

1234567891011121314151617
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.configure do |config|
  3. config.around(:each, :time_zone) do |example|
  4. # RSpec System/Capybara tests use TZ environment variable to set timezone in the browser.
  5. if example.metadata[:type] == :system
  6. old_tz = ENV['TZ']
  7. ENV['TZ'] = example.metadata[:time_zone]
  8. end
  9. # Other RSpec tests run inside the same process and don't take TZ variable into account.
  10. # However, they should still have mocking of the test time zone for the Time object applied.
  11. Time.use_zone(example.metadata[:time_zone]) { example.run }
  12. ensure
  13. ENV['TZ'] = old_tz if example.metadata[:type] == :system
  14. end
  15. end