Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def generate_id(example)
def adjust_backtrace(backtrace)
# Correct the backtrace entry so that vscode recognized it as a link to open
parts = backtrace.split(":", 3)
return backtrace if parts.length < 2

parts[0].sub(/^\./, "file://" + File.expand_path(".")) + ":" + parts[1] + " : " + (parts[2] || "")
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/chained_exception_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require_relative "../../lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter"

RSpec.configure do |config|
config.formatter = "RubyLsp::RSpec::RSpecFormatter"
end

RSpec.describe "ChainedExceptionExample" do
it "fails with a chained error" do
raise "secondary error"
rescue
raise "primary error"
end
end
9 changes: 9 additions & 0 deletions spec/rspec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@
expect(events).to match(expected)
end

it "does not crash when formatting backtrace from chained exceptions" do
fixture_path = File.expand_path("spec/fixtures/chained_exception_spec.rb")

stdout, stderr, = Open3.capture3("bundle", "exec", "rspec", fixture_path)

output = stdout + stderr
expect(output).not_to include("adjust_backtrace")
end

describe "RubyLsp::RSpec::RSpecFormatter notifications" do
let(:output) { StringIO.new }
let(:formatter) { RubyLsp::RSpec::RSpecFormatter.new(output) }
Expand Down