Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix bin/rails with ruby on Windows #353

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
17 changes: 12 additions & 5 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class CodeLens
include Requests::Support::Common
include ActiveSupportTestCaseHelper

BASE_COMMAND = "bin/rails test"

sig do
params(
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
Expand All @@ -67,7 +65,7 @@ def on_call_node_enter(node)
return unless content

line_number = node.location.start_line
command = "#{BASE_COMMAND} #{@path}:#{line_number}"
command = "#{test_command} #{@path}:#{line_number}"
add_test_code_lens(node, name: content, command: command, kind: :example)
end

Expand All @@ -77,7 +75,7 @@ def on_def_node_enter(node)
method_name = node.name.to_s
if method_name.start_with?("test_")
line_number = node.location.start_line
command = "#{BASE_COMMAND} #{@path}:#{line_number}"
command = "#{test_command} #{@path}:#{line_number}"
add_test_code_lens(node, name: method_name, command: command, kind: :example)
end
end
Expand All @@ -86,7 +84,7 @@ def on_def_node_enter(node)
def on_class_node_enter(node)
class_name = node.constant_path.slice
if class_name.end_with?("Test")
command = "#{BASE_COMMAND} #{@path}"
command = "#{test_command} #{@path}"
add_test_code_lens(node, name: class_name, command: command, kind: :group)
@group_id_stack.push(@group_id)
@group_id += 1
Expand All @@ -103,6 +101,15 @@ def on_class_node_leave(node)

private

sig { returns(String) }
def test_command
if Gem.win_platform?
"ruby bin/rails test"
else
"bin/rails test"
end
end

sig { params(node: Prism::Node, name: String, command: String, kind: Symbol).void }
def add_test_code_lens(node, name:, command:, kind:)
return unless @path
Expand Down
10 changes: 10 additions & 0 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ class AnotherTest < ActiveSupport::TestCase
assert_empty(data)
end

test "prefixes the binstub call with `ruby` on Windows" do
Gem.stubs(:win_platform?).returns(true)
response = generate_code_lens_for_source(<<~RUBY)
class Test < ActiveSupport::TestCase
end
RUBY

assert_equal("ruby bin/rails test /fake.rb", response[0].command.arguments[2])
end

private

def generate_code_lens_for_source(source)
Expand Down
Loading