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 an error for Minitest/AssertOperator and Minitest/RefuteOperator #263

Merged
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
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