[rspec-devel] Rspec blowing away my initial data

Maurício Linhares mauricio.linhares at gmail.com
Fri Jun 6 16:31:42 EDT 2008


This isn't an rspec feature, every time you run your rails app tests
it will drop the whole database and rebuild it again (based on the
development database) but only the structure will be copied, no data
will be copied and no migrations are run.

If you want to add test data to your specs you should use fixtures
instead or just add your data in a "before" block and remove it in an
"after" block.

On Fri, Jun 6, 2008 at 5:21 PM, weexpectedthis <weexpectedthis at gmail.com> wrote:
>
> I have this code in the only migration I have in my app:
>
>    create_table :states do |generic_table|
>      generic_table.with_options :null => false do |t|
>        t.string :name
>        t.datetime :created_at, :updated_at
>      end
>    end
>
>    State.create!(:name => 'New')
>    State.create!(:name => 'Submitting')
>    State.create!(:name => 'Reviewing')
>    State.create!(:name => 'Implementing')
>    State.create!(:name => 'Finished')
>
> When I run `rake test` it builds my test database with the migration I have
> correctly.  But then when I run `rake spec` and look at the database, the
> initial data (all of the States) are missing.
>
> So my questions are:
> 1) Does rspec blow away my initial data before it runs tests?
>
> 2) How can I get it to stop doing that?



-- 
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
João Pessoa, PB, +55 83 8867-7208


More information about the rspec-devel mailing list