Sha256: bc19d184a799be5cd9c4e6b21b11b424a7a9afee21b932d6eed746d8faf3e6d5

Contents?: true

Size: 1.83 KB

Versions: 18

Compression:

Stored size: 1.83 KB

Contents

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

        match = matcher.matches?(actual, &block)
        return match if match
        
        message ||= matcher.respond_to?(:failure_message_for_should) ?
                    matcher.failure_message_for_should :
                    matcher.failure_message
        
        if matcher.respond_to?(:diffable?) && matcher.diffable?
          ::Rspec::Expectations.fail_with message, matcher.expected.first, matcher.actual
        else
          ::Rspec::Expectations.fail_with message
        end
      end
    end

    class NegativeExpectationHandler
      def self.handle_matcher(actual, matcher, message=nil, &block)
        ::Rspec::Matchers.last_should = :should_not
        ::Rspec::Matchers.last_matcher = matcher
        return ::Rspec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
        
        match = matcher.respond_to?(:does_not_match?) ?
                !matcher.does_not_match?(actual, &block) :
                matcher.matches?(actual, &block)
        return match unless match
        
        message ||= matcher.respond_to?(:failure_message_for_should_not) ?
                    matcher.failure_message_for_should_not :
                    matcher.negative_failure_message

        if matcher.respond_to?(:diffable?) && matcher.diffable?
          ::Rspec::Expectations.fail_with message, matcher.expected.first, matcher.actual
        else
          ::Rspec::Expectations.fail_with message
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rspec-expectations-2.0.0.beta.8 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.7 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.6 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.5 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.4 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.3 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.2 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.beta.1 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a10 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a9 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a8 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a7 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a6 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a5 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a4 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a3 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a2 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.0.a1 lib/rspec/expectations/handler.rb