slightly better handling of template exceptions

This commit is contained in:
John Bintz 2013-02-27 17:24:31 -05:00
parent 0f05be7928
commit 0aeb59d65c

View File

@ -8,9 +8,11 @@ module Capybara
end end
def logger(level = nil) def logger(level = nil)
logger = Logger.new(logger_target) return @logger if @logger
logger.level = level || default_log_level
logger @logger = Logger.new(logger_target)
@logger.level = level || default_log_level
@logger
end end
attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level, :filter_request_starts attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level, :filter_request_starts
@ -42,6 +44,11 @@ module Capybara
def add_backtrace(exception) def add_backtrace(exception)
clean_backtrace(exception).each { |line| logger_target << " #{line.strip}\n" } clean_backtrace(exception).each { |line| logger_target << " #{line.strip}\n" }
end end
def output_line(line, target = $stderr)
target.print(Term::ANSIColor.red, line, Term::ANSIColor.reset)
target.flush
end
end end
def reset_logs def reset_logs
@ -55,7 +62,7 @@ module Capybara
lines = Capybara::RailsLogInspection.logger_target.read.lines lines = Capybara::RailsLogInspection.logger_target.read.lines
Capybara::RailsLogInspection.clean_rack_output(lines).each do |line| Capybara::RailsLogInspection.clean_rack_output(lines).each do |line|
target.print(Term::ANSIColor.red, line, Term::ANSIColor.reset) output_line(line, target)
end end
reset_logs reset_logs
@ -63,8 +70,20 @@ module Capybara
end end
end end
Rails.logger = Capybara::RailsLogInspection.logger Rails.logger = Capybara::RailsLogInspection.logger
class LogInspectionSubscriber < ActiveSupport::LogSubscriber
def process_action(event)
if event.payload[:exception]
Capybara::RailsLogInspection.output_line "Processing #{event.payload[:method]} #{event.payload[:controller]}##{event.payload[:action]} as #{event.payload[:format]}\n"
Capybara::RailsLogInspection.output_line " #{event.payload[:exception].first}: #{event.payload[:exception].last}\n"
end
end
end
LogInspectionSubscriber.attach_to :action_controller
Capybara.server do |app, port| Capybara.server do |app, port|
require 'rack/handler/webrick' require 'rack/handler/webrick'