0

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.

  • What do you mean by "doesn't work" what errors are you getting? What are your driver configurations - what is your capybara setup? What is your rails config, are you running action cable in process in the test environment? – Thomas Walpole Oct 19 '17 at 22:18
  • @ThomasWalpole I'm going to put all configuration in the question, sorry. What do you mean with running action cable in process in the test environment? I don't know how to do that. ActionCable runs in redis adapter in all environments. Thank you for your help. – Pedro Adame Vergara Oct 20 '17 at 09:56

1 Answers1

0

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!