ruby - 如何在 minitest 示例中使用标签

ruby - how to use tags within examples for minitest

我有

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,如

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

没有得到:

$ 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 gem 并且捆绑了

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

it "does stuff(some,tags)"

如果您想要更多类似 describe 的标签,那么我认为您想使用 minispec-metadata

it "does stuff", :some, :tags

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

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

注意 minitest-tags gem 已经过时了,会和 minispec-metadata[=33 冲突=] 如果两者同时安装!我建议卸载 minitest-tags,然后使用 minispec-metadata

来自 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