Sha256: 85993139df4b8251ed90bbece78ad8153eef676360167f3256804dac32d2f304

Contents?: true

Size: 736 Bytes

Versions: 9

Compression:

Stored size: 736 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
        "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
      end
      
      def negative_failure_message
        "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

9 entries across 9 versions & 1 rubygems

Version Path
dchelimsky-rspec-1.1.99.1 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.2 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.3 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.4 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.5 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.6 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.7 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.8 lib/spec/matchers/has.rb
dchelimsky-rspec-1.1.99.9 lib/spec/matchers/has.rb