Class: Spec::Expectations::NegativeExpectationMatcherHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.11/lib/spec/expectations/handler.rb

Class Method Summary collapse

Class Method Details

.handle_matcher(actual, matcher, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gems/rspec-1.1.11/lib/spec/expectations/handler.rb', line 25

def handle_matcher(actual, matcher, &block)
  ::Spec::Matchers.last_should = "should not"
  return Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
  
  unless matcher.respond_to?(:matches?)
    raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
  end

  unless matcher.respond_to?(:negative_failure_message)
    Spec::Expectations.fail_with(
<<-EOF
Matcher does not support should_not.
See Spec::Matchers for more information
about matchers.
EOF
)
  end
  match = matcher.matches?(actual, &block)
  ::Spec::Matchers.last_matcher = matcher
  Spec::Expectations.fail_with(matcher.negative_failure_message) if match
  match
end