Skip to content

Commit

Permalink
Merge pull request #263 from koic/fix_an_error_for_assert_operator_an…
Browse files Browse the repository at this point in the history
…d_refute_operator

Fix an error for `Minitest/AssertOperator` and `Minitest/RefuteOperator`
  • Loading branch information
koic committed Sep 27, 2023
2 parents e5c4eba + 01dd517 commit 0bbcb3d
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 0bbcb3d

Please sign in to comment.