-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Detection of assert when assert_equal was intended #32
Comments
This seems to be a cop when the following conditions are satisfied about how to use
The following is an example. # bad
assert([], result.errors)
# good
assert_empty(result.errors)
assert_empty(result.errors, 'Expected no errors') Hash literals may also be targeted to cop. Also, I think that auto-correct is unsafe because it is a correction to an incompatible method. For example, I considered |
[Fix #32] Add new cop assert_empty_literal
This issue can still happen when doing something like
The intent was to do Would you be open to consider updating the cop to include any literal (or number and strings t least)? I'd be happy to make a PR if so. |
Is your feature request related to a problem? Please describe.
I was wondering why some unit tests weren't failing after code changes. Turns out they were written like this:
The test should have use
assert_equal
(or maybeassert_empty
without the first argument), but since the empty array is trueish, this test always passes, regardless of the value ofresult.errors
, which is only used as the additional (optional) message parameter.Describe the solution you'd like
I would like Rubocop-Minitest to find this error
Additional context
I have absolutely no idea how this error could be detected by Rubocop. In case a third parameter is added, this could be used to detect errors:
But this is pretty pointless, since it would result in runtime errors anyway.
If anybody has an idea on how to detect this, I could probably implement it. If it appears to be impossible, we shouldn't attempt to implement it ;)
The text was updated successfully, but these errors were encountered: