-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
feat: support correcting assert_nil
and refute_nil
to RSpec/Rails/MinitestAssertions
#1773
Conversation
Initially I thought it would be best to correct to |
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 good!
Perhaps consider wrapping specs in two context
blocks, one for the “equal” assertions and one for the “nil” assertions.
oh yeah good point! I've been trailing minitest recently and so had completely forgotten we've got |
…s/MinitestAssertions`
@pirj, could I get a second opinion on this PR, please? |
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.
Fantastic, thank you!
context 'with equal assertions' do | ||
it 'registers an offense when using `assert_equal`' do | ||
expect_offense(<<~RUBY) | ||
assert_equal(a, b) |
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.
It was a miss in the original implementation, it’s confusing that a
is “expected, and b
is “actual”.
Up to you if you want to fix this along the way or leave out.
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.
Good point - I'll leave it for now since this diff is already pretty big, but happy to do a follow up addressing it
Thanks again! |
@@ -1169,6 +1169,7 @@ RSpec/Rails/MinitestAssertions: | |||
Description: Check if using Minitest matchers. | |||
Enabled: pending | |||
VersionAdded: '2.17' | |||
VersionChanged: "<<next>>" |
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.
This change should not have been made. This should only be changed when the default settings are changed. For example, when you add a configurable option or change the default for a configurable option.
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.
fix: #1777
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.
Oops, my bad. I should have caught that in review.
Thanks for discovering, and fixing.
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.
for what it's worth I feel like that was required by bundle exec rake
, but it might have been I just messed something up or changed something else I shouldn't have locally to make it think this needed updating 🤷
I'll keep this in mind for future contributions and let you know if I do find the tasks behaving wrongly
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.
Never mind! Thank you for your work.
I'm not sure how far folks want to take this (if at all), but I got the impression from rubocop/rubocop-rspec_rails#7 & #1517 that it was desirable to support at least some more assertions, and this felt like a pretty straightforward one to land.
I've deliberately gone the "boring" route of just effectively duplicating everything twice rather than try to use a single set of methods because lines of code are cheap and if more matchers are supported there might be better ways to deduplicate that are not compatible with one or both of these matchers.
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:
Added the new cop toconfig/default.yml
.The cop is configured asEnabled: pending
inconfig/default.yml
.The cop is configured asEnabled: true
in.rubocop.yml
.The cop documents examples of good and bad code.The tests assert both that bad code is reported and that good code is not reported.SetVersionAdded: "<<next>>"
indefault/config.yml
.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"
inconfig/default.yml
.