RSpec failure: could not find table after migration…?

后端 未结 3 1096
感情败类
感情败类 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:42

    Try to execute

    rake db:test:prepare
    

    This should fix your tests db.

    0 讨论(0)
  • 2021-01-30 11:46

    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)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题