gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:07 26 4
gpt4 key购买 nike

我有

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 测试示例.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 发生冲突!我建议卸载 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

关于ruby - 如何在 minitest 示例中使用标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51913064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com