RSpec failure: could not find table after migration…?

牧云@^-^@ 提交于 2019-12-02 15:11:58

Try to execute

rake db:test:prepare

This should fix your tests db.

Arnold Roa

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.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!