mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
54fd6de064
This breaks test-all: * two test-all errors (test_run_passing and test_run_failing_filtered). * -v option to test-all is ignored Additional to say, please describe summary of the change when you import from external repository. And, RUN test-all BEFORE COMMIT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
38 lines
1.2 KiB
Ruby
38 lines
1.2 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
|
|
|
|
module MiniTest
|
|
class Mock
|
|
def initialize
|
|
@expected_calls = {}
|
|
@actual_calls = Hash.new {|h,k| h[k] = [] }
|
|
end
|
|
|
|
def expect(name, retval, args=[])
|
|
n, r = name, retval # for the closure below
|
|
@expected_calls[name] = { :retval => retval, :args => args }
|
|
self.class.__send__ :remove_method, name if respond_to? name
|
|
self.class.__send__(:define_method, name) { |*x|
|
|
raise ArgumentError unless @expected_calls[n][:args].size == x.size
|
|
@actual_calls[n] << { :retval => r, :args => x }
|
|
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
|
|
end
|