time_zone.rb 669 B

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