Skip to content

Commit ee5f44d

Browse files
authored
Don't push group id to stack when encountering non-test classes (#1891)
Some tests use classes instead of modules for namespacing, such us: ```ruby module Foo class Bar class MyTest < Minitest::Test def test_something assert true end end end end ``` And when this happens, the current implementation would still push the group id to the stack, which would cause the first test group (`MyTest`) to already have non-nil group id. This will make the extension to think there's another parent test group, which is not the case and will cause no code lens to be shown. This commit fixes this by not pushing the group id to the stack when encountering non-test classes, and only pop the group id when the encountered class is a test class.
1 parent 971ba89 commit ee5f44d

File tree

3 files changed

+284
-78
lines changed

3 files changed

+284
-78
lines changed

lib/ruby_lsp/listeners/code_lens.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,22 @@ def on_class_node_enter(node)
6868
command: generate_test_command(group_stack: @group_stack),
6969
kind: :group,
7070
)
71-
end
7271

73-
@group_id_stack.push(@group_id)
74-
@group_id += 1
72+
@group_id_stack.push(@group_id)
73+
@group_id += 1
74+
end
7575
end
7676

7777
sig { params(node: Prism::ClassNode).void }
7878
def on_class_node_leave(node)
7979
@visibility_stack.pop
8080
@group_stack.pop
81-
@group_id_stack.pop
81+
82+
class_name = node.constant_path.slice
83+
84+
if @path && class_name.end_with?("Test")
85+
@group_id_stack.pop
86+
end
8287
end
8388

8489
sig { params(node: Prism::DefNode).void }

0 commit comments

Comments
 (0)