diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index 6edba5fb9..4cb80fc28 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -110,7 +110,9 @@ def detect_formatter sig { returns(String) } def detect_test_library - if direct_dependency?(/^rspec/) + if ENV.key?("RUBY_LSP_TEST_LIBRARY") + ENV["RUBY_LSP_TEST_LIBRARY"] + elsif direct_dependency?(/^rspec/) "rspec" # A Rails app may have a dependency on minitest, but we would instead want to use the Rails test runner provided # by ruby-lsp-rails. A Rails app doesn't need to depend on the rails gem itself, individual components like diff --git a/test/global_state_test.rb b/test/global_state_test.rb index a9bdb3d01..881df85d0 100644 --- a/test/global_state_test.rb +++ b/test/global_state_test.rb @@ -47,6 +47,20 @@ def test_detects_rspec_if_both_rails_and_rspec_are_present assert_equal("rspec", GlobalState.new.test_library) end + def test_detects_library_from_env_if_present + original_env = ENV.fetch("RUBY_LSP_TEST_LIBRARY", :not_present) + ENV["RUBY_LSP_TEST_LIBRARY"] = "minitest" + stub_dependencies("test-unit" => "1.2.3") + stub_dependencies("rspec" => "1.2.3") + assert_equal("minitest", GlobalState.new.test_library) + ensure + if original_env == :not_present + ENV.delete("RUBY_LSP_TEST_LIBRARY") + else + ENV["RUBY_LSP_TEST_LIBRARY"] = original_env + end + end + def test_direct_dependency_returns_false_outside_of_bundle File.expects(:file?).at_least_once.returns(false) stub_dependencies({})