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 #183] Fix an error for Minitest/AssertMatch #184

Merged
merged 1 commit into from Sep 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/mixin/minitest_cop_rule.rb
Expand Up @@ -36,7 +36,8 @@ 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 unless arguments.first.respond_to?(:method?) && arguments.first.method?(:#{target_method})
return unless arguments.first&.call_type?
return if arguments.first.arguments.empty? || !arguments.first.method?(:#{target_method})

add_offense(node, message: offense_message(arguments)) do |corrector|
autocorrect(corrector, node, arguments)
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