class RuboCop::Cop::Rails::RefuteMethods


refute_equal true, false
refute_empty [1, 2, 3]
refute false
# good
assert_not_equal true, false
assert_not_empty [1, 2, 3]
assert_not false
# bad
@example EnforcedStyle: refute
assert_not_equal true, false
assert_not_empty [1, 2, 3]
assert_not false
# good
refute_equal true, false
refute_empty [1, 2, 3]
refute false
# bad
@example EnforcedStyle: assert_not (default)
Use ‘assert_not` methods instead of `refute` methods.

def bad_method?(method_name)

def bad_method?(method_name)
  if style == :assert_not
    REFUTE_METHODS.include?(method_name)
  else
    ASSERT_NOT_METHODS.include?(method_name)
  end
end

def convert_good_method(bad_method)

def convert_good_method(bad_method)
  if style == :assert_not
    CORRECTIONS.fetch(bad_method)
  else
    CORRECTIONS.invert.fetch(bad_method)
  end
end

def offense_message(method_name)

def offense_message(method_name)
  format(MSG, bad_method: method_name, good_method: convert_good_method(method_name))
end

def on_send(node)

def on_send(node)
  return unless offensive?(node)
  method_name = node.method_name
  message = offense_message(method_name)
  range = node.loc.selector
  add_offense(range, message: message) do |corrector|
    corrector.replace(range, convert_good_method(method_name))
  end
end