aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/backtrace_cleaner_test.rb
blob: 7a1b36144054aa39ada979ad418fc2b4e8ed331f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'abstract_unit'

require 'initializer'
require 'rails/backtrace_cleaner'

if defined? Test::Unit::Util::BacktraceFilter
  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
else
  $stderr.puts 'No BacktraceFilter for minitest'
end

class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
  def setup
    @cleaner = Rails::BacktraceCleaner.new
  end

  test "should format installed gems correctly" do
    @backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
    @result = @cleaner.clean(@backtrace)
    assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
  end

  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" ]
      @result = @cleaner.clean(@backtrace)
      assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
    end
  end

  test "should format vendor gems correctly" do
    @backtrace = [ "#{Rails::GemDependency.unpacked_path}/nosuchgem-1.2.3/lib/foo.rb" ]
    @result = @cleaner.clean(@backtrace)
    assert_equal "nosuchgem (1.2.3) [v] lib/foo.rb", @result[0]
  end

end