Sha256: 6ddad088124bc6cb35004cece7ed9e0915f99fe4064080ab0134e9723eafb626

Contents?: true

Size: 1.83 KB

Versions: 56

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

56 entries across 56 versions & 6 rubygems

Version Path
horseman-0.0.4 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
horseman-0.0.3 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
horseman-0.0.2 vendor/ruby/1.9.1/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.6.alpha vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.5 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.4 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.3 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.2 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
nutshell-crm-0.0.1 vendor/bundle/gems/rspec-expectations-2.7.0/lib/rspec/expectations/handler.rb
rspec-expectations-2.7.0 lib/rspec/expectations/handler.rb
rspec-expectations-2.7.0.rc1 lib/rspec/expectations/handler.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-expectations-2.5.0/lib/rspec/expectations/handler.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-expectations-2.5.0/lib/rspec/expectations/handler.rb
rspec-expectations-2.6.0 lib/rspec/expectations/handler.rb
rspec-expectations-2.6.0.rc6 lib/rspec/expectations/handler.rb
rspec-expectations-2.6.0.rc4 lib/rspec/expectations/handler.rb
rspec-expectations-2.6.0.rc2 lib/rspec/expectations/handler.rb
rspec-expectations-2.5.0 lib/rspec/expectations/handler.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
rspec-expectations-2.4.0 lib/rspec/expectations/handler.rb