首页 > 解决方案 > 如何在 VS Code 的 Ruby 调试器中配置 $LOAD_PATH?

问题描述

我正在尝试使用 VS Code 的调试器。它适用于本地文件,但不适用于 RSpecs。

例如,我有part_1.rbunderlib/part_1_spec.rbunder spec/

part_1_spec.rb就好像

require "part_1"

describe "Part 1:" do

byebug如果我用作调试器并将规范运行为,它工作正常bundle exec rspec part_1_spec.rb,但是当我使用 VS 代码调试器时,我必须这样做require_relative "../lib/part_1"require "Rspec" include "Rspec"否则它将无法正确加载。

有什么方法可以在 VSCode 中配置 $LOAD_PATH 以便我不必更改这些规范文件?而且我会有很多项目,所以我不想为每个项目都这样做。

以下是我的 VS 代码调试器的当前 launch.json

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

标签: rubyrspec

解决方案


事实证明program我应该指定我安装的 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 - 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}"
        },
    ]
}

推荐阅读