对我来说看起来像一个错误,它不是有效的语法:
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ ruby -c /tmp/test.rb
/tmp/test.rb:3: syntax error, unexpected tLABEL
description: "yyy",
^
/tmp/test.rb:3: syntax error, unexpected ',', expecting keyword_end
/tmp/test.rb:5: syntax error, unexpected ')', expecting keyword_end
我猜这条线
product = Product.new(title: products(:ruby).title),
应该读
product = Product.new(title: products(:ruby).title,
如此重新格式化,测试将如下所示:
test "product is not valid without a unique title -il8n" do
product = Product.new(
title: products(:ruby).title,
description: "yyy",
price: 1,
image_url: "fred.gif"
)
end
(尽管测试描述与行为不匹配;-))