Forum: RSpec before(:all) leaves records in database

Posted by Zhi-Qiang Lei (Guest)
on 2011-11-25 15:59
(Received via mailing list)
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@gmail.com
Posted by Evgeni Dzhelyov (Guest)
on 2011-11-25 17:33
(Received via mailing list)
Yes,

Only before :each is run in transaction. You should avoid creating
records in the before :all hook
Posted by David Chelimsky (Guest)
on 2011-11-25 18:15
(Received via mailing list)
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.