vscode-rdbg icon indicating copy to clipboard operation
vscode-rdbg copied to clipboard

Debug rspec test with bundle exec

Open MarcPer opened this issue 1 year ago • 10 comments

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.

MarcPer avatar Jan 02 '24 13:01 MarcPer

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

ko1 avatar Jan 02 '24 20:01 ko1

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

Yes, and without bundle exec it works fine.

MarcPer avatar Jan 02 '24 21:01 MarcPer

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

ko1 avatar Jan 02 '24 21:01 ko1

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":[]}}

MarcPer avatar Jan 03 '24 13:01 MarcPer

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": []

kayn1 avatar Jan 07 '24 13:01 kayn1

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 avatar Jan 08 '24 08:01 MarcPer

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

This is my current setup which works for me.

ikhsan avatar Feb 03 '24 20:02 ikhsan

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.

MarcPer avatar Feb 07 '24 18:02 MarcPer

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}"],
},

navels avatar Mar 05 '24 20:03 navels

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}"
    ],
},

MarcPer avatar Mar 07 '24 17:03 MarcPer