Class: RuboCop::Cop::Minitest::RefuteOperator

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/minitest/refute_operator.rb

Overview

Enforces the use of ‘refute_operator(expected, :<, actual)` over `refute(expected < actual)`.

Examples:


# bad
refute(expected < actual)

# good
refute_operator(expected, :<, actual)

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/minitest/refute_operator.rb', line 23

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

  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|
    corrector.replace(node.loc.selector, 'refute_operator')

    corrector.replace(range_of_arguments(node), new_arguments)
  end
end