1 class MockExpectationError < StandardError; end
8 @actual_calls = Hash.new {|h,k| h[k] = [] }
11 def expect(name, retval, args=[])
12 n, r, a = name, retval, args # for the closure below
13 @expected_calls[name] = { :retval => retval, :args => args }
14 self.class.__send__(:define_method, name) { |*a|
15 raise ArgumentError unless @expected_calls[n][:args].size == a.size
16 @actual_calls[n] << { :retval => r, :args => a }
23 @expected_calls.each_key do |name|
24 expected = @expected_calls[name]
25 msg = "expected #{name}, #{expected.inspect}"
26 raise MockExpectationError, msg unless
27 @actual_calls.has_key? name and @actual_calls[name].include?(expected)