Skip to content

Commit

Permalink
Detect rails as the testing framework if bin/rails exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Apr 8, 2024
1 parent d915940 commit 463c4eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 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 direct_dependency?(/^rails$/) || 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
7 changes: 7 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_detects_rails_if_both_rails_and_minitest_are_present
assert_equal("rails", GlobalState.new.test_library)
end

def test_detects_rails_if_minitest_is_present_and_bin_rails_exists
stub_dependencies("minitest" => "1.2.3")
File.stubs(:exist?).with("#{Dir.pwd}/bin/rails").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")

Expand Down

0 comments on commit 463c4eb

Please sign in to comment.