From a7f7db497fb4df09d0e96db42a53fc48fbd4c4bf Mon Sep 17 00:00:00 2001 From: Tudor Bertiean Date: Thu, 23 Apr 2026 11:59:07 -0400 Subject: [PATCH] fix: TestDiscovery items missing test_case/test_group tags causes Run in Terminal to run entire file Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../ruby_lsp_rspec/spec_style_patch.rb | 11 ++++++++ lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb | 2 ++ spec/spec_style_patch_spec.rb | 25 +++++++++++++++++++ spec/test_discovery_spec.rb | 13 +++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb b/lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb index 48b6aeb..8722e01 100644 --- a/lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb +++ b/lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb @@ -11,4 +11,15 @@ def initialize(response_builder, global_state, dispatcher, uri) end end end + + module Requests + module Support + class TestItem + #: (String) -> void + def add_tag(tag) + @tags << tag + end + end + end + end end diff --git a/lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb b/lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb index 33568e9..c7936ec 100644 --- a/lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb +++ b/lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb @@ -84,6 +84,7 @@ def handle_describe(node) range_from_node(node), framework: :rspec, ) + test_item.add_tag("test_group") if parent parent.add(test_item) @@ -108,6 +109,7 @@ def handle_example(node) range_from_node(node), framework: :rspec, ) + test_item.add_tag("test_case") parent.add(test_item) @response_builder.add_code_lens(test_item) diff --git a/spec/spec_style_patch_spec.rb b/spec/spec_style_patch_spec.rb index 88ee409..ddc3153 100644 --- a/spec/spec_style_patch_spec.rb +++ b/spec/spec_style_patch_spec.rb @@ -7,3 +7,28 @@ end end end + +RSpec.describe RubyLsp::Requests::Support::TestItem do + describe "#add_tag" do + it "appends a tag to the item's tags" do + item = described_class.new( + "some_id", + "some label", + URI("file:///fake_spec.rb"), + RubyLsp::Interface::Range.new( + start: RubyLsp::Interface::Position.new(line: 0, character: 0), + end: RubyLsp::Interface::Position.new(line: 0, character: 0), + ), + framework: :rspec, + ) + + expect(item.to_hash[:tags]).to eq(["framework:rspec"]) + + item.add_tag("test_case") + expect(item.to_hash[:tags]).to eq(["framework:rspec", "test_case"]) + + item.add_tag("test_group") + expect(item.to_hash[:tags]).to eq(["framework:rspec", "test_case", "test_group"]) + end + end +end diff --git a/spec/test_discovery_spec.rb b/spec/test_discovery_spec.rb index c80b4ec..4f980fd 100644 --- a/spec/test_discovery_spec.rb +++ b/spec/test_discovery_spec.rb @@ -52,6 +52,7 @@ first_group = items.first expect(first_group[:id]).to eq("./spec/fake_spec.rb:1") expect(first_group[:label]).to eq("Sample test") + expect(first_group[:tags]).to include("test_group") expect(first_group[:children].length).to eq(2) test_ids = first_group[:children].map { |i| i[:id] } @@ -60,12 +61,16 @@ test_labels = first_group[:children].map { |i| i[:label] } expect(test_labels).to include("first test") - expect(test_labels).to include("second test") + first_group[:children].each do |child| + expect(child[:tags]).to include("test_case") + end + second_group = items[1] expect(second_group[:id]).to eq("./spec/fake_spec.rb:11") expect(second_group[:label]).to eq("Foo") + expect(second_group[:tags]).to include("test_group") expect(second_group[:children].length).to eq(1) test_ids = second_group[:children].map { |i| i[:id] } @@ -74,6 +79,7 @@ third_group = items[2] expect(third_group[:id]).to eq("./spec/fake_spec.rb:17") expect(third_group[:label]).to eq("Foo::Bar") + expect(third_group[:tags]).to include("test_group") expect(third_group[:children].length).to eq(1) test_ids = third_group[:children].map { |i| i[:id] } @@ -171,17 +177,22 @@ outer_group = items.first expect(outer_group[:label]).to eq("Outer group") + expect(outer_group[:tags]).to include("test_group") expect(outer_group[:children].length).to eq(2) inner_groups = outer_group[:children] expect(inner_groups[0][:label]).to eq("Inner group") + expect(inner_groups[0][:tags]).to include("test_group") expect(inner_groups[1][:label]).to eq("Another group") + expect(inner_groups[1][:tags]).to include("test_group") expect(inner_groups[0][:children].length).to eq(1) expect(inner_groups[0][:children][0][:label]).to eq("nested test") + expect(inner_groups[0][:children][0][:tags]).to include("test_case") expect(inner_groups[1][:children].length).to eq(1) expect(inner_groups[1][:children][0][:label]).to eq("another test") + expect(inner_groups[1][:children][0][:tags]).to include("test_case") end end