Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created July 12, 2011 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/1079020 to your computer and use it in GitHub Desktop.
Save ngauthier/1079020 to your computer and use it in GitHub Desktop.
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