Capybara not working with action_cable

与世无争的帅哥 提交于 2019-12-03 17:48:00

问题


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.

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

Has anyone else experienced this or knows any workaround?

Thanks!

Edit

Im using this capybara branch to configure Puma in Capybara

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


回答1:


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.server = :puma

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

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:


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

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

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

  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



来源:https://stackoverflow.com/questions/35897189/capybara-not-working-with-action-cable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!