I’m trying to setup rspec for testing in my rails application. I have created some sample test and executed rake rspec --trace.
In output I see this messages
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
Schema gets loaded and then rake task breaks, because I’m trying to use some values from database in one of files in initializers directory. Normally those records are in the database, they are all present in seed_fu files in db/fixtures directory.
I’m looking a way to execute this files after db:schema:load. Somebody knows how to do it?
It appears you can access the seeder directly with a simple call to
SeedFu.seed.This has the advantage of ensuring seeds run in the proper order, and if you need to, you can pass arguments for specific fixture paths or filtering options – I could see using a specific path useful for test-only fixtures, for instance.
Here’s the seed-fu method:
I have no idea if this method is meant to be used publicly, but for now at least it seems to work well for my uses.