1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/mini/mock.rb
ryan abef077ec7 Added miniunit 1.3.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 21:36:05 +00:00

37 lines
1.1 KiB
Ruby

############################################################
# This file is imported from a different project.
# DO NOT make modifications in this repo.
# File a patch instead and assign it to Ryan Davis
############################################################
class MockExpectationError < StandardError; end
require 'mini/test'
class Mini::Mock
def initialize
@expected_calls = {}
@actual_calls = Hash.new {|h,k| h[k] = [] }
end
def expect(name, retval, args=[])
n, r, a = name, retval, args # for the closure below
@expected_calls[name] = { :retval => retval, :args => args }
self.class.__send__(:define_method, name) { |*a|
raise ArgumentError unless @expected_calls[n][:args].size == a.size
@actual_calls[n] << { :retval => r, :args => a }
retval
}
self
end
def verify
@expected_calls.each_key do |name|
expected = @expected_calls[name]
msg = "expected #{name}, #{expected.inspect}"
raise MockExpectationError, msg unless
@actual_calls.has_key? name and @actual_calls[name].include?(expected)
end
true
end
end