Search code examples
rspeccapybaradocker-composepoltergeistactioncable

How to test ActionCable with Capybara and poltergeist inside Docker?


I need to test ActionCable functionality inside a dockerized rails app, running JS tests with Poltergeist (PhantomJS).

I've tried selenium-webdriver, chromedriver, headless chrome... nothing works.

And of course, setting Puma as the Capybara server.


Solution

  • I found the solution. The problem came because I generated my app using orats and it preconfigures ActionCable detached from web server (as a separate docker container).

    Added the following to make it work:

    # rails_helper.rb
    Capybara.server = :puma
    
    # docker-compose.yml
    services:
      ...
      tests:
        depends_on:
           - 'redis'
           - 'postgres'
           - 'box'
        build: .
        volumes:
          - '.:/app'
        volumes_from:
           - box # busybox image to cache bundle install
        env_file:
           - '.env'
        environment:
          RAILS_ENV: test
          ACTION_CABLE_MOUNT: '/cable'
        command: /bin/true
    
    # config/environments/test.rb
    config.action_cable.url = nil
    config.action_cable.mount_path = ENV["ACTION_CABLE_MOUNT"]
    

    Then run

    docker-compose run tests bundle exec rspec
    

    Voila!