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
11 changes: 5 additions & 6 deletions lib/ruby_lsp/listeners/spec_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ def on_module_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerM

#: (Prism::CallNode) -> void
def on_call_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
return unless in_spec_context?

case node.name
when :describe
handle_describe(node)
when :it, :specify
handle_example(node)
handle_example(node) if in_spec_context?
end
end

Expand Down Expand Up @@ -208,12 +206,13 @@ def latest_group
end

# Specs only using describes
first_group = @spec_group_id_stack.find { |i| i.is_a?(DescribeGroup) }
return unless first_group
first_group_index = @spec_group_id_stack.index { |i| i.is_a?(DescribeGroup) }
return unless first_group_index

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

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

Expand Down
30 changes: 30 additions & 0 deletions test/requests/discover_tests_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,36 @@ def test_something; end
end
end

def test_specs_defined_inside_modules
source = <<~RUBY
module MyNamespace
describe "this thing" do
it "does something" do
end
end

module OtherNamespace
describe "other test" do
it "does something else" do
end
end
end
end
RUBY

with_minitest_spec_configured(source) do |items|
assert_equal(["this thing", "other test"], items.map { |i| i[:id] })
assert_equal(
["this thing#test_0002_does something"],
items.dig(0, :children).map { |i| i[:id] },
)
assert_equal(
["other test#test_0008_does something else"],
items.dig(1, :children).map { |i| i[:id] },
)
end
end

private

def create_test_discovery_addon
Expand Down
Loading