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
The Ruby side of things is built on top of websocket-driver , nio4r, and concurrent-ruby. Action Cable is powered by a combination of WebSockets and threads. Both the framework plumbing and user-specified channel work are handled internally by utilizing Ruby's native thread support.
You can use ActionCable.createConsumer () to connect to the cable server if action_cable_meta_tag is invoked in the layout. Otherwise, A path is specified as first argument to createConsumer (e.g. ActionCable.createConsumer ("/websocket") ).
Like a database, you can tell ActionCable what type of adapter to use. The adapter choices are async (inline, used for development or testing), Redis (used for production) or PostgreSQL (does not seem very prevalent in the ActionCable use case).
The client of a WebSocket connection is called the consumer. In Action Cable, the consumer is created by the client-side JavaScript framework. Each consumer can, in turn, subscribe to multiple channels. Each channel encapsulates a logical unit of work, similar to what a controller does in a typical MVC setup.
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
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With