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
Cop idea: prevent closure variables #1648
Comments
Good catch! Few things to consider:
|
I get the feeling this should possibly be two rules:
I'll likely split this into two PR's. |
I'd start with the second one as more impactful.
|
I've always done the klass thing as a |
One example of a legitimate usage of a variable rubocop/rubocop#8447 (comment)
No, just because variables are simpler. |
The problem in the |
@pirj I think I'm going to punt on "direct calls to create/build, since it's quite popular to config.include FactoryBot::Syntax::Methods". The reason why is if you use these methods outside of an example, FactoryBot already gives you a descriptive error message stating that you should only use them within examples. |
Sounds great @thijsnado 👍 |
@pirj put up a PR, I'm getting the following failure in CI: https://app.circleci.com/pipelines/github/rubocop-hq/rubocop-rspec/460/workflows/bea51799-651f-4806-8016-12f297c9112f/jobs/16335, it looks un-related to my changes though. Any thoughts? |
@thijsnado No worries, there's a fix #1014 |
A common mistake I see is using closure variables instead of let statements. An example of this:
The issue with above example is now a user exists in the DB for the rest of the tests since it is not part of example transaction.
I'd be willing to work on a PR for this if you think this would be a good addition to this gem.
The text was updated successfully, but these errors were encountered: