如何在Docker中使用Capybara和poltergeist测试ActionCable?
问题描述:
我需要在dockerized rails应用程序内测试ActionCable功能,使用Poltergeist(PhantomJS)运行JS测试。如何在Docker中使用Capybara和poltergeist测试ActionCable?
我试过selenium-webdriver,chromedriver,无头铬...没有任何工作。
当然,将Puma设置为Capybara服务器。
答
我找到了解决方案。问题出现是因为我使用orats
生成了我的应用程序,并且它预先配置了从Web服务器分离的ActionCable(作为单独的泊坞窗容器)。
增加了以下,使其工作:
# 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"]
然后运行
docker-compose run tests bundle exec rspec
瞧!
你是什么意思的“不工作”你得到什么错误?什么是您的驱动程序配置 - 什么是您的水豚设置?什么是您的导轨配置,您是否正在测试环境中运行动作电缆? –
@ThomasWalpole我打算把所有配置都放在问题中,对不起。在测试环境中运行动作电缆的过程是什么意思?我不知道该怎么做。 ActionCable在所有环境中的redis适配器中运行。感谢您的帮助。 –