Skip to content
Open
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: 11 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/spec_style_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion spec/test_discovery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand All @@ -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] }
Expand All @@ -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] }
Expand Down Expand Up @@ -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

Expand Down