ruby - 如何在 VS Code 的 Ruby 调试器中配置 $LOAD_PATH?
问题描述
我正在尝试使用 VS Code 的调试器。它适用于本地文件,但不适用于 RSpecs。
例如,我有part_1.rb
underlib/
和part_1_spec.rb
under 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}"
},
]
}
解决方案
事实证明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}"
},
]
}
推荐阅读
- c++ - c++ GDI打印导致系统死机
- asp.net-mvc - 为每个客户提供自定义虚 URL 的最佳方式
- html - 如何在不换行的情况下实现具有水平间距的 Tailwind 网格?
- python - 如何编写 Python 脚本以使用网站的搜索栏在特定网站的数据库中搜索关键字?
- uwp - 如何制作这样的 UWP 滑块样式?
- r - 回归拟合的标准误不匹配
- sql - SQL 查询将多行返回到我的应用程序
- firebase - 在离子中如何读取和显示来自firestore的信息
- google-apps-script - 使用 Google Apps 脚本登录 Twitter
- javascript - 对列表中的每个对象进行 api 调用