Skip to content

Correct test IDs based on relative path #70

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elmuerte
Copy link
Contributor

When running rspec from a parent directory the example's location used to generate the test IDs will not match how the tests are registered in the LSP.

By defining the envvar RUBY_LSP_RSPEC_RELPATH the path prefix will be removed for while generating the test IDs so that they align up.

@elmuerte
Copy link
Contributor Author

I'm developing a plugin for Discourse. These plugin's live in a subdirectory of the Discourse rails application. In order to execute tests I need to run rspec from the Discourse base directory, but this results in incorrect test IDs.

So, my plugin would be in ./plugins/foo-bar, which is the root of the vscode project. I have bin/rspec file which ruby-lsp-rspec nicely uses, that rspec will effectively set some environment variables, change the directory to the Discourse main directory and runs bin/rspec ... from there. This works well, except that the test results are not reported back.

So I updated my bin/rspec script to also set the RUBY_LSP_RSPEC_RELPATH envvar which is pickup up with this modification, and now I have working test result reporting.

When running rspec from a parent directory the example's location used to generate the test IDs will not match how the tests are registered in the LSP.

By defining the envvar RUBY_LSP_RSPEC_RELPATH the path prefix will be removed for while generating the test IDs so that they align up.
@st0012
Copy link
Owner

st0012 commented Jun 14, 2025

Looking at bin/rspec under Discourse, it seems that by design plugins should also use it to run their specs from the Discourse root? Like path-to-discourse/bin/rspec ./plugins/my-plugin/spec? Does the addon having issues with those cases?

I seems that your customized bin/rspec that exits to parent folders to execute tests under the current workspace is a very special setup. While I understand why you want to do it, I'm not sure if I want to include the complexity that only supports very limited cases.

@elmuerte
Copy link
Contributor Author

Looking at bin/rspec under Discourse, it seems that by design plugins should also use it to run their specs from the Discourse root? Like path-to-discourse/bin/rspec ./plugins/my-plugin/spec? Does the addon having issues with those cases?

It doesn't work like that. the Discourse rspec command does need to run from the Discourse base directory in order to execute the tests of a plugin. I could use the Discourse root directory as basis of my vscode project. That would quite explode the project.

Either way... I figured out a way to have it all working nicely without these suggested changes. Basically I just added the suggested changes in the MR to a file which is included when starting the Discourse rspec command so the rspec_formatter is patched like that.

So if you don't want to add this complexity, which I can understand, you can close this MR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants