我无法在Google或stackoverflow上的任何其他位置找到此确切错误。
我正在运行Rails 4.1.0和rspec-rails 3.0.0.beta2
尝试运行$ rspec时,出现以下错误:
DEPRECATION WARNING: Passing a string to ActiveRecord::Base.establish_connection for a configuration lookup is deprecated, please pass a symbol (:development) instead. (called from <top (required)> at /Users/sam/code/rails/innovacert/spec/spec_helper.rb:4)
/Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection': 'development' database is not configured. Available: ["test"] (ActiveRecord::AdapterNotSpecified)
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:240:in `resolve_string_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:267:in `resolve_hash_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:228:in `resolve_connection'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:152:in `resolve'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:164:in `block in resolve_all'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `each'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `resolve_all'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_handling.rb:69:in `resolve'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/core.rb:46:in `configurations='
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/core.rb:48:in `block in <module:Core>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/concern.rb:120:in `class_eval'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/concern.rb:120:in `append_features'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/base.rb:297:in `include'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/base.rb:297:in `<class:Base>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/base.rb:282:in `<module:ActiveRecord>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/base.rb:23:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails/extensions/active_record/base.rb:25:in `<module:Extensions>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails/extensions/active_record/base.rb:4:in `<module:Rails>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails/extensions/active_record/base.rb:2:in `<module:RSpec>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails/extensions/active_record/base.rb:1:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails/extensions.rb:1:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-rails-3.0.0.beta2/lib/rspec/rails.rb:10:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /Users/sam/code/rails/innovacert/spec/spec_helper.rb:4:in `<top (required)>'
from /Users/sam/code/rails/innovacert/spec/validators/rut_validator_spec.rb:1:in `require'
from /Users/sam/code/rails/innovacert/spec/validators/rut_validator_spec.rb:1:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
from /Users/sam/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `load'
from /Users/sam/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `<main>'
from /Users/sam/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/sam/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
错误是从spec_helper.rb中的“require'rspec / rails'”生成的。
我不明白为什么会这样,因为我在database.yml中正确配置了测试数据库:
default: &default
host: localhost
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000
development:
<<: *default
database: innovacert_development
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASS'] %>
# 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:
<<: *default
database: innovacert_test
username: sam
password:
从这一行:
/Users/sam/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/connection_adapters/connection_specification.rb:257:in'refour_symbol_connection':'开发'数据库不是配置。可用:[“test”](ActiveRecord :: AdapterNotSpecified)
看起来,rspec正试图寻找一个名为:development的数据库。然而在spec_helper.rb中我明确定义了:
ENV [“RAILS_ENV”] || =“test”
我用pry来看看这个变量,它肯定被指定为'test'。
为什么rspec失败?