Rspec 切换到 postgresql 后控制器测试中断

Rspec controller tests broken after switch to postgresql

我最初一直在 rspec 中使用 SQLite,没有任何问题。不过,由于我的生产环境使用的是postgresql,所以我改rspec使用postgresql。

我现在收到如下错误:

undefined method `models' for nil:NilClass

据我所知,模型测试仍然运行良好,而我的控制器测试抛出了我在上面发布的错误。任何想法将不胜感激。

事实证明,解决方案与我的数据库没有正确清理自身有关,我最终使用了 "Database_Cleaner" gem:https://github.com/DatabaseCleaner/database_cleaner