-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect rails as the testing framework if bin/rails
exists
#1896
Conversation
Thanks for the PR. I have a slight concern that there could be some gems that depend on |
Hm, right. What about also checking for Something like File.exist?(File.join(workspace_path, "bin/rails")) |
Yeah, that would have less chance of a false positive. Any thoughts @st0012, @vinistock ? |
7b62b9a
to
463c4eb
Compare
bin/rails
exists
I changed the label to |
463c4eb
to
908f276
Compare
# 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")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elsif File.exist?(File.join(workspace_path, "bin/rails")) | |
elsif File.exist?(File.join(workspace_path, "bin", "rails")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I clicked merge at the same time 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's apply this change. We can't use forward slashes for Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, is that really the fix then? https://ruby-doc.org/3.3.0/File.html#method-c-join doesn't mention this being platform-aware and seems to always use /
anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe we should be using Pathname
instead and need to switch this to
elsif File.exist?(File.join(workspace_path, "bin/rails")) | |
elsif Pathname.new(workspace_path).join("bin").join("rails").exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe Ruby already takes care of that under the hood https://github.com/ruby/ruby/blob/b09604e1fd5768daf31aaa4f8130fa8cd9b8d240/file.c#L252.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR will close #1466, so let's add to the description. |
I don't think it will close this? There are still a few other places that check against a rails dependecy here. |
Do you mean in the custom bundle logic? If so, yeah that's true. |
Since Shopify/ruby-lsp#1896 the testing framework for rails is dependant on the presence on `bin/rails`
Update tests for ruby-lsp changes Since Shopify/ruby-lsp#1896 the testing framework for rails is dependant on the presence on `bin/rails`
Motivation
I have an application that depends on Rails in the following way:
The intent is to not pull in the other framework parts, like activestorage for example. Since the testing framework detection currently does a check for rails I am not getting code lenses for tests with ruby-lsp-rails.
See Shopify/ruby-lsp-rails#47 for similar reasoning.
Implementation
Also check for
railties
. A rails app doesn't boot ifrailties
isn't present (require "rails/commands"
inbin/rails
is the first failure point).Automated Tests
Yup.
Manual Tests
Create a rails app with the above gemfile, create a test, observe code lense.