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 27, 2023
1 parent e5c4eba commit 01dd517
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 @@ -22,7 +22,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?

operator = first_argument.to_a[1]
return if ALLOWED_OPERATORS.include?(operator)
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 @@ -22,7 +22,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?

operator = first_argument.to_a[1]
return if ALLOWED_OPERATORS.include?(operator)
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 @@ -91,4 +91,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 @@ -91,4 +91,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 01dd517

Please sign in to comment.