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.
This commit is contained in:
Javi Martín
2023-09-08 12:54:38 +02:00
parent aef78ee6f6
commit fc0511f4d3
2 changed files with 4 additions and 3 deletions

View File

@@ -561,6 +561,9 @@ RSpec/Rails/HaveHttpStatus:
RSpec/Rails/InferredSpecType: RSpec/Rails/InferredSpecType:
Enabled: true Enabled: true
RSpec/Rails/TravelAround:
Enabled: true
RSpec/RepeatedExample: RSpec/RepeatedExample:
Enabled: true Enabled: true

View File

@@ -148,9 +148,7 @@ RSpec.configure do |config|
.to receive(:locales).and_return(I18n.available_locales.map(&:to_s)) .to receive(:locales).and_return(I18n.available_locales.map(&:to_s))
end end
config.around(:each, :with_frozen_time) do |example| config.before(:each, :with_frozen_time) { freeze_time }
freeze_time { example.run }
end
config.before(:each, :application_zone_west_of_system_zone) do config.before(:each, :application_zone_west_of_system_zone) do
application_zone = ActiveSupport::TimeZone.new("Quito") application_zone = ActiveSupport::TimeZone.new("Quito")