Skip to content

Commit 5583a56

Browse files
authored
Correct test IDs based on relative path
When running rspec from a parent directory the example's location used to generate the test IDs will not match how the tests are registered in the LSP. By defining the envvar RUBY_LSP_RSPEC_RELPATH the path prefix will be removed for while generating the test IDs so that they align up.
1 parent 3ac0633 commit 5583a56

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class RSpecFormatter
1818

1919
def initialize(output)
2020
@output = output
21+
@relative_path = ENV["RUBY_LSP_RSPEC_RELPATH"]
2122
end
2223

2324
def example_started(notification)
@@ -59,7 +60,12 @@ def uri_for(example)
5960
end
6061

6162
def generate_id(example)
62-
[example, *example.example_group.parent_groups].reverse.map(&:location).join("::")
63+
[example, *example.example_group.parent_groups].reverse.map(&:location).map(&method(:make_relative)).join("::")
64+
end
65+
66+
def make_relative(location)
67+
return location unless @relative_path
68+
location.sub(/^#{@relative_path}/, "./")
6369
end
6470
end
6571
end

0 commit comments

Comments
 (0)