Create a gist now

Instantly share code, notes, and snippets.

exceptions are displayed in the console when integration testing with capybara
# 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