Skip to content

Commit 5814750

Browse files
authored
Handle starting tests for the whole project (#79)
If the tag is not a directory, file, group, or individual case, it is probably for the whole project. So use the path as test location.
1 parent 5cc07b2 commit 5814750

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/ruby_lsp/ruby_lsp_rspec/addon.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ def resolve_test_commands(items)
116116
elsif tags.include?("test_group")
117117
start_line = item.dig(:range, :start, :line)
118118
commands << "#{@rspec_command} -r #{FORMATTER_PATH} -f #{FORMATTER_NAME} #{path}:#{start_line + 1}"
119-
else
119+
elsif tags.include?("test_case")
120120
full_files << "#{path}:#{item.dig(:range, :start, :line) + 1}"
121+
else
122+
# whole project
123+
full_files << path
121124
end
122125

123126
queue.concat(children)

spec/addon_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,33 @@
9292
])
9393
end
9494
end
95+
96+
it "resolves commands for the whole project" do
97+
project_uri = "file:///test-project"
98+
with_server do |server|
99+
server.process_message(
100+
{
101+
id: 1,
102+
method: "rubyLsp/resolveTestCommands",
103+
params: {
104+
items: [
105+
{
106+
id: project_uri,
107+
label: "test-project",
108+
tags: ["framework:rspec"],
109+
uri: project_uri,
110+
children: [],
111+
},
112+
],
113+
},
114+
},
115+
)
116+
117+
response = pop_result(server).response
118+
expect(response[:commands]).to eq([
119+
"bundle exec rspec -r #{formatter_absolute_path} -f #{formatter_name} /test-project",
120+
])
121+
end
122+
end
95123
end
96124
end

0 commit comments

Comments
 (0)