在 Rails 3 中使用 PostgreSQL 进行测试

发布于 2024-11-29 13:35:31 字数 696 浏览 0 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2024-12-06 13:35:31

我怀疑您的 database.yml 文件中没有 test 键,并且 Rails 正在尝试使用它但没有找到它。然而,我可能是错的。不过,这看起来确实是这样的问题。

该命令末尾的 --trace 使它输出额外的内容是什么?也许您可以用该输出更新问题来帮助我们?

I have a suspicion that you do not have the test key in your database.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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文