在 Rails 3 中使用 PostgreSQL 进行测试
我正在尝试将 Rails 测试环境从 SQLite3 切换到 Postgresql。
但是,当我运行时,
rake spec:requests
会生成此错误:
omar@loco:~/apps/gctest$ rake spec:requests
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
我能够访问开发中的数据库(用于测试的database.yml 文件看起来与开发类似,但带有_test)。
是否存在我不知道的问题? “任务:...”行是什么意思?
我的环境:
rspec (2.6.0)
rails (3.0.9)
ruby 1.9.2p290
pg (0.11.0)
psql (PostgreSQL) 8.4.8
I am trying to switch my Rails TEST environment from SQLite3 to Postgresql.
However, when I run
rake spec:requests
this error is generated:
omar@loco:~/apps/gctest$ rake spec:requests
rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
I am able to access the DB in Development (my database.yml file for test looks similar to development but with _test).
Are there any gotchas that I'm unaware of?
what does the "Tasks:..." line mean?
My env:
rspec (2.6.0)
rails (3.0.9)
ruby 1.9.2p290
pg (0.11.0)
psql (PostgreSQL) 8.4.8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您的
database.yml
文件中没有test
键,并且 Rails 正在尝试使用它但没有找到它。然而,我可能是错的。不过,这看起来确实是这样的问题。该命令末尾的
--trace
使它输出额外的内容是什么?也许您可以用该输出更新问题来帮助我们?I have a suspicion that you do not have the
test
key in yourdatabase.yml
file and Rails is attempting to use that and not finding it. However, I could be wrong. That does look like that kind of issue though.What does
--trace
at the end of that command make it output extra? Perhaps you could update the question with that output to help us?