Hi, When I test my Rails controller, I find that records created in before(:all) remain in database while records created in before(:each) and let are wiped out after testing. This made me run "rake test:prepare" for every new test. Is that normal? Best regards, Zhi-Qiang Lei zhiqiang.lei at gmail.com
Evgeni Dzhelyov
2011-Nov-25 15:34 UTC
[rspec-users] before(:all) leaves records in database
Yes, Only before :each is run in transaction. You should avoid creating records in the before :all hook
David Chelimsky
2011-Nov-25 16:14 UTC
[rspec-users] before(:all) leaves records in database
On Nov 25, 2011, at 8:04 AM, Zhi-Qiang Lei wrote:> Hi, > > When I test my Rails controller, I find that records created in before(:all) remain in database while records created in before(:each) and let are wiped out after testing. This made me run "rake test:prepare" for every new test. Is that normal?Yes. before(:all) is not run in a transaction.
When using before(:all) to create records in the database, you should use after(:all) to clean that up. Sometimes when you need to setup a lot of data, this can speed your tests a lot. Otherwise avoid it. On Friday, November 25, 2011 3:04:08 PM UTC+1, Zhi-Qiang Lei wrote:> > Hi, > > When I test my Rails controller, I find that records created in > before(:all) remain in database while records created in before(:each) and > let are wiped out after testing. This made me run "rake test:prepare" for > every new test. Is that normal? > > Best regards, > Zhi-Qiang Lei > zhiqiang.lei at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120407/4aa17d33/attachment.html>