我有像这样的rspec测试代码
describe 'Utils' do
puts 1111
describe '#time_condition' do
puts 2221
it do
puts 'aaa'
end
puts 2223
end
end
我的launch.json喜欢这个
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/spec/*_rspec.rb",
"args": [
"--pattern",
"*_rspec.rb"
]
},
当我在vscode上运行测试时,我得到了
1111
2221
2223
当我按命令运行test时,得到了
>rspec spec --pattern *_rspec.rb
1111
2221
2223
aaa
.
Finished in 0.003 seconds (files took 0.23602 seconds to load)
1 example, 0 failures
正如你所看到的,没有'aaa'输出,意味着没有'它'被执行。 那么......我怎样才能让'it'在vscode上运行?
顺便说一下,我的spec配置文件(由rspec生成--init)就像
一样.rspec
--color
--require spec_helper
规格\ spec_helper.rb
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.profile_examples = 10
config.order = :random
Kernel.srand config.seed
end
VScode:1.4.0
Ruby扩展:0.5.3
感谢
答案 0 :(得分:2)
行。我解决了! 我的错是设置错误的值。 程序必须是rspec路径。
...
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "D:/Ruby/Ruby21/bin/rspec",
"args": [
"--pattern",
"${workspaceRoot}/spec/**/*_rspec.rb"
]
},
...
答案 1 :(得分:1)
这里是version: 2.0.0
(对于Linux)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "rspec - all",
"type": "shell",
"command": "$(which bundle) exec rspec",
"group": "test",
},
{
"label": "rspec - one file",
"type": "shell",
"command": "$(which bundle) exec rspec ${file}",
"group": "test",
},
{
"label": "rspec - focus",
"type": "shell",
"command": "$(which bundle) exec rspec ${file} --focus",
"group": "test",
}
]
}
现在运行Ctrl+Shift+p
并在菜单中:Tasks: ...
答案 2 :(得分:0)
如果您的项目的rspec
文件夹中有bin
,则可以尝试以下操作:
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
},
答案 3 :(得分:0)
最后在Mac上让RSpec在带有断点的VS Code上运行!在我的创业公司中没人知道如何做。请参阅Microsoft方便的GitHub page on it。
我的Gemfile
。安装3个宝石:
source 'https://rubygems.org'
gem 'rspec'
gem 'ruby-debug-ide'
gem 'debase'
我的launch.json
:
{
"configurations": [
{
"name": "Run RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/[your name]/.rvm/gems/ruby-2.6.3/bin/rspec",
"args": [
"--pattern",
"${workspaceRoot}/spec/**/*_spec.rb"
]
},
{
"name": "Debug RSpec - open spec file",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"useBundler": true,
"pathToBundler": "/Users/[your name]/.rvm/rubies/ruby-2.6.3/bin/bundle",
"pathToRDebugIDE": "/Users/[your name]/.rvm/gems/ruby-2.6.3/bin/rdebug-ide",
"debuggerPort": "1235",
"program": "/Users/[your name]/.rvm/gems/ruby-2.6.3/bin/rspec",
"args": [
"${file}"
]
},
]
}
对于“程序”,请使用值which rspec
。我的路径假设我在RVM中安装了Ruby。您的会有所不同。
对于“ pathToBundler”,请使用值which bundle
对于“ pathToRDebugIDE”,请使用值which rdebug-ide
对于这一行:"${workspaceRoot}/spec/**/*_spec.rb"
,根据规范文件的组织方式,您的文件夹可能有所不同。
要运行RSpec:
在VS Code中,转到顶部菜单中的Terminal -> New Terminal
。确保您位于Ruby项目的根目录中。
根据需要单击任意行号的左侧以设置断点。
单击VS Code左侧的错误图标。从左上方的下拉框中选择配置:
Debug RSpec - open spec file
或Run RSpec - all
然后单击左上角的绿色三角形(Start Debugging
)。
更容易:安装VS Code Extension Rails Test Runner。然后右键单击您的规范文件以进行以下操作:
Run all tests in file
或Run tests starting from the current line