Skip to content
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

Fix an error for Style/UselessAssertion when passing a single argument to methods to accept two arguments #299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_useless_assertion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#299](https://github.com/rubocop/rubocop-minitest/pull/299): Fix an error for `Style/UselessAssertion` when passing a single argument to methods to accept two arguments. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/useless_assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def offense?(node)
when *SINGLE_ASSERTION_ARGUMENT_METHODS
actual.nil? && expected&.literal? && !expected.xstr_type?
when *TWO_ASSERTION_ARGUMENTS_METHODS
return false unless expected || actual
return false unless expected && actual
return false if expected.source != actual.source

(expected.variable? && actual.variable?) ||
Expand Down
6 changes: 6 additions & 0 deletions test/rubocop/cop/minitest/useless_assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class UselessAssertionTest < Minitest::Test
#{matcher} x.foo, x.foo
RUBY
end

define_method("test_#{matcher}_no_offense_when_only_single_argument_is_given") do
assert_no_offenses(<<~RUBY)
#{matcher} foo
RUBY
end
end

%i[assert_includes refute_includes].each do |matcher|
Expand Down