![](/img/trans.png)
[英]How to append a path to ruby's LOAD_PATH in the context of rails?
[英]How to configure $LOAD_PATH in VS Code's debugger for Ruby?
我正在尝试使用 VS Code 的调试器。 它适用于本地文件,但不适用于 RSpecs。
例如,我在lib/
下有part_1_spec.rb
在spec/
下有part_1.rb
。
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"
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}"
},
]
}
原来我对于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.