Module: RuboCop::Cop::Minitest::PredicateAssertionHandleable Private

Included in:
AssertPredicate, RefutePredicate
Defined in:
lib/rubocop/cop/mixin/predicate_assertion_handleable.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Common functionality for Minitest/AssertPredicate and Minitest/RefutePredicate cops.

Constant Summary collapse

MSG =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'Prefer using `%<assertion_type>s_predicate(%<new_arguments>s)`.'

Instance Method Summary collapse

Instance Method Details

#autocorrect(corrector, node, arguments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
# File 'lib/rubocop/cop/mixin/predicate_assertion_handleable.rb', line 21

def autocorrect(corrector, node, arguments)
  corrector.replace(node.loc.selector, "#{assertion_type}_predicate")

  new_arguments = new_arguments(arguments).join(', ')

  corrector.replace(node.first_argument, new_arguments)
end

#on_send(node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/mixin/predicate_assertion_handleable.rb', line 11

def on_send(node)
  return if node.first_argument&.any_block_type?
  return unless predicate_method?(node.first_argument)
  return unless node.first_argument.arguments.none?

  add_offense(node, message: offense_message(node.arguments)) do |corrector|
    autocorrect(corrector, node, node.arguments)
  end
end