I set up Rails and MySQL in Docker and tried to run the test with rails test, but I got an error.
docker-compose.yml
services:
  mysql_test:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: aaa
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      TZ: 'Asia/Tokyo'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
$ rails test test/integration/aaa_test.rb
Error:
AaaTest#aaa:
ActiveRecord::ConnectionNotEstablished: Access denied for user 'user'@'%' to database 'aaa-1'
Looking at the error content, it refers to aaa-1, and there is no database for it, so an error occurs.
Due to the effect of parallelize (workers:: number_of_processors) in test_helper.rb, change PARALLEL_WORKERS to remove the suffix.
$ PARALLEL_WORKERS=1 rails test test/integration/aaa_test.rb
This will work.
Recommended Posts