[rspec-users] Loading (or stubbing) data before model loading
Tom Stuart
tom at experthuman.com
Wed Jul 22 09:27:52 EDT 2009
On 22 Jul 2009, at 13:57, David Chelimsky wrote:
>> The problem is that RSpec starts with an empty test database
> Not exactly. RSpec starts with whatever database you have and rolls
> back to that state after each example provided you're only using
> before(:each) to set up state before each example.
Quite right, and I should've been more specific: rake spec sets up an
empty database and then runs RSpec. In the end I solved my problem by
extending the db:test:prepare task to load the fixtures after cloning
the development database structure, which in hindsight is obviously
the right way to fix it.
> Any pre-existing database state will remain, and any state that you
> set up in before(:suite) or before(:all) will not be rolled back
> unless you do so explicitly.
On an unrelated note, why do I occasionally see leakage of fixture
data between specs? I'd expect RSpec's explicit state rollback, plus
Rails' transactional fixtures, to mean that fixtures loaded in one
example would always be invisible to another, but that doesn't seem to
be the case; I've seen many instances of mysteriously-appearing spec
failures which turned out to be because of a change in running order
(touching files + --loadby mtime --reverse) causing fixture leakage to
move somewhere else, always easily remedied by explicitly loading
whatever fixture had been forgotten. Is this a bug somewhere in RSpec
or Rails (or MySQL), or something I'm just doing wrong?
Cheers,
-Tom
More information about the rspec-users
mailing list