more tweaks and stuff
This commit is contained in:
parent
d29ece1ee2
commit
5bb15600b7
@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|||||||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||||
gem.name = "capybara-rails-log-inspection"
|
gem.name = "capybara-rails-log-inspection"
|
||||||
gem.require_paths = ["lib"]
|
gem.require_paths = ["lib"]
|
||||||
gem.version = Capybara::Rails::LogInspection::VERSION
|
gem.version = Capybara::RailsLogInspection::VERSION
|
||||||
|
|
||||||
gem.add_runtime_dependency 'term-ansicolor'
|
gem.add_runtime_dependency 'term-ansicolor'
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
module Capybara
|
module Capybara
|
||||||
module Rails
|
module RailsLogInspection
|
||||||
module LogInspection
|
VERSION = "0.0.1"
|
||||||
VERSION = "0.0.1"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,27 +13,34 @@ module Capybara
|
|||||||
logger
|
logger
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level
|
attr_writer :backtrace_clean_patterns, :default_log_level, :rack_log_level, :filter_request_starts
|
||||||
|
|
||||||
def default_log_level
|
def default_log_level
|
||||||
Logger::WARN
|
Logger::INFO
|
||||||
end
|
end
|
||||||
|
|
||||||
def rack_log_level
|
def rack_log_level
|
||||||
Logger::WARN
|
Logger::WARN
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_request_starts
|
||||||
|
@filter_request_starts ||= true
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_rack_output(lines)
|
||||||
|
lines.collect(&:strip).reject { |line| line.empty? || (filter_request_starts && line[%r{^Started }]) }
|
||||||
|
end
|
||||||
|
|
||||||
def backtrace_clean_patterns
|
def backtrace_clean_patterns
|
||||||
@backtrace_clean_patterns ||= [ %r{/gems/}, %r{/ruby/1} ]
|
@backtrace_clean_patterns ||= [ %r{/gems/}, %r{/ruby/1} ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_backtrace(exception)
|
def clean_backtrace(exception)
|
||||||
exception.backtrace.reject { |line| line.empty? || backtrace_clean_patterns.any? { |pattern| line[pattern] } }
|
exception.backtrace.collect(&:strip).reject { |line| line.empty? || backtrace_clean_patterns.any? { |pattern| line[pattern] } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_backtrace(exception)
|
def add_backtrace(exception)
|
||||||
clean_backtrace(exception).each { |line| logger_target << " #{line}\n" }
|
clean_backtrace(exception).each { |line| logger_target << " #{line}" }
|
||||||
logger_target << "\n"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,8 +52,11 @@ module Capybara
|
|||||||
def output_logs(target = $stderr)
|
def output_logs(target = $stderr)
|
||||||
Capybara::RailsLogInspection.logger_target.rewind
|
Capybara::RailsLogInspection.logger_target.rewind
|
||||||
|
|
||||||
data = Capybara::RailsLogInspection.logger_target.read
|
lines = Capybara::RailsLogInspection.logger_target.read.lines
|
||||||
target.print(Term::ANSIColor.red, data, Term::ANSIColor.reset) if !data.empty?
|
|
||||||
|
Capybara::RailsLogInspection.clean_rack_output(lines).each do |line|
|
||||||
|
target.puts(Term::ANSIColor.red, line, Term::ANSIColor.reset)
|
||||||
|
end
|
||||||
|
|
||||||
reset_logs
|
reset_logs
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user