I have a naked rails 3 app with one model, generated using rails g model User
.
I\'ve added a factory (using factory_girl_rails
):
Try to execute
rake db:test:prepare
This should fix your tests db.
try this out:
For rails version > 4.1+ this solution will work as the current scenario.
but in Rails 4.1+, rake db:test:prepare is deprecated.
try using
rake db:migrate RAILS_ENV=test (it will work for all version of rails)
The point here is that rspec
command doesn't execute migrations on your test database. and rake db:migrate
only runs migrations in your current environment, probably development
. Others environment like production
and test
ends without having those changes.
You can run
rake spec
That will prepare your testing db (drop and create using schema.rb
) and run all tests.
As the other answer suggested, this:
rake db:test:prepare
Will also setup your testing db, but you have to run the rspec command after that, so, personally I prefer the first option.