Class: RuboCop::Cop::Minitest::AssertEqual
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::AssertEqual
- Extended by:
- AutoCorrector
- Includes:
- ArgumentRangeHelper
- Defined in:
- lib/rubocop/cop/minitest/assert_equal.rb
Overview
Enforces the use of ‘assert_equal(expected, actual)` over `assert(expected == actual)`.
Constant Summary collapse
- MSG =
'Prefer using `assert_equal(%<preferred>s)`.'- RESTRICT_ON_SEND =
i[assert assert_operator].freeze
Instance Method Summary collapse
-
#on_send(node) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#on_send(node) ⇒ Object
rubocop:disable Metrics/AbcSize
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/minitest/assert_equal.rb', line 32 def on_send(node) assert_equal(node) do |expected, actual, rest_args| basic_arguments = "#{expected.source}, #{actual.source}" preferred = ( = rest_args.first) ? "#{basic_arguments}, #{message_arg.source}" : basic_arguments = format(MSG, preferred: preferred) add_offense(node, message: ) do |corrector| corrector.replace(node.loc.selector, 'assert_equal') range = if node.method?(:assert) node.first_argument else node.first_argument.source_range.begin.join(node.arguments[2].source_range.end) end corrector.replace(range, basic_arguments) end end end |