Skip to content
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

Fix minitest spec code lens load path #2706

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Fix minitest spec code lens load path #2706

merged 2 commits into from
Nov 26, 2024

Conversation

thomasmarshall
Copy link
Contributor

@thomasmarshall thomasmarshall commented Oct 10, 2024

Motivation

Fixes #2308 and #2688.

This PR changes the code lens base test command to add spec to the load path instead of test if the current path is inside a spec directory (for example tapioca).

Implementation

It checks to see whether the current path is inside a spec directory or a test directory and adds an appropriate -I argument to the base command.

This changes the default behavior—if the current path is in neither a spec or test directory it no longer adds -Itest. Is this reasonable behavior?

There are of course weird edge cases here, for example if the path is inside both a spec and test directory (like test/spec/foo_test.rb). In that case both test and spec would be added to the load path, but I don't currently see a better way of guessing which directory should be in the load path.

Automated Tests

I added a new test case to capture the behavior for minitest spec code lens. I also regenerated the expectation JSON files, which have mostly changed just to remove -Itest. We could change the logic so -Itest is added by default, even if it's not in a test directory, and only switch to -Ispec if necessary. That would minimize the expectation JSON changes here.

Manual Tests

Use code lens to run specs in the tapioca codebase (upgrade to latest minitest first):

spec-code-lens.mov

Use code lens to make sure non-spec tests still work fine:

test-code-lens.mov

Some codebases (particularly those using minitest/spec) have tests in
the `spec` directory instead of the `test` directory. This commit adds
support for detecting these paths and adjusting the load path
accordingly.

I opted to not include any directory by default. If the path contains
`test` or `spec`, the appropriate directory is added to the load path.
If the path doesn't contain either, then it seems unlikely that the
`test` directory should be added to the load path.
@thomasmarshall thomasmarshall marked this pull request as ready for review November 23, 2024 14:35
@thomasmarshall thomasmarshall changed the title Fix minitest spec code lens selectors Fix minitest spec code lens load path Nov 25, 2024
@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Nov 26, 2024
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

lib/ruby_lsp/listeners/code_lens.rb Outdated Show resolved Hide resolved
@vinistock
Copy link
Member

Thanks, Thomas!

@vinistock vinistock merged commit 30f8547 into main Nov 26, 2024
35 checks passed
@vinistock vinistock deleted the fix-spec-code-lens branch November 26, 2024 20:08
@andyw8
Copy link
Contributor

andyw8 commented Nov 26, 2024

Not essential, but it might be nice to show a warning if minitest/spec usage is detected while the minitest version is < 5.25.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VSCode test "Run in Terminal" uses hardcoded -Itest
3 participants