【问题标题】:RSpec fails testing [closed]RSpec未能通过测试[关闭]
【发布时间】:2012-05-30 07:05:43
【问题描述】:

确实,这是一个配置问题。 spec/spec_helper.rd 指向“测试”环境。 我将其更改为“开发”以使其引用 config/environments/development.rb

最好的问候
弗雷德

我是 RoR 的新手,并遵循 Michael Hartl 的 RoR 3.2 教程。

在执行第一个测试时(第 3.2.1 章),RSpec 返回一百 从这个错误开始的错误(并且所有看起来都相同或 少):

/home/fred/.rvm/gems/ruby-1.9.3-p0@ODQ/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in
`resolve_hash_connection': database configuration does not specify
adapter (ActiveRecord::AdapterNotSpecified)

我的 DEV 数据库是 PostgreSQL,看起来运行良好(迁移运行良好)。

有人可以帮助我了解问题所在并解决它吗?

谢谢。

宝石文件:

source 'https://rubygems.org'

gem 'rails', '3.2.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'postgres-pr'
gem 'pg'

# gem for test scripts
group :development, :test do 
gem 'rspec-rails'
end

group :test do
  gem 'capybara', '1.1.2'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

database.yml:

# PostgreSQL 8.4
development:
  adapter: postgresql
  encoding: unicode
  database: ODQ_APP
  pool: 5

环境:

Ruby version    1.9.3 (i686-linux)
RubyGems version    1.8.15
Rack version    1.4
Rails version   3.2.1
JavaScript Runtime  Node.js (V8)
Active Record version   3.2.1
Action Pack version 3.2.1
Active Resource version 3.2.1
Action Mailer version   3.2.1
Active Support version  3.2.1
Middleware  

ActionDispatch::Static
Rack::Lock
#<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0xa848460>
Rack::Runtime
Rack::MethodOverride
ActionDispatch::RequestId
Rails::Rack::Logger
ActionDispatch::ShowExceptions
ActionDispatch::DebugExceptions
ActionDispatch::RemoteIp
ActionDispatch::Reloader
ActionDispatch::Callbacks
ActiveRecord::ConnectionAdapters::ConnectionManagement
ActiveRecord::QueryCache
ActionDispatch::Cookies
ActionDispatch::Session::CookieStore
ActionDispatch::Flash
ActionDispatch::ParamsParser
ActionDispatch::Head
Rack::ConditionalGet
Rack::ETag
ActionDispatch::BestStandardsSupport

Application root    /home/fred/rails_projects/ODQ
Environment development
Database adapter    postgresql
Database schema version 20120503135705

弗雷德

【问题讨论】:

  • 这是你的整个 database.yml 吗?应该有测试部分,你只有开发。

标签: ruby-on-rails rspec railstutorial.org


【解决方案1】:

你需要解决这个问题

# PostgreSQL 8.4
development:
  adapter: postgresql
  encoding: unicode
  database: ODQ_APP
  pool: 5

并像这样添加测试部分

# PostgreSQL 8.4
test:
  adapter: postgresql
  encoding: unicode
  database: ODQ_APP_test
  pool: 5

还记得创建测试数据库 :) Rspec 在“测试”环境中运行,因此他将从 database.yml 而非开发中查看测试密钥:)

【讨论】:

  • 是的,你是对的。测试应在 TEST 环境下进行,这说明了 Rspec 设置的默认值。上面的配置技巧帮助我理解了它是如何工作的,但并不精益。另一方面,测试驱动开发是为了开发......我将开始讨论这个......
猜你喜欢
  • 2017-01-24
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 2012-01-03
相关资源
最近更新 更多