Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get RSpec working with debugger IDE in VSCode

Despite having spent about the last three hours trying to get this working I cannot for the life of my get RSpec to work with the debugger on VSCode. I can get Rspec to run in the terminal on VSCode but that doesn't give me any of the IDE's debugging functionality for inspecting and stepping.

This is what I've got in my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run RSpec - all",
            "type": "Ruby",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "program": "/Users/my-home-dir/.rvm/gems/ruby-2.6.5@project-gemset-name/wrappers/rspec",
            "pathToRDebugIDE": "/Users/my-home-dir/.rvm/gems/ruby-2.6.5@project-gemset-name/gems/ruby-debug-ide-0.7.2",
            "args": [
                "--pattern",
                "${workspaceRoot}/spec/**/*_rspec.rb"
            ]
        }
    ]
}

And my gemfile contains:

  gem 'ruby-debug-ide', '~>0.7.2'
  gem 'debase', '~>0.2.4.1'

I've got a feeling that the errors may be coming about due to in incompatibility between RVM and VSCode but I've no idea how to unwind that issue.

This was all setup as per the Microsoft recipe here: https://github.com/Microsoft/vscode-recipes/tree/master/debugging-Ruby-on-Rails

Every time I run this setup I get the following error in the debug console:

Debugger terminal error: Process failed: spawn rdebug-ide ENOENT

Is there any way to get this to run? Also is there any way to get it to use guard so that it runs automatically?

like image 336
Peter Nixey Avatar asked Sep 06 '25 03:09

Peter Nixey


1 Answers

I got it working. Unfortunately, I don't use RVM. So, my solution involves rbenv. I'm sharing it here anyway in case it helps you, or someone else.

which rspec pointed me to the shim (shell script) that rbenv uses to execute the version of rspec installed under the current version of Ruby. When I configured launch.json with that path rdebug-ide didn't like the shim. I assume it was expecting the executable.

So, I ran rbenv which rspec and got the actual path to the executable. Once I plugged that into launch.json it worked fine. Of course, if I change the version of Ruby I'm running, I'll have to update the file to point to the version of RSpec installed under the new version of Ruby.

Given the prevalence of Ruby version managers among the community, I would think ruby-debug-ide would have considered this. Perhaps it's worth an issue on their GitHub: https://github.com/ruby-debug/ruby-debug-ide.

like image 115
aridlehoover Avatar answered Sep 07 '25 21:09

aridlehoover