Created
July 12, 2011 21:29
-
-
Save ngauthier/1079020 to your computer and use it in GitHub Desktop.
exceptions are displayed in the console when integration testing with capybara
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
# Given an application, yield to a block to handle exceptions | |
class ExceptionRaiserApp | |
def initialize(app, &block) | |
@app = app | |
@block = block | |
end | |
def call(env) | |
@app.call(env) | |
rescue => e | |
@block.call(e) | |
end | |
end | |
# Wrap ShortmailApp with the exception raiser | |
Capybara.app = ExceptionRaiserApp.new(ShortmailApp::Application) do |exception| | |
# Write to standard error | |
$stderr.write [ | |
# The name of the exception and its message | |
exception.to_s + ": "+ exception.message, | |
# And a nice clean rails backtrace | |
Rails.backtrace_cleaner.clean(exception.backtrace, :silent), | |
nil | |
].join("\n\t")+"\n" | |
# Then re-raise so capybara gets a 500 and knows what's up | |
raise exception | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment