Class: RSpec::Expectations::PositiveExpectationHandler

Inherits:
ExpectationHandler show all
Defined in:
lib/rspec/expectations/handler.rb

Class Method Summary (collapse)

Methods inherited from ExpectationHandler

check_message

Class Method Details

+ (Object) handle_matcher(actual, matcher, message = nil)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec/expectations/handler.rb', line 18

def self.handle_matcher(actual, matcher, message=nil, &block)
  check_message(message)
  ::RSpec::Matchers.last_should = :should
  ::RSpec::Matchers.last_matcher = matcher
  return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) if matcher.nil?

  match = matcher.matches?(actual, &block)
  return match if match

  message = message.call if message.respond_to?(:call)

  message ||= matcher.respond_to?(:failure_message_for_should) ?
              matcher.failure_message_for_should :
              matcher.failure_message

  if matcher.respond_to?(:diffable?) && matcher.diffable?
    ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
  else
    ::RSpec::Expectations.fail_with message
  end
end