So this was a cool trick I learned today.

Rake allows you to chain rspec commands. So lets say you want to drop the database, rerun migrations, seed and then run specs at the end. It’s now as simple as:

rake db:drop db:create db:migrate db:test:prepare spec

There is one caveat to this though.

There appears to be some funkiness with how rails is loaded. In a couple of the apps I’ve worked on, chaining db:seed to the end doesn’t work. It tends to break up saying methods haven’t been defined.  In my specific case, the attribute was defined initially  but was  later deemed superfluous and removed. Rails seems to be break and never recognize that this later migration had been run.

There is a pretty simple workaround for this. Just start a new command at the end. While it’s not quite as succinct, running:

rake db:drop db:create db:migrate; rake db:seed db:test:prepare spec

will do the job just fine.

  1. naudo posted this