Skip to content

Commit 609478c

Browse files
Add tests
1 parent 27b3406 commit 609478c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

spec/test_discovery_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,67 @@
8181
end
8282
end
8383

84+
# Tests capybara feature/scenario syntax
85+
# see https://github.com/teamcapybara/capybara
86+
it "discovers Capybara examples" do
87+
source = <<~RUBY
88+
feature "Sample test" do
89+
scenario "first test" do
90+
expect(true).to be(true)
91+
end
92+
93+
# Test a mixed syntax
94+
it "second test" do
95+
expect(true).to be(true)
96+
end
97+
end
98+
99+
RSpec.describe Foo do
100+
it "third test" do
101+
expect(true).to be(true)
102+
end
103+
end
104+
RUBY
105+
106+
with_server(source, uri) do |server, uri|
107+
server.process_message(
108+
{
109+
id: 1,
110+
method: "rubyLsp/discoverTests",
111+
params: {
112+
textDocument: { uri: uri },
113+
},
114+
},
115+
)
116+
117+
items = pop_result(server).response
118+
119+
expect(items.length).to eq(2)
120+
121+
first_group = items.first
122+
expect(first_group[:id]).to eq("./spec/fake_spec.rb:1")
123+
expect(first_group[:label]).to eq("Sample test")
124+
expect(first_group[:children].length).to eq(2)
125+
126+
test_ids = first_group[:children].map { |i| i[:id] }
127+
expect(test_ids).to include("./spec/fake_spec.rb:1::./spec/fake_spec.rb:2")
128+
expect(test_ids).to include("./spec/fake_spec.rb:1::./spec/fake_spec.rb:6")
129+
130+
test_labels = first_group[:children].map { |i| i[:label] }
131+
expect(test_labels).to include("first test")
132+
133+
expect(test_labels).to include("second test")
134+
135+
second_group = items[1]
136+
expect(second_group[:id]).to eq("./spec/fake_spec.rb:11")
137+
expect(second_group[:label]).to eq("Foo")
138+
expect(second_group[:children].length).to eq(1)
139+
140+
test_ids = second_group[:children].map { |i| i[:id] }
141+
expect(test_ids).to include("./spec/fake_spec.rb:11::./spec/fake_spec.rb:12")
142+
end
143+
end
144+
84145
it "discovers nested example groups" do
85146
source = <<~RUBY
86147
RSpec.describe "Outer group" do

0 commit comments

Comments
 (0)