2008-11-24 05:25:28 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'rails/backtrace_cleaner'
|
|
|
|
|
2009-02-27 15:18:45 -05:00
|
|
|
if defined? Test::Unit::Util::BacktraceFilter
|
|
|
|
class TestWithBacktrace
|
|
|
|
include Test::Unit::Util::BacktraceFilter
|
|
|
|
include Rails::BacktraceFilterForTestUnit
|
2008-11-24 05:25:28 -05:00
|
|
|
end
|
2009-02-27 15:18:45 -05:00
|
|
|
|
|
|
|
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
|
2009-09-26 12:04:08 -04:00
|
|
|
|
2009-02-27 15:18:45 -05:00
|
|
|
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)
|
2009-11-11 00:04:00 -05:00
|
|
|
@test.send(:filter_backtrace, @backtrace)
|
2009-02-27 15:18:45 -05:00
|
|
|
end
|
2009-09-26 12:04:08 -04:00
|
|
|
|
2009-02-27 15:18:45 -05:00
|
|
|
test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do
|
|
|
|
assert_nothing_raised do
|
2009-11-11 00:04:00 -05:00
|
|
|
@test.send(:filter_backtrace, @backtrace, '/opt/local/lib')
|
2009-02-27 15:18:45 -05:00
|
|
|
end
|
2008-11-24 05:25:28 -05:00
|
|
|
end
|
|
|
|
end
|
2009-02-27 15:18:45 -05:00
|
|
|
else
|
|
|
|
$stderr.puts 'No BacktraceFilter for minitest'
|
|
|
|
end
|
2009-03-05 15:48:56 -05:00
|
|
|
|
2009-10-20 10:32:26 -04:00
|
|
|
if defined? Gem
|
|
|
|
class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cleaner = Rails::BacktraceCleaner.new
|
|
|
|
end
|
2009-03-05 15:48:56 -05:00
|
|
|
|
2009-10-20 10:32:26 -04:00
|
|
|
test "should format installed gems correctly" do
|
|
|
|
@backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
2010-01-16 22:34:35 -05:00
|
|
|
@result = @cleaner.clean(@backtrace, :all)
|
2009-03-05 15:48:56 -05:00
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
|
|
|
|
end
|
|
|
|
|
2009-10-20 10:32:26 -04:00
|
|
|
test "should format installed gems not in Gem.default_dir correctly" do
|
|
|
|
@target_dir = Gem.path.detect { |p| p != Gem.default_dir }
|
|
|
|
# skip this test if default_dir is the only directory on Gem.path
|
|
|
|
if @target_dir
|
|
|
|
@backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
2010-01-16 22:34:35 -05:00
|
|
|
@result = @cleaner.clean(@backtrace, :all)
|
2009-10-20 10:32:26 -04:00
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|