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

Merged
merged 1 commit into from Mar 9, 2012
View
@@ -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:
@@ -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)