Sha256: 27288f3021c2b8fcb9aaa82717874ead2fe1fe643f88d2a333cfa723d6701e2b

Contents?: true

Size: 754 Bytes

Versions: 18

Compression:

Stored size: 754 Bytes

Contents

module Rspec
  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

18 entries across 18 versions & 1 rubygems

Version Path
rspec-expectations-2.0.0.beta.8 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.7 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.6 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.5 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.4 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.3 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.2 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.beta.1 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a10 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a9 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a8 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a7 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a6 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a5 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a4 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a3 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a2 lib/rspec/matchers/has.rb
rspec-expectations-2.0.0.a1 lib/rspec/matchers/has.rb