Created
August 4, 2014 16:28
-
-
Save cupakromer/234e5468586c5aa3daa3 to your computer and use it in GitHub Desktop.
Check raise error with backtrace
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
def capture_backtrace(with_error: StandardError, &action) | |
action.call | |
:no_error_raised | |
rescue with_error => e | |
e.backtrace | |
end | |
# This fails if SocketError is not raised, | |
# or if the message doesn't match | |
it "raises a socket error reporting the address info" do | |
expect{ zone.sync_update }.to raise_error(SocketError) | |
.with_message('getaddrinfo: Name or service not known: example.com') | |
end | |
# Fails if SocketError is not raised, or if | |
# nothing is raised. If nothing is raised the error is: | |
# expected :no_error_raised to include /.../, but it does not respond to `include?` | |
it "keeps the original backtrace details" do | |
expected_failure_callsite = /lib\/zone_sync.rb:88:in `getaddrinfo\'\z/ | |
expect( | |
capture_backtrace(with_error: SocketError) { zone.sync_update } | |
).to include expected_failure_callsite | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment