Skip to content

Commit 0d135ae

Browse files
committed
Account for module wrapping Minitest specs
1 parent 0248d2d commit 0d135ae

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/ruby_lsp/listeners/spec_style.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ def on_module_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerM
5858

5959
#: (Prism::CallNode) -> void
6060
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
61-
return unless in_spec_context?
62-
6361
case node.name
6462
when :describe
6563
handle_describe(node)
6664
when :it, :specify
67-
handle_example(node)
65+
handle_example(node) if in_spec_context?
6866
end
6967
end
7068

@@ -208,12 +206,13 @@ def latest_group
208206
end
209207

210208
# Specs only using describes
211-
first_group = @spec_group_id_stack.find { |i| i.is_a?(DescribeGroup) }
212-
return unless first_group
209+
first_group_index = @spec_group_id_stack.index { |i| i.is_a?(DescribeGroup) }
210+
return unless first_group_index
213211

212+
first_group = @spec_group_id_stack[first_group_index] #: as !nil
214213
item = @response_builder[first_group.id] #: as !nil
215214

216-
@spec_group_id_stack[1..] #: as !nil
215+
@spec_group_id_stack[first_group_index + 1..] #: as !nil
217216
.each do |group|
218217
next unless group.is_a?(DescribeGroup)
219218

test/requests/discover_tests_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,36 @@ def test_something; end
792792
end
793793
end
794794

795+
def test_specs_defined_inside_modules
796+
source = <<~RUBY
797+
module MyNamespace
798+
describe "this thing" do
799+
it "does something" do
800+
end
801+
end
802+
803+
module OtherNamespace
804+
describe "other test" do
805+
it "does something else" do
806+
end
807+
end
808+
end
809+
end
810+
RUBY
811+
812+
with_minitest_spec_configured(source) do |items|
813+
assert_equal(["this thing", "other test"], items.map { |i| i[:id] })
814+
assert_equal(
815+
["this thing#test_0002_does something"],
816+
items.dig(0, :children).map { |i| i[:id] },
817+
)
818+
assert_equal(
819+
["other test#test_0008_does something else"],
820+
items.dig(1, :children).map { |i| i[:id] },
821+
)
822+
end
823+
end
824+
795825
private
796826

797827
def create_test_discovery_addon

0 commit comments

Comments
 (0)