Skip to content

Commit

Permalink
Fix an error for Minitest/AssertOperator and Minitest/RefuteOperator
Browse files Browse the repository at this point in the history
This PR fixes an error for `Minitest/AssertOperator` and `Minitest/RefuteOperator`
when using unary operation argument.
  • Loading branch information
koic committed Sep 25, 2023
1 parent 05da8ea commit e067842
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#263](https://github.com/rubocop/rubocop-minitest/pull/263): Fix an error for `Minitest/AssertOperator` and `Minitest/RefuteOperator` when using unary operation argument. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/assert_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AssertOperator < Base

def on_send(node)
first_argument = node.first_argument
return unless first_argument.respond_to?(:operator_method?) && first_argument.operator_method?
return unless first_argument.respond_to?(:binary_operation?) && first_argument.binary_operation?

new_arguments = build_new_arguments(node)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/refute_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RefuteOperator < Base

def on_send(node)
first_argument = node.first_argument
return unless first_argument.respond_to?(:operator_method?) && first_argument.operator_method?
return unless first_argument.respond_to?(:binary_operation?) && first_argument.binary_operation?

new_arguments = build_new_arguments(node)

Expand Down
10 changes: 10 additions & 0 deletions test/rubocop/cop/minitest/assert_operator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ def test_do_something
end
RUBY
end

def test_does_not_register_offense_when_using_assert_with_unary_operation
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert(-x)
end
end
RUBY
end
end
10 changes: 10 additions & 0 deletions test/rubocop/cop/minitest/refute_operator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ def test_do_something
end
RUBY
end

def test_does_not_register_offense_when_using_refute_with_unary_operation
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
refute(-x)
end
end
RUBY
end
end

0 comments on commit e067842

Please sign in to comment.