我在实施测试时感到有些困惑。使用 User.create 我可以在多个测试中创建和保存:
should "test something" do
u1 = User.create(:first_name => "Fred", :last_name => "Flintstone")
assert true
end
should "test something else" do
u1 = User.create(:first_name => "Fred", :last_name => "Flintstone")
assert true
end
但是使用 Factory.create,它会引发 ActiveRecord 重复条目错误:
should "test something" do
Factory.create(:amanda_levy)
assert true
end
should "test something else" do
Factory.create(:amanda_levy)
assert true
end
错误:“ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry”
是什么赋予了?