Class: UsersControllerTest

Inherits:
Minitest::Test
  • Object
show all
Includes:
Rack::Test::Methods
Defined in:
lib/tests/controllers/users_controller_test.rb

Instance Method Summary collapse

Instance Method Details

#appObject



6
7
8
# File 'lib/tests/controllers/users_controller_test.rb', line 6

def app
  Rubee::Application.instance
end

#test_websocket_handshake_written_to_ioObject



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'
    }
  )

  # Mock hijack interface expected by Rubee::WebSocket
  io = StringIO.new
  env['rack.hijack'] = proc {}
  env['rack.hijack_io'] = io

  # Call the WebSocket handler
  Rubee::WebSocket.call(env)

  # Expect the handshake response written to IO
  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