Class: Micronaut::Expectations::NegativeExpectationMatcherHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/micronaut/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/micronaut/expectations/handler.rb', line 25

def self.handle_matcher(actual, matcher, &block)
  ::Micronaut::Matchers.last_should = "should not"
  return Micronaut::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)
    Micronaut::Expectations.fail_with(
"Matcher does not support should_not.\nSee Micronaut::Matchers for more information\nabout matchers.\n"
)
  end
  match = matcher.matches?(actual, &block)
  ::Micronaut::Matchers.last_matcher = matcher
  Micronaut::Expectations.fail_with(matcher.negative_failure_message) if match
  match
end