我是 BDD 新手,我正在尝试使用 MiniTest Spec:
require 'minitest/spec'
require 'minitest/autorun'
class Car
attr_accessor :type
def initialize(type)
@type = 'petrol'
end
end
describe Array do
it "must be diesel" do
Car.new('diesel').type.must_equal 'diesel'
end
end
这太棒了 - 运行它我得到以下输出:
Failure:
test_0001_must_be_diesel(ArraySpec):
Expected "diesel", not "petrol".
这是有道理的 - “预期是柴油,而不是汽油”正是我所期待的。如果我在 must_equal
语句中放置第二个参数(我认为这是我想要在失败时返回的消息) - 我会得到一个奇怪的结果:
require 'minitest/spec'
require 'minitest/autorun'
class Car
attr_accessor :type
def initialize(type)
@type = 'petrol'
end
end
describe Array do
it "must be diesel" do
Car.new('diesel').type.must_equal 'diesel', 'it must be a diesel'
end
end
运行这个我得到:
1) Failure:
test_0001_must_be_diesel(ArraySpec):
it must be a diesel.
Expected "petrol", not "diesel".
出于某种原因,现在它显示“预期是汽油而不是柴油”。因此,添加我假设的消息参数(就像在测试单元版本中一样)似乎会使断言发生翻转。
规范框架中消息参数的想法是否无效?
最佳答案
MiniTest::Spec 处理多个参数的方式存在一些不一致。它似乎已在 https://github.com/seattlerb/minitest/commit/cd4fe89b0057edc2258876ad8c5f5e7e722f73c2 中修复。 .
只需从 RubyGems 安装最新版本的 MiniTest 就可以了:
gem install minitest
然后将其添加到文件顶部以使用 gem:
gem 'minitest'
关于ruby - MinitTest Spec 对第二个参数的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510955/