Ruby 在VS代码上运行rspec
我有这样的rspec测试代码Ruby 在VS代码上运行rspec,ruby,visual-studio-code,Ruby,Visual Studio Code,我有这样的rspec测试代码 describe 'Utils' do puts 1111 describe '#time_condition' do puts 2221 it do puts 'aaa' end puts 2223 end end { "name": "RSpec - all", "type": "Ruby", "request": "launch", "cwd": "${workspaceRoot}",
describe 'Utils' do
puts 1111
describe '#time_condition' do
puts 2221
it do
puts 'aaa'
end
puts 2223
end
end
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/spec/*_rspec.rb",
"args": [
"--pattern",
"*_rspec.rb"
]
},
我的launch.json是这样的
describe 'Utils' do
puts 1111
describe '#time_condition' do
puts 2221
it do
puts 'aaa'
end
puts 2223
end
end
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/spec/*_rspec.rb",
"args": [
"--pattern",
"*_rspec.rb"
]
},
当我在vscode上运行测试时,我得到了
1111
2221
2223
当我通过命令运行测试时,得到
>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\spec\u 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
谢谢好的。我解决了!
我的错误是给程序设置了错误的值。
程序必须是rspec路径
...
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "D:/Ruby/Ruby21/bin/rspec",
"args": [
"--pattern",
"${workspaceRoot}/spec/**/*_rspec.rb"
]
},
...
下面是Linux的
版本:2.0.0
{
// 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:…
如果项目的bin
文件夹中有rspec
,您可以尝试以下操作:
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
},
终于让RSpec在VS代码上运行了,在Mac上有断点!在我的创业公司,没有人知道怎么做。查看微软的handy 我的
Gemfile
。安装3个gems:
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/gems/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}"
]
},
]
}
对于“程序”,使用哪个rspec的值。我的路径假设我安装了带有RVM的Ruby。你的会不一样
对于“pathToBundler”,使用哪个捆绑包的值
对于“pathToRDebugIDE”,使用哪个rdebug ide的值
对于此行:“${workspaceRoot}/spec/***\u spec.rb”
,您的文件可能会有所不同,具体取决于您的spec文件按文件夹的组织方式
运行RSpec:
在VS代码中,进入顶部菜单中的Terminal->newterminal
。确保您位于Ruby项目的根目录中
如果愿意,单击任意行号的左侧以设置断点
单击VS代码左侧的错误图标。从左上角的下拉框中选择配置:
调试RSpec-打开规范文件
或
运行RSpec-all
然后单击左上角的绿色三角形(开始调试
)
更简单:安装VS代码扩展。然后右键单击等级库文件以选择:
运行文件中的所有测试
或
从当前行开始运行测试
我看不出你对你的期望file@Bustikiller刚刚删除。”无论是否有期望,它都无法运行。请尝试使用语法it'testname'do
instead@Bustikiller不会也不起作用。正如我所写的,rspec命令成功了。所以我的rspec代码很好。不管怎样,谢谢你如何调用它?就像其他的一样,选择“RSpec-all”,然后单击开始调试。顺便说一句,我已经很久没有玩RSpec了。谢谢。我会查一下的。我费了很大的劲才把它配置好。在Windows上也可以用WSL。美好的如果你不想把它放在你的档案里怎么办?我尝试过使用gem安装ruby调试ide,将useBundler设置为false并编辑了路径,但是安装Gems不起作用,对于您的ruby项目,您必须将它们放在Gemfile中。如果您不想在生产中使用这些宝石,请将它们放在组:test,:development do
块中。