Ruby on Rails unit test: cannot find table error

2012.01.18 | Rails, Ruby | ,

If your Ruby on Rails unit tests complain about not being able to find a table after you’ve added a new model, it just means you forgot to prepare the test database with the latest data. ┬áThe error looks like this:

ActiveRecord::StatementInvalid: Could not find table ‘yourtablenamehere’

To fix, just run:

rake db:test:prepare

and then re-run your test.