Sha256: b1bdead5fb20d90de83e48b17251983924610d8fc0496610c106084c308ce326

Contents?: true

Size: 753 Bytes

Versions: 23

Compression:

Stored size: 753 Bytes

Contents

module Spec
  module Matchers
    
    class Has
      
      def initialize(expected, *args)
        @expected, @args = expected, args
      end
      
      def matches?(actual)
        actual.__send__(predicate(@expected), *@args)
      end
      
      def failure_message_for_should
        "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
      end
      
      def failure_message_for_should_not
        "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return false, got true"
      end
      
      def description
        "have key #{@args[0].inspect}"
      end
    
    private
    
      def predicate(sym)
        "#{sym.to_s.sub("have_","has_")}?".to_sym
      end
      
    end
    
  end
end

Version data entries

23 entries across 23 versions & 7 rubygems

Version Path
rspec-1.2.3 lib/spec/matchers/has.rb
rspec-1.2.4 lib/spec/matchers/has.rb
rspec-1.2.5 lib/spec/matchers/has.rb