我被阻止实施测试,但有点混乱。使用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”
是什么给出了?
答案 0 :(得分:1)
您的spec_helper中是否有以下行:
config.use_transactional_fixtures = true
告诉rspec / test :: unit在开始时启动一个事务 每个测试用例,并在结束时发出回滚。