Sha256: 243a7b35c696694ec5b21f6956442136efa61cec375c682f0a827434aa660261

Contents?: true

Size: 976 Bytes

Versions: 50

Compression:

Stored size: 976 Bytes

Contents

module Mocha
  
  module ParameterMatchers

    # :call-seq: has_entry(key, value) -> parameter_matcher
    #
    # Matches +Hash+ containing entry with +key+ and +value+.
    #   object = mock()
    #   object.expects(:method_1).with(has_entry('key_1', 1))
    #   object.method_1('key_1' => 1, 'key_2' => 2)
    #   # no error raised
    #
    #   object = mock()
    #   object.expects(:method_1).with(has_entry('key_1', 1))
    #   object.method_1('key_1' => 2, 'key_2' => 1)
    #   # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
    def has_entry(key, value)
      HasEntry.new(key, value)
    end

    class HasEntry # :nodoc:
      
      def initialize(key, value)
        @key, @value = key, value
      end
      
      def ==(parameter)
        parameter[@key] == @value
      end
      
      def mocha_inspect
        "has_entry(#{@key.mocha_inspect}, #{@value.mocha_inspect})"
      end
      
    end
    
  end
  
end

Version data entries

50 entries across 50 versions & 4 rubygems

Version Path
redcar-dev-0.12.1dev-java lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-dev-0.12.0dev-java lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.11 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.11.0dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.10 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.9.2 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.9.1 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.9.0 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.8.1 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.8 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.7 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.6.1 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.6 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.6.1dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5.1 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5 lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5.6dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5.5dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5.4dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb
redcar-0.5.3dev lib/openssl/mocha/lib/mocha/parameter_matchers/has_entry.rb