Skip to content

Commit ea4d735

Browse files
authored
Prefix bin/rails with ruby on Windows (#353)
Co-authored-by: Andy Waite <[email protected]>
1 parent 2dae425 commit ea4d735

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/ruby_lsp/ruby_lsp_rails/code_lens.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class CodeLens
4242
include Requests::Support::Common
4343
include ActiveSupportTestCaseHelper
4444

45-
BASE_COMMAND = "bin/rails test"
46-
4745
sig do
4846
params(
4947
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
@@ -67,7 +65,7 @@ def on_call_node_enter(node)
6765
return unless content
6866

6967
line_number = node.location.start_line
70-
command = "#{BASE_COMMAND} #{@path}:#{line_number}"
68+
command = "#{test_command} #{@path}:#{line_number}"
7169
add_test_code_lens(node, name: content, command: command, kind: :example)
7270
end
7371

@@ -77,7 +75,7 @@ def on_def_node_enter(node)
7775
method_name = node.name.to_s
7876
if method_name.start_with?("test_")
7977
line_number = node.location.start_line
80-
command = "#{BASE_COMMAND} #{@path}:#{line_number}"
78+
command = "#{test_command} #{@path}:#{line_number}"
8179
add_test_code_lens(node, name: method_name, command: command, kind: :example)
8280
end
8381
end
@@ -86,7 +84,7 @@ def on_def_node_enter(node)
8684
def on_class_node_enter(node)
8785
class_name = node.constant_path.slice
8886
if class_name.end_with?("Test")
89-
command = "#{BASE_COMMAND} #{@path}"
87+
command = "#{test_command} #{@path}"
9088
add_test_code_lens(node, name: class_name, command: command, kind: :group)
9189
@group_id_stack.push(@group_id)
9290
@group_id += 1
@@ -103,6 +101,15 @@ def on_class_node_leave(node)
103101

104102
private
105103

104+
sig { returns(String) }
105+
def test_command
106+
if Gem.win_platform?
107+
"ruby bin/rails test"
108+
else
109+
"bin/rails test"
110+
end
111+
end
112+
106113
sig { params(node: Prism::Node, name: String, command: String, kind: Symbol).void }
107114
def add_test_code_lens(node, name:, command:, kind:)
108115
return unless @path

test/ruby_lsp_rails/code_lens_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ class AnotherTest < ActiveSupport::TestCase
263263
assert_empty(data)
264264
end
265265

266+
test "prefixes the binstub call with `ruby` on Windows" do
267+
Gem.stubs(:win_platform?).returns(true)
268+
response = generate_code_lens_for_source(<<~RUBY)
269+
class Test < ActiveSupport::TestCase
270+
end
271+
RUBY
272+
273+
assert_equal("ruby bin/rails test /fake.rb", response[0].command.arguments[2])
274+
end
275+
266276
private
267277

268278
def generate_code_lens_for_source(source)

0 commit comments

Comments
 (0)