File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
lib/ruby_lsp/ruby_lsp_rspec Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,10 @@ def example_failed(notification)
45
45
example = notification . example
46
46
uri = uri_for ( example )
47
47
id = generate_id ( example )
48
- RubyLsp ::LspReporter . instance . record_fail ( id : id , message : notification . exception . message , uri : uri )
48
+ message = notification . message_lines . join ( "\n " )
49
+ message << "\n \n "
50
+ message << notification . formatted_backtrace . map ( &method ( :adjust_backtrace ) ) . map { |s | "# " + s } . join ( "\n " )
51
+ RubyLsp ::LspReporter . instance . record_fail ( id : id , message : message , uri : uri )
49
52
end
50
53
51
54
def example_pending ( notification )
@@ -69,6 +72,12 @@ def uri_for(example)
69
72
def generate_id ( example )
70
73
[ example , *example . example_group . parent_groups ] . reverse . map ( &:location ) . join ( "::" )
71
74
end
75
+
76
+ def adjust_backtrace ( backtrace )
77
+ # Correct the backtrace entry so that vscode recognized it as a link to open
78
+ parts = backtrace . split ( ":" , 3 )
79
+ parts [ 0 ] . sub ( /^\. / , "file://" + File . expand_path ( "." ) ) + ":" + parts [ 1 ] + " : " + parts [ 2 ]
80
+ end
72
81
end
73
82
end
74
83
end
Original file line number Diff line number Diff line change 82
82
"method" => "fail" ,
83
83
"params" => {
84
84
"id" => "./spec/fixtures/rspec_example_spec.rb:11::./spec/fixtures/rspec_example_spec.rb:12::./spec/fixtures/rspec_example_spec.rb:17" ,
85
- "message" => " \n expected : 1\n got: 2\n \n (compared using ==)\n " ,
85
+ "message" => %r{Failure/Error: expect \( 2 \) .to eq \( 1 \) \n \n expected : 1\n got: 2\n \n \ ( compared using ==\ )\n \n # file:// #{ fixture_path } :18 : in [`']block \( 3 levels \) in <top \( required \) >'} ,
86
86
"uri" => "file://#{ fixture_path } " ,
87
87
} ,
88
88
} ,
128
128
"method" => "fail" ,
129
129
"params" => {
130
130
"id" => "./spec/fixtures/rspec_example_spec.rb:11::./spec/fixtures/rspec_example_spec.rb:12::./spec/fixtures/rspec_example_spec.rb:30" ,
131
- "message" => "oops" ,
131
+ "message" => %r{Failure/Error: raise "oops"\n \n RuntimeError: \n oops \n \n # file:// #{ fixture_path } :31 : in [`']block \( 3 levels \) in <top \( required \) >'} ,
132
132
"uri" => "file://#{ fixture_path } " ,
133
133
} ,
134
134
} ,
135
135
{ "method" => "finish" , "params" => { } } ,
136
136
]
137
137
138
- expect ( events ) . to eq ( expected )
138
+ expect ( events ) . to match ( expected )
139
139
end
140
140
141
141
describe "RubyLsp::RSpec::RSpecFormatter notifications" do
175
175
end
176
176
177
177
it "invokes ProgressFormatter's example_failed" do
178
- exception = double ( "Exception" , message : "error message" )
179
- allow ( notification ) . to receive ( :exception ) . and_return ( exception )
178
+ allow ( notification ) . to receive ( :message_lines ) . and_return ( [ " message lines" ] )
179
+ allow ( notification ) . to receive ( :formatted_backtrace ) . and_return ( [ "spec/example_spec.rb:13:in `something'" ] )
180
180
181
181
expect_any_instance_of ( RSpec ::Core ::Formatters ::ProgressFormatter ) . to receive ( :example_failed )
182
182
You can’t perform that action at this time.
0 commit comments