class RSpec::Matchers::BuiltIn::BePredicate

Public Class Methods

new(*args, &block) click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 130
def initialize(*args, &block)
  @expected = parse_expected(args.shift)
  @args = args
  @block = block
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 159
def description
  "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}"
end
failure_message_for_should() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 151
def failure_message_for_should
  "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
end
failure_message_for_should_not() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 155
def failure_message_for_should_not
  "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
end
matches?(actual) click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 136
def matches?(actual)
  @actual = actual
  begin
    return @result = actual.__send__(predicate, *@args, &@block)
  rescue NameError => predicate_missing_error
    "this needs to be here or rcov will not count this branch even though it's executed in a code example"
  end

  begin
    return @result = actual.__send__(present_tense_predicate, *@args, &@block)
  rescue NameError
    raise predicate_missing_error
  end
end

Private Instance Methods

parse_expected(expected) click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 173
def parse_expected(expected)
  @prefix, expected = prefix_and_expected(expected)
  expected
end
predicate() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 165
def predicate
  "#{@expected}?".to_sym
end
prefix_and_expected(symbol) click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 178
def prefix_and_expected(symbol)
  symbol.to_s =~ /^(be_(an?_)?)(.*)/
  return $1, $3
end
prefix_to_sentence() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 183
def prefix_to_sentence
  split_words(@prefix)
end
present_tense_predicate() click to toggle source
# File lib/rspec/matchers/built_in/be.rb, line 169
def present_tense_predicate
  "#{@expected}s?".to_sym
end