Class: RuboCop::Cop::Minitest::AssertTruthy
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Minitest::AssertTruthy
- Extended by:
- AutoCorrector
- Includes:
- ArgumentRangeHelper
- Defined in:
- lib/rubocop/cop/minitest/assert_truthy.rb
Overview
Enforces the test to use ‘assert(actual)` instead of using `assert_equal(true, actual)`.
Constant Summary collapse
- MSG =
'Prefer using `assert(%<arguments>s)`.'
- RESTRICT_ON_SEND =
%i[assert_equal].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubocop/cop/minitest/assert_truthy.rb', line 38 def on_send(node) assert_equal_with_truthy(node) do |actual, rest_receiver_arg| = rest_receiver_arg.first arguments = [actual.source, &.source].compact.join(', ') add_offense(node, message: format(MSG, arguments: arguments)) do |corrector| corrector.replace(node.loc.selector, 'assert') corrector.replace(first_and_second_arguments_range(node), actual.source) end end end |