10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/tests/controllers/users_controller_test.rb', line 10
def test_websocket_handshake_written_to_io
env = Rack::MockRequest.env_for(
'/ws',
{
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/ws',
'HTTP_CONNECTION' => 'keep-alive, Upgrade',
'HTTP_UPGRADE' => 'websocket',
'HTTP_HOST' => 'localhost:9292',
'HTTP_ORIGIN' => 'http://localhost:9292',
'HTTP_SEC_WEBSOCKET_KEY' => 'dGhlIHNhbXBsZSBub25jZQ==',
'HTTP_SEC_WEBSOCKET_VERSION' => '13',
'rack.url_scheme' => 'http'
}
)
io = StringIO.new
env['rack.hijack'] = proc {}
env['rack.hijack_io'] = io
Rubee::WebSocket.call(env)
io.rewind
handshake_response = io.read
assert_includes(handshake_response, "HTTP/1.1 101 Switching Protocols")
assert_includes(handshake_response, "Upgrade: websocket")
assert_includes(handshake_response, "Connection: Upgrade")
end
|