Class: RuboCop::Cop::Minitest::VariableAsActualArgument

Inherits:
LiteralAsActualArgument
  • Object
show all
Defined in:
lib/rubocop/cop/minitest/variable_as_actual_argument.rb

Overview

Checks for ‘assert_equal` method calls where the first argument is a actual variable, and the second argument is an expected literal.

Examples:

# bad
assert_equal 3, my_var

# good
assert_equal my_var, 3

Constant Summary collapse

MSG =
'Replace the literal with the second argument.'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autocorrect_incompatible_withObject



17
18
19
# File 'lib/rubocop/cop/minitest/variable_as_actual_argument.rb', line 17

def self.autocorrect_incompatible_with
  [LiteralAsActualArgument]
end

Instance Method Details

#on_send(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/minitest/variable_as_actual_argument.rb', line 20

def on_send(node)
  return unless node.method?(:assert_equal)

  actual, expected, _message = *node.arguments
  return unless actual&.recursive_basic_literal?
  return if expected.recursive_basic_literal?

  add_offense(all_arguments_range(node)) do |corrector|
    autocorrect(corrector, node, expected, actual)
  end
end