我被困在實施測試時略有混淆。隨着User.create我可以創建並保存在多個測試:Factory Girl創建的對象在測試之間沒有清除?
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的::錯誤:重複項「
什麼給?
什麼是:amanda_levy,這可能是問題的來源 – s84 2010-08-13 06:22:41
這只是Factory.create的工廠女孩語法(:factory_name) – ambertch 2010-08-16 02:38:47