【发布时间】:2012-11-04 20:06:18
【问题描述】:
在《Agile Web Development with Rails》一书中,他们正在教授如何编写测试单元用例:
test "product price must be positive" do
product = Product.new(title: "By Book Title",
description: "yyy",
image_url: "zzz.jpg")
product.price = -1
assert product.invalid?
assert_equal ["must be greater than or equal to 0.01"], product.errors[:price]
end
关于 assert_equal 语句,为什么“必须大于...”字符串需要括号。我假设变量类型在这里发挥作用,但需要澄清原因。
谢谢。
【问题讨论】:
标签: ruby-on-rails unit-testing variable-types