Search code examples
ruby-on-railsrspecrspec-railspostgresql-9.2

connected to db, but rspec says in `initialize': FATAL: password authentication failed for user "sample_app" (PG::Error)


I just started to learn Ruby on Rails by following the learn by example book. I am not sure if Rspec is working correctly for me.

Git: https://github.com/ivawzh/sample_app

Heroku: http://sampleappofivawzh.herokuapp.com/pages/contact

Since I'm able to add data to database from rails server. I guess Postgresql is working fine. But every time I start rspec, it gives me the error below. (I'm not sure if rspec is working because I have never used it before)

E:\RoR docs\sample_app>rspec spec/
rspec spec/
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize': FATAL:  password authentication failed for user "sample_app" (PG::Error)
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `new'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `connect'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:542:in `initialize'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
    from C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
    from C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:792:in `current_version'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
    from E:/RoR docs/sample_app/spec/spec_helper.rb:13:in `<top (required)>'
    from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from E:/RoR docs/sample_app/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

Environment:

Ruby version    2.0.0 (i386-mingw32)
RubyGems version    2.0.2
Rack version    1.5
Rails version   4.0.0
Environment development
Database adapter    postgresql

Solution

  • Rspec will use your test environment, so you need to make sure the test: section of config/database.yml contains the proper settings for your username, password, etc.

    (Looking at your github repo, it looks like you only have this filled in for development mode).