我的一些rSpec测试失败了,我怀疑这是因为测试数据库没有被清除。当我尝试运行rake db:test:prepare时,我收到下面的错误(我在Rails 3.2中)。显然,这看起来像某种Postgres问题,看起来rake任务试图删除测试数据库,以便它可以重新填充它。生产数据库模式加载正常。
我在lib / tasks /中寻找过rake任务但是我找不到它。任何人都知道发生了什么事?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
答案 0 :(得分:1)
想出来。我的开发环境的database.yml文件设置如下:
database: <%= ENV['DATABASE_NAME_TEST'] %>
rake任务正在寻找一个不存在的环境变量。