Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Created August 4, 2014 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cupakromer/234e5468586c5aa3daa3 to your computer and use it in GitHub Desktop.
Save cupakromer/234e5468586c5aa3daa3 to your computer and use it in GitHub Desktop.
Check raise error with backtrace
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