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, so ruby-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 like context.foo. Thought about this a bit more, and dropped it because even a non-test file could have usages like context "foo" {} if it was using a non-rspec DSL.
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.