RSpec failure: could not find table after migration…?

后端 未结 3 1151
感情败类
感情败类 2021-01-30 11:12

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):



        
3条回答
  •  不知归路
    2021-01-30 11:53

    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.

提交回复
热议问题