Only handle requests in _{spec,test}.rb files #6
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.
Ran into this issue today where I saw rspec markers in a non-spec file:
This PR fixes that behaviour by restricting the codelens listener to only listen on files that are named
_test.rb
or_spec.rb
.Potential Issues
Rspec's default file pattern is
_spec.rb
, but that can be configured.I vaguely remember coming across codebases that use
_test.rb
for specs, hence the added pattern. This can backfire if people use both rspec & minitest. Minitest has a spec syntax too, soruby-lsp-rspec
will end up creating incorrect markers on minitest files. Won't affect minitest-only users since I assume they won't have this addon installed.I suspect the only accurate way to fix these issues would be to get the exact value of rspec's file pattern - either through static analysis, or by having a configuration option passed in. Doubt that either of these options are easy to do, but open to suggestions!
Other approaches
My first instinct was to improve how
context
is detected, by ignoring usages likecontext.foo
. Thought about this a bit more, and dropped it because even a non-test file could have usages likecontext "foo" {}
if it was using a non-rspec DSL.