我被困在实施测试时略有混淆。随着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