问题
I have
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
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
without getting:
$ 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)
I have the minitest-tags gem in my Gem file and have bundled
回答1:
The minitest-tags gem does not accept tags as additional arguments, instead they are given in the title text:
it "does stuff(some,tags)"
If however you want more describe
-like tags, then I think you want to use minispec-metadata instead:
it "does stuff", :some, :tags
Then you can run selected tests using the --tag
option:
$ ruby test_example.rb --tag some --tag tags
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.
Note from OP - So I ended up having:
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
来源:https://stackoverflow.com/questions/51913064/ruby-how-to-use-tags-within-examples-for-minitest