Docker Community Forums

Share and learn in the Docker community.

Rails testing with docker-compose errors on gem method missing

I’ve been trying to setup docker-compose to help with automating local development testing and hopefully make the move to a new laptop a bit easier, but all of my tests fail with the error below. I think the issue has to do with context of anything being run in gems, but that’s just an idea I have. I made a small service called ‘testing’, but the same thing happens if I open a shell in a container with docker runner below and try to run any tests.

I’ve been following this tutorial:

Here is the error I’m getting from my tests. I don’t think that uuidtools is special, it’s just required for a generic setup called MasterSetup and used in almost every part of the application.

Failures:

1) Address#can_view? should be visible if linked to my company
 Failure/Error: MasterSetup.first_or_create! :uuid => UUIDTools::UUID.timestamp_create.to_s
 
 NoMethodError:
   undefined method `split' for nil:NilClass
 # /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:611:in `first_mac'
 # /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:630:in `mac_address'
 # /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:244:in `block in timestamp_create'
 # /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:234:in `synchronize'
 # /usr/local/bundle/gems/uuidtools-2.1.4/lib/uuidtools.rb:234:in `timestamp_create'
 # ./app/models/master_setup.rb:243:in `init_test_setup'
 # ./spec/spec_myapp_setup.rb:26:in `block (2 levels) in <top (required)>'

Here is my docker-compose file, most of it is the same from the previously mentioned post. I’ve been experimenting with removing certain lines, but it’s not been helping.

version: '3.7'
services:
  app: &app
    build:
      context: .
      dockerfile: .dockerdev/Dockerfile
  args:
    RUBY_VERSION: '2.5.1'
    BUNDLER_VERSION: '1.17.3'
image: myapp-dev:1.0.1
tmpfs:
  - /tmp

  backend: &backend
    <<: *app
    # The same as running a docker container with -it options
    stdin_open: true
    tty: true
    volumes:
      - .:/app:cached
      - bundle:/usr/local/bundle
      # This is just to make it faster
      - rails_cache:/app/tmp/cache
    environment:
      # Use the system rails environment or default to development
      - RAILS_ENV=${RAILS_ENV:-development}
      # Help keep Rails memory usage in check
      - MALLOC_ARENA_MAX=2
      - WEB_CONCURRENCY=1
    depends_on:
      - mysql
      - redis
      - memcached

  # use for running tests or the rails console
  # $ docker-compose run runner exec rails c
  runner:
    <<: *backend
    command: /bin/bash
    ports:
      - '3000:3000'

  rails:
    <<: *backend
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -b '0.0.0.0'"
    ports:
      - '3000:3000'

  testing:
    <<: *backend
    environment:
      # Use the system rails environment or default to development
      - RAILS_ENV=${RAILS_ENV:-test}
      # Help keep Rails memory usage in check
      - MALLOC_ARENA_MAX=2
      - WEB_CONCURRENCY=1
command: bash -c "bundle exec rspec spec/models/address_spec.rb"
ports:
  - '3000:3000'

  mysql:
    image: mysql:5.7
    command: mysqld
    volumes:
      - ./.dockerdev/my.cnf:/etc/mysql/my.cnf # Settings
      - mysql:/var/lib/mysql # Datadirectory
      - ./log:/root/log:cached
    environment:
      MYSQL_ROOT_PASSWORD: 'password'
      MYSQL_HISTFILE: /root/log/.mysql_history
    ports:
      - '3306:3306'

  memcached:
    image: 'bitnami/memcached:1.5.16'
    command: ["memcached"]

  redis:
    image: 'redis:5.0.5'
    volumes:
      - redis:/data
    ports:
      - 6379

volumes:
  mysql:
  redis:
  bundle:
  rails_cache:

I’ll post more as I figure out more.

The solution was to install net-tools into the container. I guess UUIDTools needs that to retrieve MAC address information