Skip to content

Commit

Permalink
Detect rails as the testing framework if bin/rails exists (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain authored Apr 8, 2024
1 parent 687bb2c commit aa46c58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 downloaded. Check for the presence
# of bin/rails to support these cases.
elsif File.exist?(File.join(workspace_path, "bin/rails"))
"rails"
# NOTE: Intentionally ends with $ to avoid mis-matching minitest-reporters, etc. in a Rails app.
elsif direct_dependency?(/^minitest$/)
Expand Down
8 changes: 5 additions & 3 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ def test_detects_dependencies_in_gemspecs
assert(GlobalState.new.direct_dependency?(/^prism$/))
end

def test_detects_rails_if_both_rails_and_minitest_are_present
stub_dependencies("minitest" => "1.2.3", "rails" => "1.2.3")
def test_detects_rails_if_minitest_is_present_and_bin_rails_exists
stub_dependencies("minitest" => "1.2.3")
File.expects(:exist?).with("#{Dir.pwd}/bin/rails").once.returns(true)

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")
stub_dependencies("rspec" => "1.2.3")
File.expects(:exist?).never

assert_equal("rspec", GlobalState.new.test_library)
end
Expand Down

0 comments on commit aa46c58

Please sign in to comment.