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

Rspec: Passing test not being marked green (remote) #114

Open
patrickdavey opened this issue Dec 29, 2022 · 4 comments
Open

Rspec: Passing test not being marked green (remote) #114

patrickdavey opened this issue Dec 29, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@patrickdavey
Copy link

patrickdavey commented Dec 29, 2022

Your environment

  • vscode-ruby-test-adapter version:
  • Ruby version: 2.6.3
  • VS Code version: 1.74.2
  • Operating System: OSX and remote Ubuntu 18.04
  • RSpec version: 3.11

Expected behavior

Running a test remotely which passes the test (as seen in the logs and running it directly) does not result in a green icon in the tree.

Actual behavior

I am running a single test using the explorer. After running the test the icon is gray. I can see the test outputs:

START_OF_TEST_JSON{"version":"3.11.0","messages":["Run options: include {:locations=>{\"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb\"=>[7]}}"],"seed":32808,"examples":[{"id":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb[1:1:1]","description":"must have a user","full_description":"AdminMaintenanceFile validations must have a user","status":"passed","file_path":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb","line_number":7,"type":"model","pending_message":null}],"summary":{"duration":2.648112224,"example_count":1,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"1 example, 0 failures"}END_OF_TEST_JSON

But, this seemingly is not parsed correctly back into the UI.

One possible/probable factor is that I am running this in a remote developing extension. Apologies if this is not an issue with this extension, I am a relative newbie to vscode!

Console log

I can also see this in the logs (which seems like it is parsing it correctly)

[DEBUG] {"version":"3.11.0","messages":["Run options: include {:locations=>{\"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb\"=>[7]}}"],"seed":53589,"examples":[{"id":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb[1:1:1]","description":"must have a user","full_description":"AdminMaintenanceFile validations must have a user","status":"passed","file_path":"/FOO/BAR/spec/models/admin_maintenance_file_spec.rb","line_number":7,"type":"model","pending_message":null}],"summary":{"duration":2.367175155,"example_count":1,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"1 example, 0 failures"}

@patrickdavey patrickdavey added the bug Something isn't working label Dec 29, 2022
@DylanEtris
Copy link

I'm also seeing this behavior

@DylanEtris
Copy link

After some playing around, I noticed that running the full test suite correctly updates the badges, but running a single spec file or example does not.

In Tests#runNode, the testStatesEmitter fires the "test running" event with node.id which is the relative path to the spec. In the second branch (when a spec file is run) and the fourth branch (when a single example is run), the testStatesEmitter fires the "test passed/failed" event with the absolute path to the spec, which it parses from the JSON.

I hacked my installation to fire the "test passed/failed" with the relative path, and the badges were updated. So, I think the solution here lies in figuring out why the output JSON has relative paths when running every spec file, but absolute paths when running a single spec file.

@DylanEtris
Copy link

DylanEtris commented Feb 12, 2024

  • When just rspec is run, the formatter puts the relative path, ./path/to/spec.rb[1:3], in the output JSON, which is what node.id resolves to. Since running the full test suite just runs rspec, the badges are correctly updated.
  • When rspec is run with a path rspec <path> is run, the formatter puts <path> directly in the output JSON. The <path> in the command comes from node.file, which is initialized in Tests#getTestSuiteForFile as the absolute path.

I can think of two solutions, without digging further:

  1. Update the initialization of node to use a relative path. This might have side-effects, because that attribute is used in multiple places
  2. Update Tests#runNode to remove the workspace path before calling rspec in the second and fourth branches.
  3. Store the relative path in node and use that in branch two and four.

@DylanEtris
Copy link

It looks like there's a pretty big rewrite of this repo though, so I don't know if a PR on this issue is very useful: #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants