-
-
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 *_in_delta
assertions in RSpec/Rails/MinitestAssertions
#1791
Conversation
].freeze | ||
|
||
NODE_MATCHER_PATTERN = <<~PATTERN | ||
(send nil? {:assert_in_delta :assert_not_in_delta :refute_in_delta} $_ $_ $!{sym str}? $_?) |
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.
Message can be a proc:
# File lib/minitest/unit.rb, line 196
def assert test, msg = nil
msg ||= "Failed assertion, no message given."
self._assertions += 1
unless test then
msg = msg.call if Proc === msg
raise MiniTest::Assertion, msg
end
true
end
```
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.
That's not unique to this though, and none of our code depends on that - we're just copying the source code as is (you might be mentioning this because we're doing !failure_message.empty?
for this assertion, but that is checking against an array which contains the matched nodes).
We should have tests for this but since it applies for every assertion we currently have I'll do it in a dedicated PR
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’m most concerned (see my earlier comments below), is that we assume that the message (str/sym) can be passed as the third argument, and in this case, skip matching. But this would be incorrect for Minitest.
My point is to disregard the type, and always consider the third argument to be the delta (optional), and the fourth - the message (optional, no type constraints.
I agree that we’d better investigate proc messages in a separate pr. Wondering if RSpec provides a lazily evaluated failure message and we could autocorrect those.
If it can’t - we need to skip autocorrection.
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 news that RSpec does seem to support proc failure messages.. I would still double check this.
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.
Thank you! What a streak!
This is branched off #1790, showing how easy it is to now add a new assertion matcher - until the prior PR is merged, the last commit of this PR should be looked at for review.
related 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
.