2 class BacktraceCleaner
< ActiveSupport
::BacktraceCleaner
3 ERB_METHOD_SIG
= /:in `_run_erb_.*/
5 RAILS_GEMS
= %w( actionpack activerecord actionmailer activesupport activeresource rails
)
7 VENDOR_DIRS
= %w( vendor
/rails
)
8 SERVER_DIRS
= %w( lib
/mongrel bin/mongrel
9 lib
/passenger bin/passenger-spawn-server
11 RAILS_NOISE
= %w( script
/server
)
12 RUBY_NOISE
= %w( rubygems
/custom_require benchmark
.rb
)
14 ALL_NOISE
= VENDOR_DIRS
+ SERVER_DIRS
+ RAILS_NOISE
+ RUBY_NOISE
18 add_filter
{ |line
| line
.sub("#{RAILS_ROOT}/", '') }
19 add_filter
{ |line
| line
.sub(ERB_METHOD_SIG
, '') }
20 add_filter
{ |line
| line
.sub('./', '/') } # for tests
24 add_silencer
{ |line
| ALL_NOISE
.any
? { |dir
| line
.include?(dir
) } }
25 add_silencer
{ |line
| RAILS_GEMS
.any
? { |gem
| line
=~
/^#{gem} / } }
26 add_silencer
{ |line
| line
=~
%r(vendor
/plugins/[^\
/]+/lib
) }
32 Gem
.path
.each
do |path
|
33 # http://gist.github.com/30430
34 add_filter
{ |line
| line
.sub(/(#{path})\/gems\
/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
37 vendor_gems_path
= Rails
::GemDependency.unpacked_path
.sub("#{RAILS_ROOT}/",'')
38 add_filter
{ |line
| line
.sub(/(#{vendor_gems_path})\/([a-z
]+)-([0-9.]+)\
/(.*)/, '\2 (\3) [v] \4')}
42 # For installing the BacktraceCleaner in the test/unit
43 module BacktraceFilterForTestUnit
#:nodoc:
44 def self.included(klass
)
45 klass
.send
:alias_method_chain, :filter_backtrace, :cleaning
48 def filter_backtrace_with_cleaning(backtrace
, prefix
=nil)
49 backtrace
= filter_backtrace_without_cleaning(backtrace
, prefix
)
50 backtrace
= backtrace
.first
.split("\n") if backtrace
.size
== 1
51 Rails
.backtrace_cleaner
.clean(backtrace
)