Permalink
Browse files

Mention when a method with an expectation is unstubbed. Fixes #5.

  • Loading branch information...
1 parent 650afb0 commit 17dc7d2a114d227649016ae4d6e4286ef2902252 @tristandunn tristandunn committed Mar 9, 2012
Showing with 15 additions and 1 deletion.
  1. +9 −1 lib/bourne/api.rb
  2. +6 −0 test/acceptance/spy_test.rb
View
10 lib/bourne/api.rb
@@ -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
@@ -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:
View
6 test/acceptance/spy_test.rb
@@ -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)

0 comments on commit 17dc7d2

Please sign in to comment.