Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Mention when a method with an expectation is unstubbed. Fixes #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Mar 9, 2012
1 parent 650afb0 commit 17dc7d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/bourne/api.rb
Expand Up @@ -51,7 +51,9 @@ def does_not_match?(mock)
end

def failure_message
@expectation.mocha_inspect
message = ""
message << "unstubbed, " if matching_stubs.length == 0
message << @expectation.mocha_inspect
end

private
Expand All @@ -71,6 +73,12 @@ def invocations
invocation.mock.equal?(@mock)
end
end

def matching_stubs
Mockery.instance.stubba.stubba_methods.select do |method|
method.mock.equal?(@mock) && method.method == @expected_method_name
end
end
end

# :call-seq:
Expand Down
6 changes: 6 additions & 0 deletions test/acceptance/spy_test.rb
Expand Up @@ -95,6 +95,12 @@ def test_should_not_allow_should_not
flunk("Expected to fail")
end

def test_should_warn_for_unstubbed_methods_with_expectations
new_instance.stubs(:unknown)

assert_fails(/unstubbed, expected exactly once/) { assert_matcher_accepts have_received(:unknown), new_instance }
end

def test_should_reject_not_enough_calls
instance = new_instance
instance.stubs(:magic)
Expand Down

0 comments on commit 17dc7d2

Please sign in to comment.