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.
精彩评论