如何在示例中使用标记以进行最小测试

如何在示例中使用标记以进行最小测试

本文介绍了红宝石-如何在示例中使用标记以进行最小测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/tags'
require 'rspec/expectations'

describe "One happy and one sad test", :happy do
  include RSpec::Matchers

  it "it is true" do
    expect(true).to be true
  end
  it "it is false" do
    expect(false).to be true
  end
end

describe标记有效,但是我不能像

那样将标记添加到it

and the describe tag works but I can't add a tag to the it, as in

it "it is true", :happy do
  expect(true).to be true
end

没有得到:

$ ruby​​ test_example.rb

$ ruby test_example.rb

...1: from test_example.rb:9:in `block in <main>'

.../minitest-5.11.3/lib/minitest/spec.rb:212:in `it':
wrong number of arguments (given 2, expected 0..1) (ArgumentError)

我的Gem文件中有minitest-tags宝石,并且已捆绑

I have the minitest-tags gem in my Gem file and have bundled

推荐答案

minitest-tags gem不接受标签作为附加参数,而是在标题文本中给出:

The minitest-tags gem does not accept tags as additional arguments, instead they are given in the title text:

it "does stuff(some,tags)"

但是,如果您想要更多类似describe的标签,那么我想您要使用 minispec-元数据代替:

If however you want more describe-like tags, then I think you want to use minispec-metadata instead:

it "does stuff", :some, :tags

然后,您可以使用--tag选项运行选定的测试:

Then you can run selected tests using the --tag option:

$ ruby test_example.rb --tag some --tag tags

请注意, minitest-tags gem已经相当过时,如果同时安装 minispec-metadata ,它将与 minispec-metadata 冲突!我建议卸载 minitest-tags ,并改为使用 minispec-metadata .

Note that the minitest-tags gem is quite outdated, and it will conflict with minispec-metadata if both are installed at the same time! I recommend uninstalling minitest-tags, and going with minispec-metadata instead.

OP的注意事项-所以我最终遇到了

require 'minitest/spec'
require 'minitest/autorun'
require 'minispec-metadata'
require 'rspec/expectations'

describe "One happy and one sad test" do
  include RSpec::Matchers

  it "is is true", :happy do
    expect(true).to be true
  end
  it "it is false", :sad do
    expect(true).to be true
  end
end

这篇关于红宝石-如何在示例中使用标记以进行最小测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:36