问题
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