-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RSpec/Rails/TravelAround
and RSpec/RedundantAround
cops
#1503
Conversation
If I recall it correctly, |
Oh, it's true. There are cases where
So, would it be better to add the above explanation and set |
If the cop is focused to specs with Rails metadata it might be fine.
|
RSpec/Rails/FreezeTimeAround
and RSpec/RedundantAround
copsRSpec/Rails/TravelAround
and RSpec/RedundantAround
cops
I see. Based on the background above, I agree to set |
0e58c9a
to
fdb58d0
Compare
5bb06a8
to
fbbac37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
No errors, and offences look legit:
/Users/pirj/source/real-world-rspec/gitlabhq/spec/spec_helper.rb:258:3: C: [Correctable] RSpec/RedundantAround: Remove redundant around hook.
config.around do |example| ...
^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/pirj/source/real-world-rspec/solidus/core/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb:23:7: C: [Correctable] RSpec/Rails/TravelAround: Prefer to travel in before rather than around.
travel_to(Time.current) { e.run }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57497 files inspected, 90 offenses detected, 90 offenses autocorrectable
5b981de
to
db99493
Compare
What happens if the example is using freeze_time, is travel_back still called automatically? In other words, can we now avoid:
and just call freeze_time in the beginning? Note that this is valid only if the block is the last thing in the example, e.g. we don't rely on time being restored for next statements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
9199fc4
to
9d7e9ed
Compare
9d7e9ed
to
9a03fb7
Compare
@r7kamura I'm sorry, there were few releases around the capybara extraction. |
9a03fb7
to
c8505ac
Compare
Thank you, @r7kamura ! |
Since Rails 5.2,
travel_back
is called automatically, so you can easily do that by just calling it inbefore
instead of usingaround
with nested blocks.In response to this change, I thought it would be a good idea to add a cop recommending the easier way when possible.
Unlike a typical Pull Request, the exception here is the addition of two cops.
RSpec/Rails/TravelAround
applies the following autocorrection:This may result in a meaningless
around
. As a measure to remove this, I have also addedRSpec/RedundantAround
cop to remove this kind of redundantaround
. I thought it would be more orthogonal to leave it to an independentcCop rather than have each cop take care of such a redundantaround
. This is why the both two cops are included in this one Pull Request.For further reference, another possible idea related to this Rails change would be to remove the redundant
travel_back
as shown below:In some cases, there may be travel-dependent hooks after this, so this would be an unsafe autocorrection.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.