Skip to content

Commit

Permalink
[Fix #183] Fix an error for Minitest/AssertMatch
Browse files Browse the repository at this point in the history
Fixes #183.

This PR fixes an error for `Minitest/AssertMatch` when using `assert` with no arguments `match`.
  • Loading branch information
koic committed Sep 15, 2022
1 parent 077feab commit d055d3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_minitest_assert_match.md
@@ -0,0 +1 @@
* [#183](https://github.com/rubocop/rubocop-minitest/issues/183): Fix an error for `Minitest/AssertMatch` when using `assert` with no arguments `match`. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/mixin/minitest_cop_rule.rb
Expand Up @@ -36,6 +36,7 @@ def define_rule(assertion_method, target_method:, preferred_method: nil, inverse
def on_send(node)
return unless node.method?(:#{assertion_method})
return unless (arguments = peel_redundant_parentheses_from(node.arguments))
return if arguments.first&.call_type? && arguments.first.arguments.empty?
return unless arguments.first.respond_to?(:method?) && arguments.first.method?(:#{target_method})
add_offense(node, message: offense_message(arguments)) do |corrector|
Expand Down
20 changes: 20 additions & 0 deletions test/rubocop/cop/minitest/assert_match_test.rb
Expand Up @@ -132,4 +132,24 @@ def test_do_something
end
RUBY
end

def test_does_not_register_offense_when_using_assert_with_no_arguments_match_call
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert(matcher.match)
end
end
RUBY
end

def test_does_not_register_offense_when_using_assert_with_no_arguments_match_safe_navigation_call
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert(matcher&.match)
end
end
RUBY
end
end

0 comments on commit d055d3b

Please sign in to comment.