diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index 0e48a5fa71..a3d3f5c1e2 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -104,8 +104,10 @@ def detect_test_library if 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. - elsif direct_dependency?(/^rails$/) + # by ruby-lsp-rails. A Rails app doesn't need to depend on the rails gem itself, individual components like + # activestorage may be added to the gemfile so that other components aren't present. A Rails app doesn't boot + # without railties, so check that as well. + elsif direct_dependency?(/^rails$/) || direct_dependency?(/^railties$/) "rails" # NOTE: Intentionally ends with $ to avoid mis-matching minitest-reporters, etc. in a Rails app. elsif direct_dependency?(/^minitest$/) diff --git a/test/global_state_test.rb b/test/global_state_test.rb index fa36b9ce45..823d42dff3 100644 --- a/test/global_state_test.rb +++ b/test/global_state_test.rb @@ -39,6 +39,12 @@ def test_detects_rails_if_both_rails_and_minitest_are_present assert_equal("rails", GlobalState.new.test_library) end + def test_detects_rails_if_both_minitest_and_railties_are_present + stub_dependencies("minitest" => "1.2.3", "railties" => "1.2.3") + + assert_equal("rails", GlobalState.new.test_library) + end + def test_detects_rspec_if_both_rails_and_rspec_are_present stub_dependencies("rspec" => "1.2.3", "rails" => "1.2.3")