aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/backtrace_cleaner_test.rb
blob: 6de23acebe18d2fe877f630b5bcca1b17ebd1f4e (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
# frozen_string_literal: true

require "abstract_unit"
require "rails/backtrace_cleaner"

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

  test "should consider traces from irb lines as User code" do
    backtrace = [ "(irb):1",
                  "/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'",
                  "bin/rails:4:in `<main>'" ]
    result = @cleaner.clean(backtrace)
    assert_equal "(irb):1", result[0]
    assert_equal 1, result.length
  end

  test "can filter for noise" do
    backtrace = [ "(irb):1",
                  "/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'",
                  "bin/rails:4:in `<main>'" ]
    result = @cleaner.clean(backtrace, :noise)
    assert_equal "/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'", result[0]
    assert_equal "bin/rails:4:in `<main>'", result[1]
    assert_equal 2, result.length
  end

  test "should omit ActionView template methods names" do
    method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name
    backtrace = [ "app/views/application/index.html.erb:4:in `block in #{method_name}'"]
    result = @cleaner.clean(backtrace, :all)
    assert_equal "app/views/application/index.html.erb:4", result[0]
  end
end