From fc0511f4d3677af40ba7e5f0aac4fb004af1d9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 8 Sep 2023 12:54:38 +0200 Subject: [PATCH] Add and appy RSpec/Rails/TravelAround rubocop rule This rule was added in rubocop-rspec 2.19.0. When freezing time in a test, `travel_back` is called automatically when the test finishes, so we can do it in a `before` block instead of an `around` block. Note this rule didn't detect our usage of `freeze_time` because we were using it on cops with a certain tag, but I expect the rule to be able to detect this usage in the future. --- .rubocop.yml | 3 +++ spec/spec_helper.rb | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index fc87323d8..1e8dc07ad 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -561,6 +561,9 @@ RSpec/Rails/HaveHttpStatus: RSpec/Rails/InferredSpecType: Enabled: true +RSpec/Rails/TravelAround: + Enabled: true + RSpec/RepeatedExample: Enabled: true diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f47bafa8d..d7a2b57fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -148,9 +148,7 @@ RSpec.configure do |config| .to receive(:locales).and_return(I18n.available_locales.map(&:to_s)) end - config.around(:each, :with_frozen_time) do |example| - freeze_time { example.run } - end + config.before(:each, :with_frozen_time) { freeze_time } config.before(:each, :application_zone_west_of_system_zone) do application_zone = ActiveSupport::TimeZone.new("Quito")