2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "rails/backtrace_cleaner"
|
2008-11-24 05:25:28 -05:00
|
|
|
|
2016-07-01 19:33:26 -04:00
|
|
|
class BacktraceCleanerTest < ActiveSupport::TestCase
|
2012-05-02 06:56:13 -04:00
|
|
|
def setup
|
|
|
|
@cleaner = Rails::BacktraceCleaner.new
|
|
|
|
end
|
|
|
|
|
2016-07-01 19:33:26 -04:00
|
|
|
test "should consider traces from irb lines as User code" do
|
2018-08-06 01:40:49 -04:00
|
|
|
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
|
2016-07-01 19:33:26 -04:00
|
|
|
end
|
2018-08-06 23:17:01 -04:00
|
|
|
|
2019-10-03 16:58:08 -04:00
|
|
|
test "should show relative paths" do
|
|
|
|
backtrace = [ "./test/backtrace_cleaner_test.rb:123",
|
|
|
|
"/Path/to/rails/activesupport/some_testing_file.rb:42:in `test'",
|
|
|
|
"bin/rails:4:in `<main>'" ]
|
|
|
|
result = @cleaner.clean(backtrace)
|
|
|
|
assert_equal "./test/backtrace_cleaner_test.rb:123", result[0]
|
|
|
|
assert_equal 1, result.length
|
|
|
|
end
|
|
|
|
|
2019-04-14 21:22:43 -04:00
|
|
|
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
|
|
|
|
|
2018-08-06 23:17:01 -04:00
|
|
|
test "should omit ActionView template methods names" do
|
2019-03-08 17:52:22 -05:00
|
|
|
method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name
|
2018-08-06 23:17:01 -04:00
|
|
|
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
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|