~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/mocha-0.5.6/lib/mocha/parameter_matchers/has_entries.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'mocha/parameter_matchers/base'
 
2
 
 
3
module Mocha
 
4
  
 
5
  module ParameterMatchers
 
6
 
 
7
    # :call-seq: has_entries(entries) -> parameter_matcher
 
8
    #
 
9
    # Matches +Hash+ containing all +entries+.
 
10
    #   object = mock()
 
11
    #   object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
 
12
    #   object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3)
 
13
    #   # no error raised
 
14
    #
 
15
    #   object = mock()
 
16
    #   object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
 
17
    #   object.method_1('key_1' => 1, 'key_2' => 99)
 
18
    #   # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
 
19
    def has_entries(entries)
 
20
      HasEntries.new(entries)
 
21
    end
 
22
    
 
23
    class HasEntries < Base # :nodoc:
 
24
      
 
25
      def initialize(entries)
 
26
        @entries = entries
 
27
      end
 
28
      
 
29
      def matches?(available_parameters)
 
30
        parameter = available_parameters.shift
 
31
        @entries.all? { |key, value| parameter[key] == value }
 
32
      end
 
33
      
 
34
      def mocha_inspect
 
35
        "has_entries(#{@entries.mocha_inspect})"
 
36
      end
 
37
      
 
38
    end
 
39
    
 
40
  end
 
41
  
 
42
end
 
 
b'\\ No newline at end of file'