简体   繁体   中英

How to configure $LOAD_PATH in VS Code's debugger for Ruby?

I'm trying to use VS Code's debugger. It works fine for local files, but not RSpecs.

for example, i have the part_1.rb under lib/ and part_1_spec.rb under spec/ .

part_1_spec.rb is like

require "part_1"

describe "Part 1:" do

It works fine if I use byebug as debugger and run the spec as bundle exec rspec part_1_spec.rb , but when I use VS code debugger, I have to do require_relative "../lib/part_1" and require "Rspec" include "Rspec" otherwise it will unable to load properly.

Is there any way I can configure $LOAD_PATH in VSCode so that I don't have to change these spec files? And I will have many projects so I don't want to do it for each project.

The following is my current launch.json for my VS code debugger

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "RSpec - active spec file only",
            "type": "Ruby",
            "request": "launch",
            "cwd":"${workspaceRoot}",
            "program": "${file}",
            "args": [
                "-I",
                "${workspaceRoot}/lib",
            ]
        },
        {
            "name": "Debug Local File",
            "type": "Ruby",
            "request": "launch",
            "cwd":"${workspaceRoot}",
            "program": "${file}"
        },
    ]
}

It turns out I for program I should specify the new version of my installed Rspec and that would automatically look for files under the root folder

{
    // 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 - active spec file only",
            "type": "Ruby",
            "request": "launch",
            "program": "/usr/local/bin/rspec",
            "args": ["${file}"],
        },
        {
            "name": "Debug Local File",
            "type": "Ruby",
            "request": "launch",
            "cwd":"${workspaceRoot}",
            "program": "${file}"
        },
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM