在VS Code上运行rspec

问题描述 投票:2回答:2

我有这样的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

当我按命令运行测试时,得到了

>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'输出,意味着没有'它'被执行。那么......我如何让'它'在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

谢谢

ruby visual-studio-code
2个回答
2
投票

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

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

1
投票

这是适用于Linux的version: 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: ...

© www.soinside.com 2019 - 2024. All rights reserved.