Skip to content

Commit

Permalink
Set load path based on test/spec directory
Browse files Browse the repository at this point in the history
Some codebases (particularly those using minitest/spec) have tests in
the `spec` directory instead of the `test` directory. This commit adds
support for detecting these paths and adjusting the load path
accordingly.
  • Loading branch information
thomasmarshall committed Oct 10, 2024
1 parent 9d02cb3 commit c243daf
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 174 deletions.
7 changes: 5 additions & 2 deletions lib/ruby_lsp/listeners/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CodeLens
"bundle exec ruby"
rescue Bundler::GemfileNotFound
"ruby"
end + " -Itest ",
end,
String,
)
ACCESS_MODIFIERS = T.let([:public, :private, :protected], T::Array[Symbol])
Expand Down Expand Up @@ -229,7 +229,10 @@ def add_test_code_lens(node, name:, command:, kind:, id: name)
).returns(String)
end
def generate_test_command(group_stack: [], spec_name: nil, method_name: nil)
command = BASE_COMMAND + T.must(@path)
command = BASE_COMMAND
command += " -Itest" if T.must(@path).include?("#{File::SEPARATOR}test#{File::SEPARATOR}")
command += " -Ispec" if T.must(@path).include?("#{File::SEPARATOR}spec#{File::SEPARATOR}")
command += " #{T.must(@path)}"

case @global_state.test_library
when "minitest"
Expand Down

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions test/expectations/code_lens/minitest_spec_tests.exp.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions test/expectations/code_lens/minitest_tests.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
{
"start_line": 0,
"start_column": 0,
Expand Down Expand Up @@ -51,7 +51,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
{
"start_line": 0,
"start_column": 0,
Expand Down Expand Up @@ -85,7 +85,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^Test(#|::)/\"",
{
"start_line": 0,
"start_column": 0,
Expand Down Expand Up @@ -119,7 +119,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public",
{
"start_line": 5,
"start_column": 2,
Expand Down Expand Up @@ -152,7 +152,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public",
{
"start_line": 5,
"start_column": 2,
Expand Down Expand Up @@ -185,7 +185,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public",
{
"start_line": 5,
"start_column": 2,
Expand Down Expand Up @@ -218,7 +218,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_command",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_command",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_command",
{
"start_line": 9,
"start_column": 9,
Expand Down Expand Up @@ -251,7 +251,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_command",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_command",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_command",
{
"start_line": 9,
"start_column": 9,
Expand Down Expand Up @@ -284,7 +284,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_command",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_command",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_command",
{
"start_line": 9,
"start_column": 9,
Expand Down Expand Up @@ -317,7 +317,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_another_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_another_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_another_public",
{
"start_line": 11,
"start_column": 9,
Expand Down Expand Up @@ -350,7 +350,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_another_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_another_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_another_public",
{
"start_line": 11,
"start_column": 9,
Expand Down Expand Up @@ -383,7 +383,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_another_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_another_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_another_public",
{
"start_line": 11,
"start_column": 9,
Expand Down Expand Up @@ -416,7 +416,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_vcall",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_vcall",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_vcall",
{
"start_line": 17,
"start_column": 2,
Expand Down Expand Up @@ -449,7 +449,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_vcall",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_vcall",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_vcall",
{
"start_line": 17,
"start_column": 2,
Expand Down Expand Up @@ -482,7 +482,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_public_vcall",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_public_vcall",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_public_vcall",
{
"start_line": 17,
"start_column": 2,
Expand Down Expand Up @@ -515,7 +515,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_with_q?",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
{
"start_line": 19,
"start_column": 2,
Expand Down Expand Up @@ -548,7 +548,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_with_q?",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
{
"start_line": 19,
"start_column": 2,
Expand Down Expand Up @@ -581,7 +581,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"Test#test_with_q?",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
"bundle exec ruby /fixtures/minitest_tests.rb --name Test#test_with_q\\?",
{
"start_line": 19,
"start_column": 2,
Expand Down Expand Up @@ -614,7 +614,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
{
"start_line": 24,
"start_column": 0,
Expand Down Expand Up @@ -648,7 +648,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
{
"start_line": 24,
"start_column": 0,
Expand Down Expand Up @@ -682,7 +682,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
"bundle exec ruby /fixtures/minitest_tests.rb --name \"/^AnotherTest(#|::)/\"",
{
"start_line": 24,
"start_column": 0,
Expand Down Expand Up @@ -716,7 +716,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public",
{
"start_line": 25,
"start_column": 2,
Expand Down Expand Up @@ -749,7 +749,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public",
{
"start_line": 25,
"start_column": 2,
Expand Down Expand Up @@ -782,7 +782,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public",
{
"start_line": 25,
"start_column": 2,
Expand Down Expand Up @@ -815,7 +815,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
{
"start_line": 31,
"start_column": 2,
Expand Down Expand Up @@ -848,7 +848,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
{
"start_line": 31,
"start_column": 2,
Expand Down Expand Up @@ -881,7 +881,7 @@
"arguments": [
"/fixtures/minitest_tests.rb",
"AnotherTest#test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
"bundle exec ruby /fixtures/minitest_tests.rb --name AnotherTest#test_public_2",
{
"start_line": 31,
"start_column": 2,
Expand Down
Loading

0 comments on commit c243daf

Please sign in to comment.