2012-05-30 19 views
6

In effetti, si trattava di un problema di configurazione. La specifica/spec_helper.rd indicava l'ambiente 'test'. ho cambiato in 'sviluppo', al fine di rendere più riferimento a config/ambienti/development.rbRSpec fallisce il test

migliori saluti
Fred

Sono nuovo di RoR, e seguendo il tutorial RoR 3.2 da Michael Hartl. (Cap. 3.2.1)

Quando si tratta di eseguire il primo test, RSpec restituisce un centinaio di errori che iniziano con questo (e tutti guardando la stessa più o meno ):

/home/fred/.rvm/gems/[email protected]/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) 

Il mio database DEV è PostgreSQL e sembra funzionare bene (le migrazioni funzionano bene).

Qualcuno può aiutarmi a capire cosa c'è che non va e risolverlo?

Grazie.

Gemfile:

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 

Ambiente:

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 

Fred

+1

È tutto il tuo database.yml? Ci dovrebbe essere una sezione per test, hai solo lo sviluppo. –

risposta

10

è necessario per risolvere questo

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

e aggiungere la sezione test come questo

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

ricordarsi anche di creare test di db :) Rspec viene eseguito in ambiente di "test" in modo da guarderà sotto chiave test da database.yml non sviluppo :)

+0

Sì, certo, hai ragione. I test dovrebbero essere condotti sull'ambiente TEST, che spiega il valore predefinito impostato da Rspec. Il trucco di configurazione di cui sopra mi ha aiutato a capire come funziona, ma non è snello. D'altra parte, lo sviluppo guidato dai test è per lo sviluppo ... Inizierò una discussione su questo ... – user1185081

Problemi correlati