-
-
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 *_includes
assertions in RSpec/Rails/MinitestAssertions
#1779
Conversation
(send nil? {:assert_empty :assert_not_empty :refute_empty} $_ $_?) | ||
PATTERN | ||
|
||
def on_send(node) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize |
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.
I've just disabled AbcSize
for now because I don't want to go too far from #1778 until it's landed, but I think a good next step for improving this could be to move the node matchers / block into the assertion classes too, so it becomes something like:
EqualAssertion.check(node)
IncludesAssertion.check(node)
NilAssertion.check(node)
EmptyAssertion.check(node)
# ...
(which you could probably take further by having an ASSERTION_CHECKERS array, and then the rest of this rule just iterates over that in a few places to pull through node matchers, restrict sends, check
, etc)
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, thank you!
@@ -30,66 +30,146 @@ class MinitestAssertions < Base | |||
RESTRICT_ON_SEND = %i[ | |||
assert_equal | |||
assert_not_equal | |||
refute_equal | |||
assert_includes | |||
assert_not_includes |
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.
Does it exist?
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's defined by Rails: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/test_case.rb#L206
@@ -28,11 +30,14 @@ class MinitestAssertions < Base | |||
RESTRICT_ON_SEND = %i[ | |||
assert_equal | |||
assert_not_equal | |||
assert_includes | |||
assert_not_includes | |||
assert_nil | |||
assert_not_nil |
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.
There’s an “a-ha” moment, since all those assert_no_* are from test-unit, not minitest.
But I’d say we don’t care much if there’s a corresponding native RSpec expectation/matcher we can suggest using instead.
test-unit assertions https://www.rubydoc.info/gems/test-unit/2.3.2/Test/Unit/Assertions
Minitest assertions https://ruby-doc.org/stdlib-3.0.0/libdoc/minitest/rdoc/Minitest/Assertions.html
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.
Yea though also they're defined by Rails which is actually why I was including them: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/test_case.rb#L206
a58d40c
to
9a97e40
Compare
9a97e40
to
847e6a3
Compare
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. Thank you!
Branched off #1778This adds support for the
includes
assertionsrelated to rubocop/rubocop-rspec_rails#7
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:
SetVersionChanged: "<<next>>"
inconfig/default.yml
.