Sha256: 01337ab3d4960cb04595f2469aed60afadb8242679003af9f998069e447d51ae

Contents?: true

Size: 1.06 KB

Versions: 47

Compression:

Stored size: 1.06 KB

Contents

module Spec
  module Matchers
    
    class Has #:nodoc:
      def initialize(sym, *args)
        @sym = sym
        @args = args
      end
      
      def matches?(target)
        @target = target
        begin
          return target.send(predicate, *@args)
        rescue => @error
          # This clause should be empty, but rcov will not report it as covered
          # unless something (anything) is executed within the clause
          rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
        end
        return false
      end
      
      def failure_message
        raise @error if @error
        "expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
      end
      
      def negative_failure_message
        raise @error if @error
        "expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
      end
      
      def description
        "have key #{@args[0].inspect}"
      end
      
      private
        def predicate
          "#{@sym.to_s.sub("have_","has_")}?".to_sym
        end
        
    end
 
  end
end

Version data entries

47 entries across 47 versions & 8 rubygems

Version Path
rspec-1.0.2 lib/spec/matchers/has.rb
rspec-1.0.3 lib/spec/matchers/has.rb
rspec-1.0.4 lib/spec/matchers/has.rb
rspec-0.9.4 lib/spec/matchers/has.rb
rspec-0.8.2 lib/spec/matchers/has.rb
rspec-0.9.0 lib/spec/matchers/has.rb
rspec-0.9.1 lib/spec/matchers/has.rb
rspec-0.9.2 lib/spec/matchers/has.rb
rspec-1.0.5 lib/spec/matchers/has.rb
rspec-1.0.0 lib/spec/matchers/has.rb
rspec-1.0.7 lib/spec/matchers/has.rb
rspec-1.0.6 lib/spec/matchers/has.rb
rspec-1.0.8 lib/spec/matchers/has.rb
rspec-1.1.0 lib/spec/matchers/has.rb
rspec-1.1.1 lib/spec/matchers/has.rb
rspec-1.1.2 lib/spec/matchers/has.rb
rspec-1.1.3 lib/spec/matchers/has.rb
spree-0.2.0 vendor/plugins/rspec/lib/spec/matchers/has.rb
typo-5.0.2 vendor/plugins/rspec/lib/spec/matchers/has.rb
typo-5.0.1 vendor/plugins/rspec/lib/spec/matchers/has.rb