1

I am trying to set up VsCode to run my spec tests in debug mode.

I have added the following launch.json file to the project. I am using rvm and have installed the necessary gems in that location such as rspec.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "RSpec - all",
            "type": "Ruby",
            "request": "launch",
            "program": "<home>.rvm/gems/ruby-2.4.5/gems/rspec",
            "args": [
                "-I",
                "${workspaceRoot}/spec/*_spec.rb"
            ]
        }
    ]
}

When I run in debug mode the following displays in the console.

Uncaught exception: cannot load such file -- home-directory/.rvm/gems/ruby-2.4.5/gems/rspec

I've installed the necessary extension based on the documentation I found. ruby, solargraph, and rubicon

Any help would be greatly appreciated.

Thank you, Joe

Joe
  • 743
  • 5
  • 10
  • 26

2 Answers2

2

Set the output from which rspec command as "program" parameter.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Andrew K
  • 51
  • 4
0

The problem is that the path "home-directory/.rvm/gems/ruby-2.4.5/gems/rspec" is not a valid path. You can test that theory by simply pasting into your console and executing.

In order to locate the actual rspec binary, you can use run which rspec. However, while it is possible to hard code this path into your launch config, you don't want to do that because when you upgrade the version, the path will change and you'll have problems running your tests again.

A better way is to use the environment variable that points to the GEM_HOME that includes rspec.

Here are the settings that worked for me, on ruby 3.0.3 managed by rvm on OSX.

Gemfile includes:

group :development do 
  gem 'ruby-debug-ide'
  gem 'debase', "~> 0.2.5.beta2"
end

(the stable version of debase didn't support ruby v3, hence the beta)

Launch config use the GEM_HOME environment variable to specify the rspec binary:

   {
        "name": "RSpec - all",
        "type": "Ruby",
        "request": "launch",
        "program": "${env:GEM_HOME}/bin/rspec",
        "args": [
            "-I",
            "${workspaceRoot}"
        ]
    }
Rene Wooller
  • 1,107
  • 13
  • 22