Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

factory_girl + rspec doesn't seem to roll back changes after each example

Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec

in Short (shorten'd code):

spec_helper:

config.use_transactional_fixtures = true
config.use_instantiated_fixtures  = false

factories.rb:

Factory.define :state do
  f.name "NY"
end

in my spec

before(:each) do 
  @static_model = Factory(:state) # with validate uniqueness of state name
end

error:

duplicate entry name "NY" etc.


Question: Shouldn't rspec clear database before each spec example and hence not throwing duplicate entry errors?

like image 727
Rex Avatar asked Jul 26 '10 09:07

Rex


1 Answers

Things i think off:

  • do you use rake spec to run your testsuite: that builds up the database from scratch (to make sure nothing is sticking)
  • do you use, anywhere, a before (:all) ? Because whatever you create inside a before :all should be deleted again in a after :all or it keeps on existing.
like image 189
nathanvda Avatar answered Sep 23 '22 03:09

nathanvda