2009-04-28 21:21:03 -04:00
|
|
|
require 'active_support/backtrace_cleaner'
|
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
module Rails
|
|
|
|
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
|
|
|
|
ERB_METHOD_SIG = /:in `_run_erb_.*/
|
2010-01-16 22:34:35 -05:00
|
|
|
APP_DIRS = %w( app config lib test )
|
2008-11-22 12:06:08 -05:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
2009-10-16 15:49:39 -04:00
|
|
|
add_filter { |line| line.sub("#{Rails.root}/", '') }
|
2008-11-22 12:06:08 -05:00
|
|
|
add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
|
2008-11-24 09:43:47 -05:00
|
|
|
add_filter { |line| line.sub('./', '/') } # for tests
|
2009-03-05 15:48:56 -05:00
|
|
|
|
|
|
|
add_gem_filters
|
|
|
|
|
2010-04-05 17:03:36 -04:00
|
|
|
add_silencer { |line| !APP_DIRS.any? { |dir| line =~ /^\/?#{dir}/ } }
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2009-10-20 10:32:26 -04:00
|
|
|
|
2009-03-05 15:48:56 -05:00
|
|
|
private
|
|
|
|
def add_gem_filters
|
2009-10-20 10:32:26 -04:00
|
|
|
return unless defined? Gem
|
2009-09-26 12:04:08 -04:00
|
|
|
(Gem.path + [Gem.default_dir]).uniq.each do |path|
|
2009-03-05 15:48:56 -05:00
|
|
|
# http://gist.github.com/30430
|
2010-01-16 22:34:35 -05:00
|
|
|
add_filter { |line|
|
|
|
|
line.sub(%r{(#{path})/gems/([^/]+)-([0-9.]+)/(.*)}, '\2 (\3) \4')
|
|
|
|
}
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# For installing the BacktraceCleaner in the test/unit
|
|
|
|
module BacktraceFilterForTestUnit #:nodoc:
|
|
|
|
def self.included(klass)
|
|
|
|
klass.send :alias_method_chain, :filter_backtrace, :cleaning
|
|
|
|
end
|
2008-11-24 05:25:28 -05:00
|
|
|
|
|
|
|
def filter_backtrace_with_cleaning(backtrace, prefix=nil)
|
|
|
|
backtrace = filter_backtrace_without_cleaning(backtrace, prefix)
|
2008-11-22 12:06:08 -05:00
|
|
|
backtrace = backtrace.first.split("\n") if backtrace.size == 1
|
|
|
|
Rails.backtrace_cleaner.clean(backtrace)
|
|
|
|
end
|
|
|
|
end
|
2008-12-05 12:24:28 -05:00
|
|
|
end
|