public
Created

exceptions are displayed in the console when integration testing with capybara

  • Download Gist
test_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.