diff --git a/lib/telebugs/middleware/gem_root_filter.rb b/lib/telebugs/middleware/gem_root_filter.rb index a9e6b58..c5f3fe9 100644 --- a/lib/telebugs/middleware/gem_root_filter.rb +++ b/lib/telebugs/middleware/gem_root_filter.rb @@ -42,8 +42,13 @@ def format_file(file) parts = file.split("/") gem_info = parts[0].split("-") - gem_name = gem_info[0] - gem_version = gem_info[1] + if gem_info.size < 2 + gem_name = gem_info[0] + gem_version = gem_info[1] + else + gem_name = gem_info[0..-2].join("-") + gem_version = gem_info[-1] + end file_path = parts[1..].join("/") diff --git a/test/middleware/test_gem_root_filter.rb b/test/middleware/test_gem_root_filter.rb index 6e11ab9..4a32c88 100644 --- a/test/middleware/test_gem_root_filter.rb +++ b/test/middleware/test_gem_root_filter.rb @@ -4,21 +4,26 @@ class TestGemRootFilter < Minitest::Test def test_gem_root_filter - begin - raise StandardError.new("test error") - rescue => e - report = Telebugs::Report.new(e) - end + gem_path = Gem.path.first + e = StandardError.new("test error") + e.set_backtrace([ + "#{gem_path}/gems/minitest-5.14.0/lib/minitest/test.rb:3:in `block in '", + "/test/middleware/test_gem_root_filter.rb:3:in `test_gem_root_filter'", + "#{gem_path}/gems/turbo-rails-2.0.5/lib/turbo-rails.rb:3:in `block in '", + "#{gem_path}/gems/turbo-turbo-rails-rails-2.0.5/lib/turbo-rails.rb:3:in `block in '", + "#{gem_path}/gems/turbo_turbo_rails-2.0.5/lib/turbo-rails.rb:3:in `block in '" + ]) + + report = Telebugs::Report.new(e) Telebugs::Middleware::GemRootFilter.new.call(report) - assert_match( - %r{/test/middleware/test_gem_root_filter.rb}, - report.data[:errors][0][:backtrace][0][:file] - ) - assert_match( - %r{\Aminitest \(.+\..+\..+\) lib/minitest/test.rb\z}, - report.data[:errors][0][:backtrace][1][:file] - ) + assert_equal [ + "minitest (5.14.0) lib/minitest/test.rb", + "/test/middleware/test_gem_root_filter.rb", + "turbo-rails (2.0.5) lib/turbo-rails.rb", + "turbo-turbo-rails-rails (2.0.5) lib/turbo-rails.rb", + "turbo_turbo_rails (2.0.5) lib/turbo-rails.rb" + ], report.data[:errors].first[:backtrace].map { |f| f[:file] } end end