Skip to content

Commit

Permalink
Merge pull request #262 from koic/fix_an_error_for_assert_operator
Browse files Browse the repository at this point in the history
[Fix #261] Fix an error for `Minitest/AssertOperator`
  • Loading branch information
koic committed Sep 24, 2023
2 parents 4c0d555 + 9aad91a commit 4794578
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_assert_operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#261](https://github.com/rubocop/rubocop-minitest/issues/261): Fix an error for `Minitest/AssertOperator` and `Minitest/RefuteOperator` when using variable argument. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/minitest/assert_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class AssertOperator < Base
RESTRICT_ON_SEND = %i[assert].freeze

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

new_arguments = build_new_arguments(node)

Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/minitest/refute_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class RefuteOperator < Base
RESTRICT_ON_SEND = %i[refute].freeze

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

new_arguments = build_new_arguments(node)

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

def test_does_not_register_offense_when_using_assert_with_variable
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
var = do_something
assert(var)
end
end
RUBY
end
end
12 changes: 12 additions & 0 deletions test/rubocop/cop/minitest/refute_operator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@ def test_do_something
end
RUBY
end

def test_does_not_register_offense_when_using_refute_with_variable
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
var = do_something
refute(var)
end
end
RUBY
end
end

0 comments on commit 4794578

Please sign in to comment.