I just found that any db changes I make in before(:all) will not automatically rollback when tests were finished. It leave a dirty test environment and broke my specs in next round.
Here is the example:
@user = User.new
# do some very time consuming task that need @user
it "should have some consequences" do
it "should have some other consequences" do
And I will found that there is a user in my test db after I run this spec.
I think it should rollback any db changes I made in before(:all) when it finished running all the specs in that describe block.
transactions are not supported in before(:all)
Thanks for the clarification.
Sure - I need to doc this in a more public place - will try to remember to comment here when I do (though if you google "rspec transactions before(:all)" you'll see a lot of references to it).
Any specific reason why there are no TX in before(:all)?
@dchelimsky We just ran into this as well...
I don't really understand why transactions are not supported for :all but for :each?
May I suggest to at least document it right there: http://relishapp.com/rspec/rspec-core/v/2-6/dir/hooks/before-and-after-hooks :)
Transaction management is handled by Rails, not RSpec, and Rails has no concept of before(:all) to tap into. Additionally, not all RDBMSes handle nested transactions, which would be a requirement for this to work. This would mean additional confusion/complexity/frustration when users switch databases.
If this is really as big a problem for you as you say, the tools to fix it are at your disposal. You just need to tell Rails (via RSpec) not to manage transactions, and then manage them explicitly via database_cleaner, opening transactions in all before(:all) and before(:each) hooks, and closing them in after(:each) and after(:all) hooks. If you care to publish a gem that does this, I'd be glad to reference it in the documentation, but it is not the common case in my view and I don't want to confuse things any further by adding this to rspec-rails directly.
As for where to doc this, rspec-core is the wrong place as there is nothing rails specific about it. It should be somewhere in http://relishapp.com/rspec/rspec-rails. I'll give it some thought and get it documented.
thanks for the explanation.