[英]How to configure $LOAD_PATH in VS Code's debugger for Ruby?
I'm trying to use VS Code's debugger.我正在尝试使用 VS Code 的调试器。 It works fine for local files, but not RSpecs.
它适用于本地文件,但不适用于 RSpecs。
for example, i have the part_1.rb
under lib/
and part_1_spec.rb
under spec/
.例如,我在
lib/
下有part_1_spec.rb
在spec/
下有part_1.rb
。
part_1_spec.rb
is like part_1_spec.rb
就像
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.如果我使用
byebug
作为调试器并将规范作为bundle exec rspec part_1_spec.rb
运行,它工作正常,但是当我使用 VS 代码调试器时,我必须执行require_relative "../lib/part_1"
并require "Rspec" include "Rspec"
require_relative "../lib/part_1"
require "Rspec" include "Rspec"
否则将无法正常加载。
Is there any way I can configure $LOAD_PATH in VSCode so that I don't have to change these spec files?有什么方法可以在 VSCode 中配置 $LOAD_PATH 以便我不必更改这些规范文件? 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以下是我当前用于 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}"
},
]
}
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原来我对于
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}"
},
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.