Sha256: 726e37f9e9b627d7e3b47dffffcc5de9722001dac9da21dc48621e05480083a6

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

module Micronaut
  module Expectations
    class InvalidMatcherError < ArgumentError; end        
    
    class ExpectationMatcherHandler        
      class << self
        def handle_matcher(actual, matcher, &block)
          ::Micronaut::Matchers.last_should = "should"
          return Micronaut::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?

          unless matcher.respond_to?(:matches?)
            raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
          end
          
          match = matcher.matches?(actual, &block)
          ::Micronaut::Matchers.last_matcher = matcher
          Micronaut::Expectations.fail_with(matcher.failure_message) unless match
          match
        end
      end
    end

    class NegativeExpectationMatcherHandler
      class << self
        def 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(
<<-EOF
Matcher does not support should_not.
See Micronaut::Matchers for more information
about matchers.
EOF
)
          end
          match = matcher.matches?(actual, &block)
          ::Micronaut::Matchers.last_matcher = matcher
          Micronaut::Expectations.fail_with(matcher.negative_failure_message) if match
          match
        end
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spicycode-micronaut-0.0.2 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.3 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.4 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.5 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.6 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.7 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.0.9 lib/micronaut/expectations/handler.rb