开发者

Factory Girl created objects not clearing in between tests?

开发者 https://www.devze.com 2023-01-11 22:22 出处:网络
I\'m being held up implementing tests with a slight confusion. With User.create I can create and s开发者_如何学JAVAave in multiple tests:

I'm being held up implementing tests with a slight confusion. With User.create I can create and s开发者_如何学JAVAave in multiple tests:

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

but using Factory.create, it throws a ActiveRecord duplicate entry error:

should "test something" do
  Factory.create(:amanda_levy)
  assert true
end

should "test something else" do
  Factory.create(:amanda_levy)
  assert true
end

Error: "ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry"

What gives?


Do you have the the following line in your spec_helper:

config.use_transactional_fixtures = true

That tells rspec/ test::unit to start a transaction at the start of every test case, and issue a rollback when it's over.

0

精彩评论

暂无评论...
验证码 换一张
取 消