【问题标题】:How to test ActionCable with Capybara and poltergeist inside Docker?如何在 Docker 中使用 Capybara 和 poltergeist 测试 ActionCable?
【发布时间】:2017-10-19 22:04:16
【问题描述】:

我需要在 dockerized rails 应用程序中测试 ActionCable 功能,使用 Poltergeist (PhantomJS) 运行 JS 测试。

我已经尝试过 selenium-webdriver、chromedriver、headless chrome……没有任何效果。

当然,将 Puma 设置为 Capybara 服务器。

【问题讨论】:

  • “不起作用”是什么意思,您遇到了什么错误?您的驱动程序配置是什么 - 您的水豚设置是什么?你的 Rails 配置是什么,你在测试环境中运行 action cable 吗?
  • @ThomasWalpole 我将把所有配置都放在问题中,抱歉。在测试环境中运行动作电缆是什么意思?我不知道该怎么做。 ActionCable 在所有环境中的 redis 适配器中运行。感谢您的帮助。

标签: rspec capybara docker-compose poltergeist actioncable


【解决方案1】:

我找到了解决方案。问题出现是因为我使用 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

瞧!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多