module RuboCop::Cop::Capybara::RSpec::ExplicitHelper

def allowed_explicit_matchers

def allowed_explicit_matchers
  cop_config.fetch('AllowedExplicitMatchers', []) + BUILT_IN_MATCHERS
end

def check_explicit(node) # rubocop:disable Metrics/MethodLength

rubocop:disable Metrics/MethodLength
def check_explicit(node) # rubocop:disable Metrics/MethodLength
  predicate_matcher?(node) do |actual, matcher|
    add_offense(node,
                message: message_explicit(matcher)) do |corrector|
      corrector_explicit(corrector, node, actual, matcher)
    end
  end
end

def corrector_explicit(corrector, to_node, actual, matcher)

def corrector_explicit(corrector, to_node, actual, matcher)
  replacement_matcher = replacement_matcher(to_node)
  corrector.replace(matcher, replacement_matcher)
  move_predicate(corrector, actual, matcher)
  corrector.replace(to_node.loc.selector, 'to')
end

def message_explicit(matcher)

def message_explicit(matcher)
  format(MSG_EXPLICIT,
         predicate_name: to_predicate_method(matcher.method_name),
         matcher_name: matcher.method_name)
end

def move_predicate(corrector, actual, matcher)

def move_predicate(corrector, actual, matcher)
  predicate = to_predicate_method(matcher.method_name)
  args = args_loc(matcher).source
  corrector.insert_after(actual,
                         ".#{predicate}" + args)
end

def predicate_matcher_name?(name)

def predicate_matcher_name?(name)
  name = name.to_s
  return false if allowed_explicit_matchers.include?(name)
  INFLECTED_MATCHER.include?(name)
end

def replacement_matcher(node)

rubocop:disable Metrics/MethodLength
def replacement_matcher(node)
  case [cop_config['Strict'], node.method?(:to)]
  when [true, true]
    'be(true)'
  when [true, false]
    'be(false)'
  when [false, true]
    'be_truthy'
  when [false, false]
    'be_falsey'
  else
    # :nocov:
    :noop
    # :nocov:
  end
end

def to_predicate_method(matcher)

def to_predicate_method(matcher)
  "#{matcher.to_s.sub('match_', 'matches_')}?"
end