Skip to content

Commit

Permalink
Fix an error for Style/UselessAssertion when passing a single argum…
Browse files Browse the repository at this point in the history
…ent to methods to accept two arguments
  • Loading branch information
Earlopain committed Jan 18, 2024
1 parent 4218ced commit 9257270
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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

0 comments on commit 9257270

Please sign in to comment.