簡體   English   中英

受測的Rails:數據庫配置未指定適配器的生產

[英]Rails under test: database configuration does not specify adapter production

導軌3.2.18
的mysql2 0.3.18

嘗試啟動rspec spec
有很多:

19) Reports::TaxReportService  should properly generate for rests
     Failure/Error: Unable to find matching line from backtrace
     ActiveRecord::AdapterNotSpecified:
       database configuration does not specify adapter
     # /home/drobazko/.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection'
     # /home/drobazko/.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
     # /home/drobazko/.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:27:in `spec'
     # /home/drobazko/.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
     # ./spec/support/database_cleaner.rb:18:in `block (2 levels) in <top (required)>'

* database.yml

# MySQL.  Versions 4.1 and 5.0 are recommended.
# 
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: mrdelivery_development
  pool: 5
  username: hd_user
  password: 
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: mrdelivery_test
  pool: 5
  username: hd_user
  password: 
  host: 127.0.0.1
  port: 3306

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: mrdelivery_production
  pool: 5
  username: hd_user
  password: 
  host: localhost

在開發中,一切正常。

可能的問題:

Rails環境區分大小寫。 是database.yml中的“測試”,還是您以“ RAILS_ENV = Test”的身份運行測試

嘗試運行:

rake db:test:prepare 

這將設置運行測試用例所需的測試數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM