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
|
|
|
|
|
|
|
|
test "should format installed gems correctly" do
|
2016-07-01 19:33:26 -04:00
|
|
|
backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @cleaner.clean(backtrace, :all)
|
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0]
|
2012-05-02 06:56:13 -04:00
|
|
|
end
|
2009-03-05 15:48:56 -05:00
|
|
|
|
2012-05-02 06:56:13 -04:00
|
|
|
test "should format installed gems not in Gem.default_dir correctly" do
|
2016-07-01 19:33:26 -04:00
|
|
|
target_dir = Gem.path.detect { |p| p != Gem.default_dir }
|
2012-05-02 06:56:13 -04:00
|
|
|
# skip this test if default_dir is the only directory on Gem.path
|
2016-11-25 20:55:11 -05:00
|
|
|
if target_dir
|
2016-07-01 19:33:26 -04:00
|
|
|
backtrace = [ "#{target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
|
|
|
|
result = @cleaner.clean(backtrace, :all)
|
|
|
|
assert_equal "nosuchgem (1.2.3) lib/foo.rb", result[0]
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|
2009-10-20 10:32:26 -04:00
|
|
|
end
|
2016-07-01 19:33:26 -04:00
|
|
|
|
|
|
|
test "should consider traces from irb lines as User code" do
|
|
|
|
backtrace = [ "from (irb):1",
|
|
|
|
"from /Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'",
|
|
|
|
"from bin/rails:4:in `<main>'" ]
|
|
|
|
result = @cleaner.clean(backtrace, :all)
|
|
|
|
assert_equal "from (irb):1", result[0]
|
|
|
|
end
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|