Skip to content

Commit

Permalink
+ Mocked methods can take a block to verify state. Seattle.rb 12 bday…
Browse files Browse the repository at this point in the history
… present from ernie! Thanks!!

[git-p4: depot-paths = "//src/minitest/dev/": change = 9245]
  • Loading branch information
zenspider committed Feb 26, 2014
1 parent 0ef1f88 commit 80041ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/minitest/mock.rb
Expand Up @@ -109,7 +109,7 @@ def verify
true
end

def method_missing(sym, *args) # :nodoc:
def method_missing(sym, *args, &block) # :nodoc:
unless @expected_calls.has_key?(sym) then
raise NoMethodError, "unmocked method %p, expected one of %p" %
[sym, @expected_calls.keys.sort_by(&:to_s)]
Expand All @@ -128,7 +128,7 @@ def method_missing(sym, *args) # :nodoc:

if val_block then
raise MockExpectationError, "mocked method %p failed block w/ %p" %
[sym, args] unless val_block.call(args)
[sym, args] unless val_block.call(*args, &block)

# keep "verify" happy
@actual_calls[sym] << expected_call
Expand Down
11 changes: 11 additions & 0 deletions test/minitest/test_minitest_mock.rb
Expand Up @@ -265,6 +265,17 @@ def test_mock_block_is_passed_function_params
assert mock.verify
end

def test_mock_block_is_passed_function_block
mock = MiniTest::Mock.new
block = proc { 'bar' }
mock.expect :foo, nil do |arg, &blk|
arg == 'foo' &&
blk == block
end
mock.foo 'foo', &block
assert mock.verify
end

def test_verify_fails_when_mock_block_returns_false
mock = Minitest::Mock.new
mock.expect :foo, nil do
Expand Down

0 comments on commit 80041ef

Please sign in to comment.