在 VS Code 上运行 rspec [英] Run rspec on VS Code

查看:42
本文介绍了在 VS Code 上运行 rspec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 rspec 测试代码

I have rspec test code like this

describe 'Utils' do

  puts 1111
  describe '#time_condition' do
    puts 2221
    it do
      puts 'aaa'
    end
    puts 2223
  end
end

我的launch.json是这样的

my launch.json like this

{
  "name": "RSpec - all",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceRoot}",
  "program": "${workspaceRoot}/spec/*_rspec.rb",
  "args": [
    "--pattern",
    "*_rspec.rb"
  ]
},

当我在 vscode 上运行测试时,我得到了

when I run test on vscode, I got

1111
2221
2223

当我通过命令运行测试时,得到

when I run test by command, got

>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 上运行?

As your can see, no 'aaa' output, means no 'it' was executed. So...How can I make 'it' to run on vscode?

顺便说一下,我的规范配置文件(由 rspec --init 生成)就像

by the way, my spec config files (generated by rspec --init)like

.rspec

--color
--require spec_helper

spec\spec_helper.rb

spec\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

VScode : 1.4.0

Ruby 扩展:0.5.3

Ruby Extensions : 0.5.3

谢谢

推荐答案

好的.我解决了!我的错是为程序设置了错误的值.程序必须是rspec路径.

OK. I solved it! My fault is setting wrong value to program. Program must be rspec path.

...
{
  "name": "RSpec - all",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceRoot}",
  "program": "D:/Ruby/Ruby21/bin/rspec",
  "args": [
    "--pattern",
    "${workspaceRoot}/spec/**/*_rspec.rb"
  ]
},
...

这篇关于在 VS Code 上运行 rspec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆