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

RSpec/ScatteredSetup is marked as safe but misforms case statements #1995

Closed
corsonknowles opened this issue Nov 9, 2024 · 5 comments
Closed

Comments

@corsonknowles
Copy link
Contributor

Cop Doc: https://www.rubydoc.info/gems/rubocop-rspec/1.10.0/RuboCop/Cop/RSpec/ScatteredSetup

RSpec/ScatteredSetup is not safe for autocorrection because it will move before logic out of case statements and into one giant and many empty case statements

@pirj
Copy link
Member

pirj commented Nov 9, 2024 via email

@corsonknowles
Copy link
Contributor Author

corsonknowles commented Nov 10, 2024

@pirj
Copy link
Member

pirj commented Nov 10, 2024

I don’t think we have to account for RSpec DSL in case/if.
RSpec has rich metadata capabilities, and those should be used instead

@pirj pirj closed this as completed Nov 10, 2024
@corsonknowles
Copy link
Contributor Author

Thanks @pirj -- It took my a moment to figure out what that means, I think it's that code like this should be refactored to pass params into the before block, etc and bring the case statements inside so that these errors are not generated by the autocorrect.

I'm convinced that the Rubocop rule here doesn't need to accomadate these cases, but I'm not convinced that it should remain marked as safe for autocorrection.

The examples here were perfectly validy Ruby/RSpec before, but are not after the autocorrect runs.

@corsonknowles
Copy link
Contributor Author

In fact, for the example of hoisting to a higher context, I'm not convinced that is good behavior at all.

But I'm confident neither case should be considered equivalent by design, as is the guideline for cops marked SafeForAutocorrect.

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