Skip to content

Commit

Permalink
Remove redundant test
Browse files Browse the repository at this point in the history
Closes #454.

I believe this test was intended to refer to the exception [1] raised in
`Mockery#verify` i.e. ExpectationError [2] when using Test::Unit and
MiniTest::Assertion [3] when using MiniTest.

When an unexpected invocation is received by a mock object, it raises
the same type of exception (see Mock#raise_unexpected_invocation_error
[4]). Thus the scenario for an unexpected invocation earlier in the same
test case gives us some related coverage.

I believe the reason why we don't want the exception class to be rescued
by a standard `rescue` is that the code under test could legitimately
include such a rescue block. If the Mocha-generated exception was
rescued by the code under test, the test failure might be swallowed or a
confusing error message might be displayed. It's much less legitimate
for code under test to rescue `Exception` and so it's preferable if the
Mocha-generated exception is a direct subclass of `Exception` and not
`StandardError`.

Having said all that the test in question is not really testing anything
useful that isn't tested elsewhere.

[1]: https://github.com/freerange/mocha/blob/8751dcbda08650a339932d86c9f24d076c167300/lib/mocha/mockery.rb#L93
[2]: https://github.com/freerange/mocha/blob/8751dcbda08650a339932d86c9f24d076c167300/lib/mocha/expectation_error.rb#L7)
[3]: https://github.com/freerange/mocha/blob/8751dcbda08650a339932d86c9f24d076c167300/lib/mocha/integration/mini_test/adapter.rb#L26
[4]: https://github.com/freerange/mocha/blob/8751dcbda08650a339932d86c9f24d076c167300/lib/mocha/mock.rb#L380)
  • Loading branch information
nitishr authored and floehopper committed Jan 20, 2020
1 parent 8751dcb commit 8e4f1a7
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions test/acceptance/exception_rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,4 @@ def test_invocation_never_expected_exception_is_not_caught_by_standard_rescue
assert_failed(test_result)
assert_equal 'unexpected invocation: #<Mock:mock>.some_method()', test_result.failure_message_lines[0]
end

def test_unsatisfied_expectation_exception_is_not_caught_by_standard_rescue
test_result = run_as_test do
mock = mock('mock')
mock.expects(:some_method)
end
assert_failed(test_result)
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, invoked never: #<Mock:mock>.some_method(any_parameters)'
], test_result.failure_message_lines
end
end

0 comments on commit 8e4f1a7

Please sign in to comment.