I have a problem using ActionCable with system specs using Capybara. ActionCable is working perfectly on my development server, but when testing with system specs, it is unable to connect to Websockets.
The output from /log/test.log shows:
Started GET "/cable" for 127.0.0.1 at 2017-11-15 18:17:04 +0900
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2017-11-15 18:17:04 +0900
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
WebSocket error occurred: undefined method `write_nonblock' for nil:NilClass
WebSocket error occurred: undefined method `write_nonblock' for nil:NilClass
WebSocket error occurred: undefined method `write_nonblock' for nil:NilClass
I'm using:
- ruby 2.4.1
- rails 5.1.4
- rspec 3.7.0
- capybara 2.13.0
- puma 3.10.0
- selenium-webdriver 3.6.0
I have tried:
Capybara.server = :puma
This made no difference (probably since system specs are already using Puma).
My attempt at debugging the issue:
Looking closer at the error, the method write_nonblock is called on nil, which happens here on line 45:
It seems like @rack_hijack_io gets set to nil, which likely happens in the hijack_rack_socket method here:
@socket_object.env["rack.hijack_io"] returns nil, so we don't have a "rack.hijack_io" key. So the error seems to be related to the Rack Hijacking API.