bootstrapping test database?

With Rails 2.3.x there was a rake task "rake db:test:clone" that I used to use all the time in order to clone the development DB for use with testing.

However I can't seem to find that test with Rails 3.0. How is everyone bootstrapping their test database etc. for testing?

Alex wrote:

With Rails 2.3.x there was a rake task "rake db:test:clone" that I used to use all the time in order to clone the development DB for use with testing.

However I can't seem to find that test with Rails 3.0. How is everyone bootstrapping their test database etc. for testing?

You don't want to do that. Start from a blank DB, and in each test, use factories to create only the records you need for that test. That way it is clearer what is being tested.

Best,

Except for the dictionaries tables. I changed the rake tasks so development and test database are both seeded.

Robert Pankowecki

I did not think that rake db:test:clone cloned the db contents, I thought it was just the structure, that is certainly what happened when I tried it (expecting it to clone the data). Though what the difference is between db:test:clone, db:test:clone_structure and db:test:prepare I am not sure.

If I am right then I think the OP is asking how to create his test db in Rails 3, in other words the equivalent of db:test:prepare.

Colin

Robert Pankowecki wrote:

You don't want to do that. �Start from a blank DB, and in each test, use factories to create only the records you need for that test. �That way it is clearer what is being tested.

Except for the dictionaries tables. I changed the rake tasks so development and test database are both seeded.

No. Even dictionaries should not be seeded in test. Just use factories to create only the actual records needed for each individual test.

As far as I can tell, there is no valid use case for seeding the test DB. Don't ever do it.

Robert Pankowecki

Best,

I can't agree. Try to convince me. Having all the dictionaries seeded once at the start makes my tests shorter and faster.

Robert Pankowecki

Robert Pankowecki wrote:

No. �Even dictionaries should not be seeded in test. �Just use factories to create only the actual records needed for each individual test.

I can't agree. Try to convince me. Having all the dictionaries seeded once at the start makes my tests shorter and faster.

It does not make them faster, because you're loading lots of unnecessary records.

Anyway, who cares who fast your tests are if they're wrong? You can't know that you're actually testing what you think you are, unless you start each test from a blank slate and create only a restricted set of records (generally no more than 10 if your tests are of the proper granularity). Preloading the DB is cheating at solitaire.

Robert Pankowecki

Best,