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
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
rspec-expectations-2.3.0 lib/rspec/expectations/handler.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/handler.rb
rspec-expectations-2.2.0 lib/rspec/expectations/handler.rb
rspec-expectations-2.1.0 lib/rspec/expectations/handler.rb
rspec-expectations-2.0.1 lib/rspec/expectations/handler.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.4.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.4.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.3.2 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.3.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.3.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.2.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.1.2 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.1.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb
gemrage-0.1.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/lib/rspec/expectations/handler.rb