1 2 3 4 5 6 7 8 9 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
# frozen_string_literal: true
RSpec.shared_examples_for 'all client drafts' do
def validate_request
expect(handshake.to_s).to eql(client_request)
handshake << server_response
expect(handshake.error).to be_nil
expect(handshake).to be_finished
expect(handshake).to be_valid
end
it 'is valid' do
handshake << server_response
expect(handshake.error).to be_nil
expect(handshake).to be_finished
expect(handshake).to be_valid
end
it 'returns valid version' do
expect(handshake.version).to eql(version)
end
it 'returns valid host' do
@request_params = { host: 'www.test.cc' }
expect(handshake.host).to eql('www.test.cc')
end
it 'returns valid path' do
@request_params = { path: '/custom' }
expect(handshake.path).to eql('/custom')
end
it 'returns valid query' do
@request_params = { query: 'aaa=bbb' }
expect(handshake.query).to eql('aaa=bbb')
end
it 'returns default port' do
expect(handshake.port).to be(80)
end
it 'returns valid port' do
@request_params = { port: 123 }
expect(handshake.port).to be(123)
end
it 'returns valid headers' do
@request_params = { headers: { 'aaa' => 'bbb' } }
expect(handshake.headers).to eql('aaa' => 'bbb')
end
it 'parses uri' do
@request_params = { uri: 'ws://test.example.org:301/test_path?query=true' }
expect(handshake.host).to eql('test.example.org')
expect(handshake.port).to be(301)
expect(handshake.path).to eql('/test_path')
expect(handshake.query).to eql('query=true')
end
it 'parses url' do
@request_params = { url: 'ws://test.example.org:301/test_path?query=true' }
expect(handshake.host).to eql('test.example.org')
expect(handshake.port).to be(301)
expect(handshake.path).to eql('/test_path')
expect(handshake.query).to eql('query=true')
end
it 'resolves correct path with root server provided' do
@request_params = { url: 'ws://test.example.org' }
expect(handshake.path).to eql('/')
end
it 'returns valid response' do
validate_request
end
it 'allows custom path' do
@request_params = { path: '/custom' }
validate_request
end
it 'allows query in path' do
@request_params = { query: 'test=true' }
validate_request
end
it 'allows custom port' do
@request_params = { port: 123 }
validate_request
end
it 'allows custom headers' do
@request_params = { headers: { 'aaa' => 'bbb' } }
validate_request
end
it 'recognizes unfinished requests' do
handshake << server_response[0..-20]
expect(handshake).not_to be_finished
expect(handshake).not_to be_valid
end
it 'disallows requests with invalid request method' do
handshake << server_response.gsub('101', '404')
expect(handshake).to be_finished
expect(handshake).not_to be_valid
expect(handshake.error).to be(:invalid_status_code)
end
end
|