Capybara没有使用action_cable

时间:2021-08-17 01:14:38

I'm using the Rails 5 beta 3 with action cable, the integration works fine in development but when I try to run a feature test through capybara, it doesn't seem to hit the channel actions.

我正在使用带有动作电缆的Rails 5 beta 3,这种集成在开发中运行良好,但是当我尝试通过capybara运行功能测试时,它似乎没有达到通道操作。

I'm using Portergeist and configured puma as capybara's server. Also I'm using es5-shim and es6-shim.

我正在使用Portergeist并将puma配置为capybara的服务器。我也在使用es5-shim和es6-shim。

Has anyone else experienced this or knows any workaround?

有没有其他人经历过这个或知道任何解决方法?

Thanks!

Edit

Im using this capybara branch to configure Puma in Capybara

我正在使用这个水豚分支来配置Capybara中的Puma

Capybara.register_server :puma do |app, port, host|
  require 'puma'
  Puma::Server.new(app).tap do |s|
    s.add_tcp_listener host, port
  end.run.join
end

I have not set anything on config.action_cable.allowed_request_origins

我没有在config.action_cable.allowed_request_origins上设置任何内容

2 个解决方案

#1


12  

For testing actioncable with Capybara you need to be using a multithreaded webserver. Since you're using a current pull request on Capybara that supports registering named drivers you will need to specify the named server to use

要使用Capybara测试actioncable,您需要使用多线程Web服务器。由于您在Capybara上使用支持注册命名驱动程序的当前pull请求,因此您需要指定要使用的命名服务器

Capybara.server = :puma

For anyone not using the capybara branch with named servers you can do

对于没有使用带有命名服务器的capybara分支的人,你可以做到

Capybara.server {|app, port| 
  require 'puma'
  Puma::Server.new(app).tap do |s|
    s.add_tcp_listener Capybara.server_host, port
  end.run.join
}

#2


6  

From Capybara v2.7.0 passing a block to Capybara::server is deprecated (commit).

从Capybara v2.7.0传递一个块到Capybara :: server不推荐使用(commit)。

Deprecation message: DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead

弃用消息:DEPRECATED:不推荐将块传递给Capybara :: server,请改用Capybara :: register_server

To register new web server (for example puma) use:

要注册新的Web服务器(例如puma),请使用:

  Capybara.register_server :puma do |app, port, host|
    require 'puma'
    Puma::Server.new(app).tap do |s|
      s.add_tcp_listener host, port
    end.run.join
  end

Link to documentation

链接到文档

#1


12  

For testing actioncable with Capybara you need to be using a multithreaded webserver. Since you're using a current pull request on Capybara that supports registering named drivers you will need to specify the named server to use

要使用Capybara测试actioncable,您需要使用多线程Web服务器。由于您在Capybara上使用支持注册命名驱动程序的当前pull请求,因此您需要指定要使用的命名服务器

Capybara.server = :puma

For anyone not using the capybara branch with named servers you can do

对于没有使用带有命名服务器的capybara分支的人,你可以做到

Capybara.server {|app, port| 
  require 'puma'
  Puma::Server.new(app).tap do |s|
    s.add_tcp_listener Capybara.server_host, port
  end.run.join
}

#2


6  

From Capybara v2.7.0 passing a block to Capybara::server is deprecated (commit).

从Capybara v2.7.0传递一个块到Capybara :: server不推荐使用(commit)。

Deprecation message: DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead

弃用消息:DEPRECATED:不推荐将块传递给Capybara :: server,请改用Capybara :: register_server

To register new web server (for example puma) use:

要注册新的Web服务器(例如puma),请使用:

  Capybara.register_server :puma do |app, port, host|
    require 'puma'
    Puma::Server.new(app).tap do |s|
      s.add_tcp_listener host, port
    end.run.join
  end

Link to documentation

链接到文档