Skip to content

Commit

Permalink
Fixed bug with stubbed methods and never
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinesh Majrekar committed Feb 11, 2009
1 parent 03f8694 commit 6c805cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mocha/expectation.rb
Expand Up @@ -105,6 +105,8 @@ def once
# # => verify succeeds
def never
@cardinality = Cardinality.exactly(0)
@mock.expectations.to_a.delete_if{ |e| e.match?(@method_matcher.expected_method_name) and not e == self} if
@mock.expectations.matches_method?(@method_matcher.expected_method_name)
self
end

Expand Down
12 changes: 12 additions & 0 deletions test/acceptance/expected_invocation_count_test.rb
Expand Up @@ -173,6 +173,18 @@ def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_eve
assert_passed(test_result)
end


def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_after_it_has_been_stubbed
test_result = run_as_test do
o = mock('stub')
o.stubs(:method)
o.expects(:method).never
1.times { o.method }
end
assert_failed(test_result)
assert_equal ["unexpected invocation: #<Mock:stub>.method()\nsatisfied expectations:\n- expected never, not yet invoked: #<Mock:stub>.method(any_parameters)\n"], test_result.failure_messages
end

def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed
test_result = run_as_test do
stub = stub_everything('stub')
Expand Down

0 comments on commit 6c805cb

Please sign in to comment.