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_.*/
|
2008-11-24 05:25:28 -05:00
|
|
|
|
2009-03-05 06:22:42 -05:00
|
|
|
RAILS_GEMS = %w( actionpack activerecord actionmailer activesupport activeresource rails )
|
|
|
|
|
2009-03-05 15:48:56 -05:00
|
|
|
VENDOR_DIRS = %w( vendor/rails )
|
2008-12-05 12:24:28 -05:00
|
|
|
SERVER_DIRS = %w( lib/mongrel bin/mongrel
|
|
|
|
lib/passenger bin/passenger-spawn-server
|
|
|
|
lib/rack )
|
2008-11-22 12:06:08 -05:00
|
|
|
RAILS_NOISE = %w( script/server )
|
|
|
|
RUBY_NOISE = %w( rubygems/custom_require benchmark.rb )
|
|
|
|
|
2008-11-29 04:45:52 -05:00
|
|
|
ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE
|
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
|
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } }
|
2009-03-05 06:22:42 -05:00
|
|
|
add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
|
2008-12-30 21:25:44 -05:00
|
|
|
add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
|
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
|
|
|
|
add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
|
|
|
|
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
|