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

Debug rspec test with bundle exec #410

Open
MarcPer opened this issue Jan 2, 2024 · 10 comments
Open

Debug rspec test with bundle exec #410

MarcPer opened this issue Jan 2, 2024 · 10 comments

Comments

@MarcPer
Copy link

MarcPer commented Jan 2, 2024

I'm able to run Rspec on a given line with the following rdbg call:

rdbg -c -- bundle exec rspec my_spec.rb:123

I could also make it work within VSCode if I don't use bundler, by using the following launch.json::

{
    "type": "rdbg",
    "name": "RSpec current line with rdbg",
    "useBundler": false,
    "command": "rspec",
    "request": "launch",
    "script": "${file}",
    "args": [
        "${file}:${lineNumber}"
    ],
},

However, if I change command to bundle exec rspec, I get the following message without much clarification:

Couldn't start debug session. The debuggee process exited with code 0

Is there a way to do it currently? Otherwise, let me know if I should push a PR to make this possible.

@ko1
Copy link
Collaborator

ko1 commented Jan 2, 2024

Did you put a breakpoint to somewhere you want to stop?

@MarcPer
Copy link
Author

MarcPer commented Jan 2, 2024

Did you put a breakpoint to somewhere you want to stop?

Yes, and without bundle exec it works fine.

@ko1
Copy link
Collaborator

ko1 commented Jan 2, 2024

Thank you. Can you share 'rdbg' information in "OUTPUT" tab?

@MarcPer
Copy link
Author

MarcPer commented Jan 3, 2024

Sure, here you go:

"Running: rdbg --command --open --stop-at-load -- bundle exec rspec /Users/marcper/my_project/my_spec.rb /Users/marcper/my_project/my_spec.rb:21"
[Start session]
{"d":{},"f":"87107d23-84d9-4499-8869-6cddada117c0","g":"rdbg","h":"RSpec current line with rdbg","i":{"uri":{"$mid":1,"fsPath":"/Users/marcper/my_project","external":"file:///Users/marcper/my_project","path":"/Users/marcper/my_project","scheme":"file"},"name":"my_project","index":0},"j":{"type":"rdbg","name":"RSpec current line with rdbg","useBundler":false,"command":"bundle exec rspec","request":"launch","script":"/Users/marcper/my_project/my_spec.rb","args":["/Users/marcper/my_project/my_spec.rb:21"],"__configurationTarget":6,"rdbgExtensions":["traceInspector"],"rdbgInitialScripts":[]}}

Then there's the error I mentioned in the issue description:

Couldn't start debug session. The debuggee process exited with code 0

The output shows the file name twice in the "Running:" part, so I also tried changing launch.json, removing the file name from args, and moving lineNumber to script, like this:

{
    "type": "rdbg",
    "name": "RSpec current line with rdbg",
    "useBundler": false,
    "command": "bundle exec rspec",
    "request": "launch",
    "script": "${file}:${lineNumber}",
    "args": []
}

But I get the same error, and the following output:

"Running: rdbg --command --open --stop-at-load -- bundle exec rspec /Users/marcper/my_project/my_spec.rb:21"
[Start session]
{"d":{},"f":"6f186413-d5e7-4e6c-8ff4-caaf3366c97a","g":"rdbg","h":"RSpec current line with rdbg","i":{"uri":{"$mid":1,"fsPath":"/Users/marcper/my_project","external":"file:///Users/marcper/my_project","path":"/Users/marcper/my_project","scheme":"file"},"name":"my_project","index":0},"j":{"type":"rdbg","name":"RSpec current line with rdbg","useBundler":false,"command":"bundle exec rspec","request":"launch","script":"/Users/marcper/my_project/my_spec.rb:21","args":[],"__configurationTarget":6,"rdbgExtensions":["traceInspector"],"rdbgInitialScripts":[]}}

@kayn1
Copy link

kayn1 commented Jan 7, 2024

I can confirm this issue.
Using just rspec works but bundle exec rspec does not

      "name": "Debug Rspec with current file",
      "type": "rdbg",
      "request": "launch",
      "command": "rspec",
      "script": "${file}",
      "useBundler": true,
      "args": []

@MarcPer
Copy link
Author

MarcPer commented Jan 8, 2024

I can confirm this issue. Using just rspec works but bundle exec rspec does not

Good point, I hadn't realized the issue is with RSpec+bundle generally, I thought it was associated with running a specific spec line. I'm changing the issue title.

@MarcPer MarcPer changed the title Debug rspec test with given line and bundle exec Debug rspec test with bundle exec Jan 8, 2024
@ikhsan
Copy link
Contributor

ikhsan commented Feb 3, 2024

Have you tried "rdbgPath": "bundle exec rdbg", in your config file?

This is my current setup which works for me.

@MarcPer
Copy link
Author

MarcPer commented Feb 7, 2024

Have you tried "rdbgPath": "bundle exec rdbg", in your config file?

This is my current setup which works for me.

That is odd, this fails for me with spawn bundle exec rdbg ENOENT, implying rdbgPath is expected to be just a file path.

@navels
Copy link

navels commented Mar 5, 2024

This tipped me off from the README:

  • useBundler:
    • Execute Ruby programs with bundle exec if command configuration is not given

The config that works for me is then

{
    "type": "rdbg",
    "name": "RSpec current line with rdbg",
    "useBundler": true,
    "request": "launch",
    "script": "/usr/local/bundle/bin/rspec",
    "args": ["${file}:${lineNumber}"],
},

@MarcPer
Copy link
Author

MarcPer commented Mar 7, 2024

The config that works for me is then

{
    "type": "rdbg",
    "name": "RSpec current line with rdbg",
    "useBundler": true,
    "request": "launch",
    "script": "/usr/local/bundle/bin/rspec",
    "args": ["${file}:${lineNumber}"],
},

This did not work for me, but it got me in the right track. I generated the RSpec binstub with bundle binstubs rspec-core, then the following configuration worked:

{
    "type": "rdbg",
    "name": "RSpec current line with rdbg",
    "request": "launch",
    "useBundler": true,
    "script": "./bin/rspec",
    "args": [
        "${file}:${lineNumber}"
    ],
},

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

No branches or pull requests

5 participants