class RuboCop::Cop::RSpec::InvalidPredicateMatcher

Checks invalid usage for predicate matcher.

Predicate matcher does not need a question. This cop checks an unnecessary question in predicate matcher.

@example

# bad
expect(foo).to be_something?

# good
expect(foo).to be_something

Constants

MSG

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/rspec/invalid_predicate_matcher.rb, line 25
def on_send(node)
  invalid_predicate_matcher?(node) do |predicate|
    add_offense(predicate, location: :expression)
  end
end

Private Instance Methods

message(predicate) click to toggle source
# File lib/rubocop/cop/rspec/invalid_predicate_matcher.rb, line 38
def message(predicate)
  format(MSG, matcher: predicate.method_name)
end
predicate?(name) click to toggle source
# File lib/rubocop/cop/rspec/invalid_predicate_matcher.rb, line 33
def predicate?(name)
  name = name.to_s
  name.start_with?('be_', 'have_') && name.end_with?('?')
end