Skip to content

Commit

Permalink
Accept a prefix argument to filter_backtrace_with_cleaning [#1456 sta…
Browse files Browse the repository at this point in the history
…te:committed]

Add a prefix argument to filter_backtrace_with_cleaning so it has
the same arity as test/unit's filter_backtrace.

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
Manfred authored and dhh committed Nov 24, 2008
1 parent f3f67ce commit 1f48c09
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 4 additions & 6 deletions railties/lib/rails/backtrace_cleaner.rb
@@ -1,14 +1,13 @@
module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
ERB_METHOD_SIG = /:in `_run_erb_.*/

VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails )
MONGREL_DIRS = %w( lib/mongrel bin/mongrel )
RAILS_NOISE = %w( script/server )
RUBY_NOISE = %w( rubygems/custom_require benchmark.rb )

ALL_NOISE = VENDOR_DIRS + MONGREL_DIRS + RAILS_NOISE + RUBY_NOISE


def initialize
super
Expand All @@ -18,15 +17,14 @@ def initialize
end
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
def filter_backtrace_with_cleaning(backtrace)
backtrace = filter_backtrace_without_cleaning(backtrace)

def filter_backtrace_with_cleaning(backtrace, prefix=nil)
backtrace = filter_backtrace_without_cleaning(backtrace, prefix)
backtrace = backtrace.first.split("\n") if backtrace.size == 1
Rails.backtrace_cleaner.clean(backtrace)
end
Expand Down
3 changes: 2 additions & 1 deletion railties/test/abstract_unit.rb
Expand Up @@ -9,6 +9,7 @@
require 'mocha'
require 'stringio'
require 'active_support'
require 'active_support/test_case'

def uses_mocha(test_name)
yield
Expand All @@ -18,4 +19,4 @@ def uses_mocha(test_name)
RAILS_ROOT.replace File.dirname(__FILE__)
else
RAILS_ROOT = File.dirname(__FILE__)
end
end
28 changes: 28 additions & 0 deletions railties/test/backtrace_cleaner_test.rb
@@ -0,0 +1,28 @@
require 'abstract_unit'

require 'initializer'
require 'rails/backtrace_cleaner'

class TestWithBacktrace
include Test::Unit::Util::BacktraceFilter
include Rails::BacktraceFilterForTestUnit
end

class BacktraceCleanerFilterTest < ActiveSupport::TestCase
def setup
@test = TestWithBacktrace.new
@backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ]
end

test "test with backtrace should use the rails backtrace cleaner to clean" do
Rails.stubs(:backtrace_cleaner).returns(stub(:clean))
Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil)
@test.filter_backtrace(@backtrace)
end

test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do
assert_nothing_raised do
@test.filter_backtrace(@backtrace, '/opt/local/lib')
end
end
end

0 comments on commit 1f48c09

Please sign in to comment.