Created
May 3, 2016 17:25
-
-
Save MatiasFernandez/8453d559c2e82596c9499677e7df8af8 to your computer and use it in GitHub Desktop.
Log Capybara Exceptions
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
# Note: Add the uncommented lines inside the Application class definition inside application.rb file | |
# [...] | |
# class XYZ < Rails::Application | |
if Rails.env == 'test' | |
require 'diagnostic' | |
config.middleware.use(::Diagnostic) | |
end |
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
# Note: Put this class in 'lib' | |
class Diagnostic | |
FILENAME = File.join(Rails.root, 'log', 'test.log') | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
return @app.call(env) | |
rescue StandardError => e | |
trace = e.backtrace.select{ |l|l.start_with?(Rails.root.to_s) }.join("\n ") | |
msg = "#{e.class}\n#{e.message}\n#{trace}\n" | |
File.open(FILENAME, 'a') { |f| | |
f.write "\n" | |
f.write "\n" | |
f.write " --- BACKTRACE --- \n" | |
f.write "\n" | |
f.write msg | |
f.write "\n" | |
f.write " --- BACKTRACE --- \n" | |
f.write "\n" | |
f.write "\n" | |
} | |
raise e | |
end | |
end |
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
# Note: Make sure this setting exist inside test.rb file | |
config.action_dispatch.show_exceptions = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment