Sha256: cec721f9365ff3df216a7e1d125c4fee4ffab0402835cb86a10b9015b32d7948

Contents?: true

Size: 1.59 KB

Versions: 36

Compression:

Stored size: 1.59 KB

Contents

module Micronaut
  module Expectations
    class InvalidMatcherError < ArgumentError; end        
    
    class ExpectationMatcherHandler        

        def self.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

    class NegativeExpectationMatcherHandler

        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(
<<-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

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
rsanheim-micronaut-0.1.3.2 lib/micronaut/expectations/handler.rb
rsanheim-micronaut-0.1.4.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.0 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.2 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.3 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.4.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.4.2 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.4.3 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.4.4 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.4 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.5.2 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.5 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.6.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.6.8 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.6.9.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.6.9 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.6 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.7.1 lib/micronaut/expectations/handler.rb
spicycode-micronaut-0.1.7.2 lib/micronaut/expectations/handler.rb