Sha256: 6c505562295b0818b9d2be03052e244a67dd30799c090a653213829121925761

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 KB

Contents

module Spec
  module Expectations
    
    module MatcherHandlerHelper
      def describe(matcher)
        matcher.respond_to?(:description) ? matcher.description : "[#{matcher.class.name} does not provide a description]"
      end
    end
    
    class ExpectationMatcherHandler
      class << self
        include MatcherHandlerHelper
        def handle_matcher(actual, matcher, &block)
          unless matcher.nil?
            match = matcher.matches?(actual, &block)
            ::Spec::Matchers.generated_description = "should #{describe(matcher)}"
            Spec::Expectations.fail_with(matcher.failure_message) unless match
          end
        end
      end
    end

    class NegativeExpectationMatcherHandler
      class << self
        include MatcherHandlerHelper
        def handle_matcher(actual, matcher, &block)
          unless matcher.nil?
            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.generated_description = "should not #{describe(matcher)}"
            Spec::Expectations.fail_with(matcher.negative_failure_message) if match
          end
        end
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
puppet-0.22.4 test/lib/spec/expectations/handler.rb
puppet-0.23.0 test/lib/spec/expectations/handler.rb
puppet-0.23.1 test/lib/spec/expectations/handler.rb
puppet-0.23.2 test/lib/spec/expectations/handler.rb
riess-0.0.8 vendor/rspec-0.8.2/lib/spec/expectations/handler.rb
rspec-0.8.1 lib/spec/expectations/handler.rb
rspec-0.8.0 lib/spec/expectations/handler.rb
rspec-0.8.2 lib/spec/expectations/handler.rb