0
我捎带在我早些时候的question那里我有一家工厂创建一个父母和孩子。我正在运行我的单元测试,并且有一个不通过的简单测试。MiniTest的工厂女孩
test "invoice can save" do
invoice = build(:invoice)
assert invoice.save, "Error message: #{invoice.errors.full_messages}"
end
返回以下错误。
错误消息: “跳闸不能为空”]
但是,下面的代码工作。
test "invoice can save" do
invoice = create(:invoice)
assert invoice.save, "Error message: #{invoice.errors.full_messages}"
end
我的理解是,build
应该将它保存在内存中,直到调用save。是不是第一个更好的测试,看看它是否成功地保存到数据库?
1日感谢您使用形容词小气。 第二谢谢你通过这个和我连接的问题。 我一定会给你链接评论的文章。 – CheeseFry
很高兴有人欣赏一些有趣的形容词哈哈:)并希望响应也帮助解决了更大的测试问题! –