Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests for the change in fdcb150 where Mocha::ExpectationEr…
…ror became an Exception not just a StandardError. See the following for more details :- https://github.com/floehopper/mocha/issues#issue/15 http://floehopper.lighthouseapp.com/projects/22289/tickets/1-mochaexpectationerror-exception
- Loading branch information
1 parent
fdcb150
commit e2c5f3e
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require File.expand_path('../acceptance_test_helper', __FILE__) | ||
require 'mocha' | ||
|
||
class ExceptionRescueTest < Test::Unit::TestCase | ||
|
||
include AcceptanceTest | ||
|
||
def setup | ||
setup_acceptance_test | ||
end | ||
|
||
def teardown | ||
teardown_acceptance_test | ||
end | ||
|
||
def test_unexpected_invocation_exception_is_not_caught_by_standard_rescue | ||
test_result = run_as_test do | ||
mock = mock('mock') | ||
begin | ||
mock.some_method | ||
rescue => e | ||
flunk "should not rescue #{e.class}" | ||
end | ||
end | ||
assert_failed(test_result) | ||
failure_message_lines = test_result.failure_messages.first.split("\n") | ||
assert_equal "unexpected invocation: #<Mock:mock>.some_method()", failure_message_lines.first | ||
end | ||
|
||
def test_invocation_never_expected_exception_is_not_caught_by_standard_rescue | ||
test_result = run_as_test do | ||
mock = mock('mock') | ||
mock.expects(:some_method).never | ||
begin | ||
mock.some_method | ||
rescue => e | ||
flunk "should not rescue #{e.class}" | ||
end | ||
end | ||
assert_failed(test_result) | ||
failure_message_lines = test_result.failure_messages.first.split("\n") | ||
assert_equal "unexpected invocation: #<Mock:mock>.some_method()", failure_message_lines.first | ||
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) | ||
failure_message_lines = test_result.failure_messages.first.split("\n") | ||
assert_equal [ | ||
"not all expectations were satisfied", | ||
"unsatisfied expectations:", | ||
"- expected exactly once, not yet invoked: #<Mock:mock>.some_method(any_parameters)" | ||
], failure_message_lines | ||
end | ||
end |