rubocop-rspec: `RSpec/Rails/AvoidSetupHook` consider `minitest` setup hook as problem
Hi there, I got rails project with a bunch of legacy code, and for some forgotten reason it uses both rspec and minitest tests
If I run rubocop with auto-fix in root folder - it will consider this as a problem and fix it and broke minitest file
rubocop test/controllers/clients_controller_test.rb
Inspecting 1 file
C
Offenses:
test/controllers/clients_controller_test.rb:6:3: C: [Correctable] RSpec/Rails/AvoidSetupHook: Use before instead of setup.
setup do ...
^^^^^^^^
1 file inspected, 1 offense detected, 1 offense auto-correctable
And after applying fix I got:
rake test
rake aborted!
NoMethodError: undefined method `before' for ClientsControllerTest:Class
I think this cop should ignore files containg minitest tests, maybe by detecting class ClientsControllerTest < ActionController::TestCase or something like this
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (14 by maintainers)
Commits related to this issue
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
- Fix default config for sub-departments It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn... — committed to rubocop/rubocop-rspec by pirj 3 years ago
@pirj Actually I’m not very familar with Rubocop internal mechanics and config default format, I usually only report bugs )
So I’m little bit worried that I may broke something and not sure I’ll be able to write a correct test suite
This problem is very similar to rubocop/rubocop#9889 and we were able to resolve that problem, but I failed to realize that the solution should not be in @dmke’s local configuration but in the configuration of rubocop-rspec.
The crux of the matter is that configuration for the
RSpecdepartment isn’t automatically inherited down to subdepartments likeRSpec/Rails. I’m not sure if we could change RuboCop so that kind of inheritance takes place. The other solution would be to addin
config/default.ymlof rubocop-rspec.TIL
bundle add ...That would be helpful, thanks!
@pirj Thanks for your investigation
I can simplify my repo to minimal reproducible case if this needed by @koic or @bbatsov, because right now project is rather complicated
@ShockwaveNN Ha! The documentation is correct and corresponds to the default configuration. I can’t remember seeing
rubocop-rspecinspecting outside*/spec/, and if it does, it’s either a misconfiguration, or a regression inrubocop.I can reproduce the issue with the repository you provided with RuboCop 1.16.1, though. Can’t see anything suspicious in your configuration.
The problem seems to be somewhere here:
and deeper inside:
@koic @bbatsov Can you please transfer this issue to
rubocop? Wondering if there were some changes made that could affect howIncludemerging between cops’s own config andAllCops/Include? As far as I remember, cops’ and extensions’ configs should override the default broad list ofIncludes according to https://docs.rubocop.org/rubocop/1.9/configuration.html#unusual-files-that-would-not-be-included-by-default.