简体   繁体   中英

Rake cannot run Rspec specs in Docker/Rails/Postgres setup (but web app works fine)

Is there a special step or configuration needed to get Rails (3.2.21) test database (eg, Rspec specs) working under Docker when using the Heroku-docker solution?

I'm using Docker Toolkit (the Docker Quickstart Terminal) to run my Heroku app locally, and everything except running specs is working.

This works:

docker-compose run web rake db:reset

And the web app works, reading and writing the database with all seed value loaded.

However any command to create or use the test database fails:

docker-compose run web rake db:test:prepare
docker-compose run web rake db:test:load    
docker-compose run web rake spec
docker-compose run web bundle exec rake spec

all throw the error:

PG::ConnectionBad: FATAL: role "root" does not exist

I'm using the Heroku postgres image, with an app.json that looks like:

{
  "name": "My App",
  "description": "Localized Docker Setup",
  "image": "hrails200",
  "addons": [
    "heroku-postgresql"
  ]
}

(hrails200 is the heroku/ruby image modified to use Ruby 2.0.0)

and the docker-compose.yml file ends with:

herokuPostgresql:
  image: postgres

and the web and worker have a links entry pointing to Postgres:

  links:
    - herokuPostgresql

My config/database.yml looks like:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: docker_mondo_dev

test:
  <<: *default
  database: docker_mondo_test

When you connect to Postgres, it defaults to the current Unix user ( $USER ). Under Docker, you are 'root' by default. However, Postgres does not have any user named 'root' by default. Instead, the superuser is named 'postgres'.

I think that your web app is specifying a database user name, and your test is not. You might try setting the PGUSER environment variable to postgres .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM