[rspec-users] how to avoid tests removing data that my migrations put in?

Pat Maddox pergesu at gmail.com
Tue Nov 4 19:26:36 EST 2008

Ben Mabey <ben at benmabey.com> writes:

> Aslak Hellesøy wrote:
>> Sent from my iPhone
>> On 5. nov.. 2008, at 00.05, Pat Maddox <pergesu at gmail.com> wrote:
>>> "Greg Hauptmann" <greg.hauptmann.ruby at gmail.com> writes:
>>>> hi,
>>>> I have an issue in that I have some reference data my migrations run
>>>> in. However when running  "rake spec" it seems to remove the data in
>>>> the test database up front.
>>>> What do you recommend to workaround this issue?
>>>> Thanks
>>>> Greg
>>>> _______________________________________________
>>>> rspec-users mailing list
>>>> rspec-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>> You should probably create it in a before block, or if the reference
>>> data is always going to be the same, you'll want to insert it into the
>>> db BEFORE the test transactions start.  That will require a bit of
>>> work...clear out all the tables and insert the data, that way when
>>> transactions get rolled back you're back at the db with reference data.
>>> I'm not quite sure how to do that though.  Is there a before(:suite)
>>> that might work?
>> There is no need for a special construct. Just do it at the top
>> level in env.rb or an adjacent file. Use at_exit for a global
>> "teardown".
> I believe they are talking about rspec examples and not cucumber features...

aslak's right though in that case too.  In your spec_helper, just loop
over the tables and delete everything, then insert the seed data you
want, and it should be good to go.


More information about the rspec-users mailing list