When you add data in an RSpec before :all, it's not inside the transactions RSpec places around each test. rake spec clears the database before running all the specs, but the data created in before :all will hang around after it runs. This introduces an order dependency between specs. A spec that assumes the database (or one table) is empty will run fine if it runs before the before :all, but can fail if it runs after. Your specs can start failing just because you reorganized them, which changed their run order.
I've been bitten by this three or four times. The moral is to not create data in a before :all if other code assumes that data isn't there.
Tuesday, November 23, 2010
Subscribe to:
Post Comments (Atom)
2 comments:
Hey - your blog just served it's mission - this was helpful! Love the blog title as well! :)
well, you can still use before(:all) as long as you clear out your data in after(:all)
Post a Comment