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

Update AssertOperator and RefuteOperator to allow :[] #264

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
4 changes: 4 additions & 0 deletions lib/rubocop/cop/minitest/assert_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class AssertOperator < Base

MSG = 'Prefer using `assert_operator(%<new_arguments>s)`.'
RESTRICT_ON_SEND = %i[assert].freeze
ALLOWED_OPERATORS = [:[]].freeze

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

operator = first_argument.to_a[1]
return if ALLOWED_OPERATORS.include?(operator)

new_arguments = build_new_arguments(node)

add_offense(node, message: format(MSG, new_arguments: new_arguments)) do |corrector|
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/minitest/refute_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class RefuteOperator < Base

MSG = 'Prefer using `refute_operator(%<new_arguments>s)`.'
RESTRICT_ON_SEND = %i[refute].freeze
ALLOWED_OPERATORS = [:[]].freeze

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

operator = first_argument.to_a[1]
return if ALLOWED_OPERATORS.include?(operator)

new_arguments = build_new_arguments(node)

add_offense(node, message: format(MSG, new_arguments: new_arguments)) do |corrector|
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_consider_brackets_to_be_an_offense
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert(array_of_booleans[42])
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_consider_brackets_to_be_an_offense
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
refute(array_of_booleans[42])
end
end
RUBY
end
end