Skip to content
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

Rails/RedundantTravelBack should not auto-correct #579

Closed
katelovescode opened this issue Oct 29, 2021 · 7 comments
Closed

Rails/RedundantTravelBack should not auto-correct #579

katelovescode opened this issue Oct 29, 2021 · 7 comments

Comments

@katelovescode
Copy link

katelovescode commented Oct 29, 2021

I've turned off Rails/RedundantTravelBack because it's auto-corrected and on by default, but the after_teardown hook is only called in Minitest, not in RSpec, from what I can tell. So my travel_backs are getting removed even though I use Rspec and need them. Given that we can initialize Rails without Minitest, does it make sense to make this clearer in documentation and/or not autocorrect this particular cop? It seems like this behavior, even though it's built into part of Rails, is more Minitest-specific.

Since this lives at the intersection of Rails and RSpec, I'm not sure if there's a better rubocop extension to add this to, happy to open a PR at rubocop-rspec if that makes more sense.


Expected behavior

Not remove my necessary travel_back calls

Actual behavior

Necessary travel_back calls are removed

Steps to reproduce the problem

In a Rails app using RSpec instead of minitest, put an after { travel_back } hook in a file where travel_to happens in a before block or in an expectation block. Run rubocop -a and your travel_back will be removed, and your tests will break

RuboCop version

➜ be rubocop -V
1.22.1 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 3.0.2 x86_64-darwin20)
  - rubocop-rails 2.12.4
  - rubocop-rspec 2.5.0
@pirj
Copy link
Member

pirj commented Oct 30, 2021

This has been discussed in detail here and here.
Can you check if your spec has a proper Rails-related type: tag?

Edit: RSpec's Minitest adapter calling after_teardown.

@katelovescode
Copy link
Author

This has been discussed in detail here and here. Can you check if your spec has a proper Rails-related type: tag?

Edit: RSpec's Minitest adapter calling after_teardown.

Well, I tried to fix this by doing the following:

  • Changed my travel_back specs to type: :view and type: :helper (one is a blueprint spec and the other 3 are service classes)
  • included the Minitest adapter

Tests are still failing after removing the travel_back

@katelovescode
Copy link
Author

pieforproviders/pieforproviders#1904 - Draft PR so you can see the changes

@pirj
Copy link
Member

pirj commented Nov 9, 2021

Tests are still failing after removing the travel_back

What tests?

Screen Shot 2021-11-09 at 21 31 55

@katelovescode
Copy link
Author

My locals - on the same branch with the same seed
Screen Shot 2021-11-09 at 9 11 47 PM

@pirj
Copy link
Member

pirj commented Nov 10, 2021

@katelovescode I ran specs (rspec spec/services/ spec/blueprints) on your PR's branch, and everything is green most of the time.

spec/services/wonderschool/necc/attendance_csv_importer_spec.rb seems order-dependent. I suggest running rspec bisect to figure it out. If you run it separately, it passes.

On your screenshot, I see some unrelated specs (spec/requests/api) are failing, is it the same on the integration branch? Or is it a lead?

You both use transactional specs (config.use_transactional_fixtures) and DatabaseCleaner, why?

In any case, failures seem unrelated to the behaviour of Rails/RedundantTravelBack. I'm not convinced to make it unsafe for autocorrection.

What do you think?

@katelovescode
Copy link
Author

I think a lot of your comments make sense, thanks for taking the time to look into this and to run the tests locally. I agree with you, my test-suite alone should not dictate that this is unsafe for autocorrection 😂 Those unrelated specs that were failing also only failed when I removed the travel_backs so I'm not really sure. They pass on all the other branches right now.

As for the transactional specs and DB cleaner - I'm not sure honestly, I think I may have run into a bug during testing and found the transactional fixtures as a possible fix, and then maybe didn't ever clear it out. I'm working on a big refactor that will necessitate a lot of spec changes so hopefully I can start digging some of this mess out. Thanks again for your time, I'll close this issue as not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants