1

I'm trying to set up a reliable continuous integration server that runs rspec. I've read this answer, and indeed if I run db:reset that seems to get me in a good state to run the tests. In fact, if I run db:reset and then after it, on the cli, run rake spec - my tests run.

However, if I make one rake task that does both, like this:

desc 'Run all tests, used by Jenkins CI'
  task :run => [ 'db:reset' ] do
  Rake::Task["spec"].invoke
end

By the time the tests run, the database is empty. That appears to be because rake:spec calls the following:

** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke 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 
** Execute spec

If I'm reading it right, it will (line 2) abort if there are pending migrations. Then, eventually db:schema:load again, which loads the database from schema rb... which I'd already done. And, it makes me particularly unclear why, if it's going to re-wipe the db, it would abort if migrations wouldn't have been applied.

Worse still, in my case the first thing the spec task does is bail because the users table doesn't exist... and that was defined in schema.rb (which at this point has been loaded twice).

Any ideas where I'm misunderstanding?

Community
  • 1
  • 1
Tom Lianza
  • 4,012
  • 4
  • 41
  • 50

0 Answers0