Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Trap Capybara Stack Trace
### Show stack trace for 500 errors
### (adapted from https://gist.github.com/1079020)
# Given an application, yield to a block to handle exceptions
class ExceptionRaiserApp
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
rescue => e
backtrace = [ "#{'*'*20} #{e.to_s} #{'*'*20}",
'',
e.message,
'',
Rails.backtrace_cleaner.clean(e.backtrace, :silent),
'',
'*'*80,
'' ].join("\n\t")
# log the backtrace
Rails.logger.error backtrace
# re-raise so capybara gets a 500 and knows what's up
raise e
end
end
Capybara.app = ExceptionRaiserApp.new(MyApp::Application)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment