Skip to content

Commit

Permalink
Detect rails as the testing framework if direct dependency on railties
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Apr 6, 2024
1 parent d915940 commit 7b62b9a
Show file tree
Hide file tree
Showing 2 changed files with 10 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 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$/)
Expand Down
6 changes: 6 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 7b62b9a

Please sign in to comment.