我需要在dockerized rails app中测试ActionCable功能,使用Poltergeist(PhantomJS)运行JS测试。
我尝试过selenium-webdriver,chromedriver,无头镀铬......没什么用。
当然,将Puma设置为Capybara服务器。
答案 0 :(得分:0)
我找到了解决方案。问题出现了,因为我使用orats
生成了我的应用程序,它预配置了从Web服务器分离的ActionCable(作为单独的docker容器)。
添加以下内容以使其有效:
# 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
瞧!