【问题标题】:Rails under test: database configuration does not specify adapter productionRails 被测:数据库配置未指定适配器生产
【发布时间】:2023-03-27 09:50:01
【问题描述】:

导轨 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

在开发中一切正常。

【问题讨论】:

  • 发布你的整个 database.yml

标签: mysql ruby-on-rails rspec


【解决方案1】:

可能的问题:

Rails 环境区分大小写。要么是 database.yml 中的“测试”,要么您正在以“RAILS_ENV=Test”的身份运行测试

【讨论】:

  • 在数据库中,yml test 是小写的。我试过RAILS_ENV=test bundle exec rspec spec没有结果
【解决方案2】:

尝试运行:

rake db:test:prepare 

这将设置运行测试用例所需的测试数据库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多