Sha256: 8e61b6faa2e419ba926b425997e081aba9e38518f4a012eb940d57e45259a75c

Contents?: true

Size: 1.28 KB

Versions: 117

Compression:

Stored size: 1.28 KB

Contents

require 'mocha/parameter_matchers/base'
require 'mocha/parameter_matchers/all_of'
require 'mocha/parameter_matchers/has_entry'

module Mocha
  
  module ParameterMatchers

    # :call-seq: has_entries(entries) -> parameter_matcher
    #
    # Matches +Hash+ containing all +entries+.
    #   object = mock()
    #   object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
    #   object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3)
    #   # no error raised
    #
    #   object = mock()
    #   object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
    #   object.method_1('key_1' => 1, 'key_2' => 99)
    #   # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
    def has_entries(entries)
      HasEntries.new(entries)
    end
    
    class HasEntries < Base # :nodoc:
      
      def initialize(entries)
        @entries = entries
      end
      
      def matches?(available_parameters)
        parameter = available_parameters.shift
        has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) }
        AllOf.new(*has_entry_matchers).matches?([parameter])
      end
      
      def mocha_inspect
        "has_entries(#{@entries.mocha_inspect})"
      end
      
    end
    
  end
  
end

Version data entries

117 entries across 112 versions & 13 rubygems

Version Path
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/mocha-0.9.4/lib/mocha/parameter_matchers/has_entries.rb
hashrocket-clearance-0.4.0 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
hashrocket-clearance-0.4.1 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
hashrocket-clearance-0.4.2 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
hashrocket-clearance-0.4.3 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.5.0.1240002286 lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.5.0.1240351621 lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.5.0.1241126838 lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.7.0.1247796736 lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.7.20090701124354 lib/mocha/parameter_matchers/has_entries.rb
jferris-mocha-0.9.7.20090911190113 lib/mocha/parameter_matchers/has_entries.rb
thewoolleyman-mocha-0.9.3.20081219131457 lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.2 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.3 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.4 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.5 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.6 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.7 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.8 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb
thoughtbot-clearance-0.2.9 test/rails_root/vendor/gems/mocha-0.9.1/lib/mocha/parameter_matchers/has_entries.rb