Fix minitest spec code lens selectors #2706
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #2648 and #2688.
This PR improves minitest spec code lens in two ways:
spec
to the load path instead oftest
if the current path is inside aspec
directory (for example tapioca).Note: This doesn't fix the issue with the code lens above the class in spec files not matching any tests. That has been broken since before my earlier changes and is more tricky to fix because when we generate the code lens we don't yet know if we're in a class that wraps minitest/spec examples or not.
Implementation
To fix the specs inside classes issue, I started tracking the group type (
:class
,:module
,:describe
) alongside the group name in@group_stack
. It then filters out anything except the:describe
groups when constructing the selector.To fix the load path option, it checks to see whether the current path is inside a
spec
directory or atest
directory and adds an appropriate-I
argument to the base command. This changes the default behavior—if the current path is in neither aspec
ortest
directory it no longer adds-Itest
.There are of course weird edge cases here, for example if the path is inside both a
spec
andtest
directory (liketest/spec/foo_test.rb
). In that case bothtest
andspec
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 original behavior for minitest spec code lens' and then updated it to match each fix. I also regenerated the expectation JSON files, which have mostly changed just to remove
-Itest
. I guess we could change the logic so-Itest
is added by default, even if it's not in atest
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:
spec-code-lens.mov
Use code lens to make sure non-spec tests still work fine:
test-code-lens.mov