Class: RuboCop::Cop::Minitest::AssertMatch
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::AssertMatch
- Extended by:
- AutoCorrector
- Includes:
- ArgumentRangeHelper
- Defined in:
- lib/rubocop/cop/minitest/assert_match.rb
Overview
Enforces the test to use ‘assert_match` instead of using `assert(matcher.match(string))`.
Constant Summary collapse
- MSG =
'Prefer using `assert_match(%<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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/minitest/assert_match.rb', line 36 def on_send(node) assert_match(node) do |expected, actual, rest_args| basic_arguments = order_expected_and_actual(expected, actual) preferred = ( = rest_args.first) ? "#{basic_arguments}, #{.source}" : basic_arguments = format(MSG, preferred: preferred) add_offense(node, message: ) do |corrector| corrector.replace(node.loc.selector, 'assert_match') 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 |