diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-10 01:18:03 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-10 01:18:03 +0000 |
commit | 7ebbb3871e473dca485993759b07a9a86d84d70c (patch) | |
tree | 7ccd6a46b401d455cd0dc8de7037d90fbc4a7f70 /lib/minitest/mock.rb | |
parent | 30e76a6af3f1ea21552a566680a19254e1c005fb (diff) |
Added minitest 1.3.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/minitest/mock.rb')
-rw-r--r-- | lib/minitest/mock.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/minitest/mock.rb b/lib/minitest/mock.rb new file mode 100644 index 0000000000..54af28c453 --- /dev/null +++ b/lib/minitest/mock.rb @@ -0,0 +1,37 @@ +############################################################ +# 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, a = name, retval, args # for the closure below + @expected_calls[name] = { :retval => retval, :args => args } + 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 |