Sha256: cc5111143e1c999454eff677f5a5b3a647d1e2fd3cea7f2818ae9e9a2ba2d04b

Contents?: true

Size: 1.63 KB

Versions: 27

Compression:

Stored size: 1.63 KB

Contents

module Spec
  module Expectations
    class InvalidMatcherError < ArgumentError; end        
    
    module MatcherHandlerHelper
      def describe_matcher(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.respond_to?(:matches?)
            raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
          end
          
          match = matcher.matches?(actual, &block)
          ::Spec::Matchers.generated_description = "should #{describe_matcher(matcher)}"
          Spec::Expectations.fail_with(matcher.failure_message) unless match
        end
      end
    end

    class NegativeExpectationMatcherHandler
      class << self
        include MatcherHandlerHelper
        def handle_matcher(actual, matcher, &block)
          unless matcher.respond_to?(:matches?)
            raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
          end

          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(matcher)}"
          Spec::Expectations.fail_with(matcher.negative_failure_message) if match
        end
      end
    end

  end
end

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.3 rails_plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.2 rails_plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.4 rails_plugins/rspec/lib/spec/expectations/handler.rb
picolena-0.1.5 rails_plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.5.1 vendor/plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.5 vendor/plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.7 vendor/plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.6 vendor/plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.8 vendor/plugins/rspec/lib/spec/expectations/handler.rb
radiant-0.6.9 vendor/plugins/rspec/lib/spec/expectations/handler.rb
rspec-1.1.1 lib/spec/expectations/handler.rb
rspec-1.1.0 lib/spec/expectations/handler.rb
rspec-1.1.2 lib/spec/expectations/handler.rb
rspec-1.1.3 lib/spec/expectations/handler.rb
spree-0.2.0 vendor/plugins/rspec/lib/spec/expectations/handler.rb
typo-5.0.1 vendor/plugins/rspec/lib/spec/expectations/handler.rb
typo-5.0.2 vendor/plugins/rspec/lib/spec/expectations/handler.rb