9

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

  • 2
    Please show your configuration of puma as Capybaras server – Thomas Walpole Mar 09 '16 at 16:34
  • 2
    Also - what have you set config.action_cable.allowed_request_origins to in your test config – Thomas Walpole Mar 09 '16 at 16:37
  • @TomWalpole I just edited my question. I think I'm using your capybara PR to configure Puma :). Also, config.action_cable.allowed_request_origins is not set. – Sergio D. Márquez Mar 09 '16 at 17:13
  • 2
    ok -- rather than trying to configure allowed_request_origins in the test env with unknown ports, names, etc I just set `config.action_cable.disable_request_forgery_protection = true` in my test.rb - which allows connections from any location – Thomas Walpole Mar 09 '16 at 17:21
  • From here: https://github.com/rails/rails/tree/master/actioncable#allowed-request-originse – Thomas Walpole Mar 09 '16 at 17:31
  • Thanks, but that didn't work. – Sergio D. Márquez Mar 09 '16 at 17:31
  • How are you specifying the connection location for action cable? Are you using action_cable_meta_tag in your layout? Are you hardcoding in your JS? – Thomas Walpole Mar 09 '16 at 17:33
  • I am using action_cable_meta_tag . Also configuring App.cable = ActionCable.createConsumer() just like that, without specifying an address. Please note that this configuration works fin in development mode – Sergio D. Márquez Mar 09 '16 at 17:38
  • One last guess -- Did you specify Capybara.server = :puma ?? Without that the server would be registered but Capybara would still start webrick. If thats not it I would say say it's time to debug the browser connection and see whats happening -- (also I assumed you were using a JS capable driver with capybara - seems too simple but just verifying) – Thomas Walpole Mar 09 '16 at 17:42
  • Yesss that was it! Can you add that response as an answer so I can mark it correct? – Sergio D. Márquez Mar 09 '16 at 17:47

2 Answers2

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.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
}
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
6

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

NickGnd
  • 5,107
  • 1
  • 20
  • 26