websocket 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.travis.yml +2 -6
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile +2 -1
  4. data/README.md +10 -6
  5. data/Rakefile +1 -1
  6. data/lib/websocket.rb +1 -1
  7. data/lib/websocket/exception_handler.rb +6 -0
  8. data/lib/websocket/frame/base.rb +1 -1
  9. data/lib/websocket/frame/data.rb +11 -9
  10. data/lib/websocket/frame/handler.rb +1 -1
  11. data/lib/websocket/frame/handler/handler03.rb +17 -17
  12. data/lib/websocket/frame/handler/handler07.rb +8 -8
  13. data/lib/websocket/frame/handler/handler75.rb +8 -7
  14. data/lib/websocket/frame/incoming.rb +1 -1
  15. data/lib/websocket/frame/outgoing.rb +1 -1
  16. data/lib/websocket/handshake/base.rb +7 -7
  17. data/lib/websocket/handshake/client.rb +5 -3
  18. data/lib/websocket/handshake/handler/base.rb +5 -5
  19. data/lib/websocket/handshake/handler/client.rb +6 -1
  20. data/lib/websocket/handshake/handler/client04.rb +7 -6
  21. data/lib/websocket/handshake/handler/client75.rb +5 -4
  22. data/lib/websocket/handshake/handler/client76.rb +5 -5
  23. data/lib/websocket/handshake/handler/server04.rb +11 -6
  24. data/lib/websocket/handshake/handler/server75.rb +5 -5
  25. data/lib/websocket/handshake/handler/server76.rb +9 -9
  26. data/lib/websocket/handshake/server.rb +25 -24
  27. data/lib/websocket/version.rb +1 -1
  28. data/spec/frame/incoming_03_spec.rb +25 -25
  29. data/spec/frame/incoming_04_spec.rb +25 -25
  30. data/spec/frame/incoming_05_spec.rb +29 -29
  31. data/spec/frame/incoming_07_spec.rb +31 -31
  32. data/spec/frame/incoming_75_spec.rb +13 -13
  33. data/spec/frame/incoming_common_spec.rb +12 -13
  34. data/spec/frame/masking_spec.rb +10 -10
  35. data/spec/frame/outgoing_03_spec.rb +17 -17
  36. data/spec/frame/outgoing_04_spec.rb +17 -17
  37. data/spec/frame/outgoing_05_spec.rb +17 -17
  38. data/spec/frame/outgoing_07_spec.rb +19 -19
  39. data/spec/frame/outgoing_75_spec.rb +9 -9
  40. data/spec/frame/outgoing_common_spec.rb +7 -8
  41. data/spec/handshake/client_04_spec.rb +9 -9
  42. data/spec/handshake/client_75_spec.rb +2 -2
  43. data/spec/handshake/client_76_spec.rb +9 -9
  44. data/spec/handshake/server_04_spec.rb +5 -5
  45. data/spec/handshake/server_75_spec.rb +1 -1
  46. data/spec/handshake/server_76_spec.rb +21 -21
  47. data/spec/spec_helper.rb +4 -1
  48. data/spec/support/all_client_drafts.rb +62 -52
  49. data/spec/support/all_server_drafts.rb +49 -49
  50. data/spec/support/handshake_requests.rb +16 -16
  51. data/spec/support/incoming_frames.rb +28 -28
  52. data/spec/support/outgoing_frames.rb +10 -10
  53. data/websocket.gemspec +1 -1
  54. metadata +42 -22
  55. checksums.yaml +0 -7
@@ -1,10 +1,10 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Outgoing frame draft 75' do
4
+ RSpec.describe 'Outgoing frame draft 75' do
5
5
  let(:version) { 75 }
6
- let(:frame) { WebSocket::Frame::Outgoing.new(:version => version, :data => decoded_text, :type => frame_type) }
7
- let(:decoded_text) { "" }
6
+ let(:frame) { WebSocket::Frame::Outgoing.new(version: version, data: decoded_text, type: frame_type) }
7
+ let(:decoded_text) { '' }
8
8
  let(:encoded_text) { "\x00\xFF" }
9
9
  let(:frame_type) { :text }
10
10
  let(:require_sending) { true }
@@ -13,26 +13,26 @@ describe 'Outgoing frame draft 75' do
13
13
 
14
14
  it_should_behave_like 'valid_outgoing_frame'
15
15
 
16
- context "should properly encode text frame" do
17
- let(:decoded_text) { "abc" }
16
+ context 'should properly encode text frame' do
17
+ let(:decoded_text) { 'abc' }
18
18
  let(:encoded_text) { "\x00abc\xFF" }
19
19
  let(:require_sending) { true }
20
20
 
21
21
  it_should_behave_like 'valid_outgoing_frame'
22
22
  end
23
23
 
24
- context "should properly encode close frame" do
24
+ context 'should properly encode close frame' do
25
25
  let(:frame_type) { :close }
26
- let(:decoded_text) { "abc" }
26
+ let(:decoded_text) { 'abc' }
27
27
  let(:encoded_text) { "\xFF\x00" }
28
28
  let(:require_sending) { true }
29
29
 
30
30
  it_should_behave_like 'valid_outgoing_frame'
31
31
  end
32
32
 
33
- context "should return error for unknown frame type" do
33
+ context 'should return error for unknown frame type' do
34
34
  let(:frame_type) { :unknown }
35
- let(:decoded_text) { "Hello" }
35
+ let(:decoded_text) { 'Hello' }
36
36
  let(:encoded_text) { nil }
37
37
  let(:error) { :unknown_frame_type }
38
38
  let(:require_sending) { false }
@@ -1,16 +1,15 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe 'Outgoing common frame' do
4
+ RSpec.describe 'Outgoing common frame' do
5
5
  subject { WebSocket::Frame::Outgoing.new }
6
6
 
7
- its(:version) { should eql(13) }
8
- # Not implemented yet
9
- # its(:error?) { should be_false }
7
+ its(:version) { is_expected.to eql(13) }
8
+ its(:error?) { is_expected.to be false }
10
9
 
11
- it "should raise error on invalid version" do
12
- subject = WebSocket::Frame::Incoming.new(:version => 70)
13
- subject.error?.should be_true
14
- subject.error.should eql(:unknown_protocol_version)
10
+ it 'should raise error on invalid version' do
11
+ subject = WebSocket::Frame::Incoming.new(version: 70)
12
+ expect(subject.error?).to be true
13
+ expect(subject.error).to eql(:unknown_protocol_version)
15
14
  end
16
15
  end
@@ -1,20 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Client draft 4 handshake' do
4
- let(:handshake) { WebSocket::Handshake::Client.new({ :uri => 'ws://example.com/demo', :origin => 'http://example.com', :version => version }.merge(@request_params || {})) }
3
+ RSpec.describe 'Client draft 4 handshake' do
4
+ let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
5
5
 
6
6
  let(:version) { 4 }
7
- let(:client_request) { client_handshake_04({ :key => handshake.handler.send(:key), :version => version }.merge(@request_params || {})) }
8
- let(:server_response) { server_handshake_04({ :accept => handshake.handler.send(:accept) }.merge(@request_params || {})) }
7
+ let(:client_request) { client_handshake_04({ key: handshake.handler.send(:key), version: version }.merge(@request_params || {})) }
8
+ let(:server_response) { server_handshake_04({ accept: handshake.handler.send(:accept) }.merge(@request_params || {})) }
9
9
 
10
10
  it_should_behave_like 'all client drafts'
11
11
 
12
- it "should disallow client with invalid challenge" do
13
- @request_params = { :accept => "invalid" }
12
+ it 'should disallow client with invalid challenge' do
13
+ @request_params = { accept: 'invalid' }
14
14
  handshake << server_response
15
15
 
16
- handshake.should be_finished
17
- handshake.should_not be_valid
18
- handshake.error.should eql(:invalid_handshake_authentication)
16
+ expect(handshake).to be_finished
17
+ expect(handshake).not_to be_valid
18
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Client draft 75 handshake' do
4
- let(:handshake) { WebSocket::Handshake::Client.new({ :uri => 'ws://example.com/demo', :origin => 'http://example.com', :version => version }.merge(@request_params || {})) }
3
+ RSpec.describe 'Client draft 75 handshake' do
4
+ let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
5
5
 
6
6
  let(:version) { 75 }
7
7
  let(:client_request) { client_handshake_75(@request_params || {}) }
@@ -1,20 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Client draft 76 handshake' do
4
- let(:handshake) { WebSocket::Handshake::Client.new({ :uri => 'ws://example.com/demo', :origin => 'http://example.com', :version => version }.merge(@request_params || {})) }
3
+ RSpec.describe 'Client draft 76 handshake' do
4
+ let(:handshake) { WebSocket::Handshake::Client.new({ uri: 'ws://example.com/demo', origin: 'http://example.com', version: version }.merge(@request_params || {})) }
5
5
 
6
6
  let(:version) { 76 }
7
- let(:client_request) { client_handshake_76({ :key1 => handshake.handler.send(:key1), :key2 => handshake.handler.send(:key2), :key3 => handshake.handler.send(:key3) }.merge(@request_params || {})) }
8
- let(:server_response) { server_handshake_76({ :challenge => handshake.handler.send(:challenge) }.merge(@request_params || {})) }
7
+ let(:client_request) { client_handshake_76({ key1: handshake.handler.send(:key1), key2: handshake.handler.send(:key2), key3: handshake.handler.send(:key3) }.merge(@request_params || {})) }
8
+ let(:server_response) { server_handshake_76({ challenge: handshake.handler.send(:challenge) }.merge(@request_params || {})) }
9
9
 
10
10
  it_should_behave_like 'all client drafts'
11
11
 
12
- it "should disallow client with invalid challenge" do
13
- @request_params = { :challenge => "invalid" }
12
+ it 'should disallow client with invalid challenge' do
13
+ @request_params = { challenge: 'invalid' }
14
14
  handshake << server_response
15
15
 
16
- handshake.should be_finished
17
- handshake.should_not be_valid
18
- handshake.error.should eql(:invalid_handshake_authentication)
16
+ expect(handshake).to be_finished
17
+ expect(handshake).not_to be_valid
18
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Server draft 04 handshake' do
3
+ RSpec.describe 'Server draft 04 handshake' do
4
4
  let(:handshake) { WebSocket::Handshake::Server.new }
5
5
  let(:version) { 04 }
6
6
  let(:client_request) { client_handshake_04(@request_params || {}) }
@@ -8,11 +8,11 @@ describe 'Server draft 04 handshake' do
8
8
 
9
9
  it_should_behave_like 'all server drafts'
10
10
 
11
- it "should disallow request without Sec-WebSocket-Key" do
11
+ it 'should disallow request without Sec-WebSocket-Key' do
12
12
  handshake << client_request.gsub(/^Sec-WebSocket-Key:.*\n/, '')
13
13
 
14
- handshake.should be_finished
15
- handshake.should_not be_valid
16
- handshake.error.should eql(:invalid_handshake_authentication)
14
+ expect(handshake).to be_finished
15
+ expect(handshake).not_to be_valid
16
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
17
17
  end
18
18
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Server draft 75 handshake' do
3
+ RSpec.describe 'Server draft 75 handshake' do
4
4
  let(:handshake) { WebSocket::Handshake::Server.new }
5
5
 
6
6
  let(:version) { 75 }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Server draft 76 handshake' do
3
+ RSpec.describe 'Server draft 76 handshake' do
4
4
  let(:handshake) { WebSocket::Handshake::Server.new }
5
5
  let(:version) { 76 }
6
6
  let(:client_request) { client_handshake_76(@request_params || {}) }
@@ -8,39 +8,39 @@ describe 'Server draft 76 handshake' do
8
8
 
9
9
  it_should_behave_like 'all server drafts'
10
10
 
11
- it "should disallow request without spaces in key 1" do
12
- @request_params = { :key1 => "4@146546xW%0l15" }
11
+ it 'should disallow request without spaces in key 1' do
12
+ @request_params = { key1: '4@146546xW%0l15' }
13
13
  handshake << client_request
14
14
 
15
- handshake.should be_finished
16
- handshake.should_not be_valid
17
- handshake.error.should eql(:invalid_handshake_authentication)
15
+ expect(handshake).to be_finished
16
+ expect(handshake).not_to be_valid
17
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
18
18
  end
19
19
 
20
- it "should disallow request without spaces in key 2" do
21
- @request_params = { :key2 => "129985Y31.P00" }
20
+ it 'should disallow request without spaces in key 2' do
21
+ @request_params = { key2: '129985Y31.P00' }
22
22
  handshake << client_request
23
23
 
24
- handshake.should be_finished
25
- handshake.should_not be_valid
26
- handshake.error.should eql(:invalid_handshake_authentication)
24
+ expect(handshake).to be_finished
25
+ expect(handshake).not_to be_valid
26
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
27
27
  end
28
28
 
29
- it "should disallow request with invalid number of spaces or numbers in key 1" do
30
- @request_params = { :key1 => "4 @1 46546xW%0l 1 5" }
29
+ it 'should disallow request with invalid number of spaces or numbers in key 1' do
30
+ @request_params = { key1: '4 @1 46546xW%0l 1 5' }
31
31
  handshake << client_request
32
32
 
33
- handshake.should be_finished
34
- handshake.should_not be_valid
35
- handshake.error.should eql(:invalid_handshake_authentication)
33
+ expect(handshake).to be_finished
34
+ expect(handshake).not_to be_valid
35
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
36
36
  end
37
37
 
38
- it "should disallow request with invalid number of spaces or numbers in key 2" do
39
- @request_params = { :key2 => "12998 5 Y3 1 .P00" }
38
+ it 'should disallow request with invalid number of spaces or numbers in key 2' do
39
+ @request_params = { key2: '12998 5 Y3 1 .P00' }
40
40
  handshake << client_request
41
41
 
42
- handshake.should be_finished
43
- handshake.should_not be_valid
44
- handshake.error.should eql(:invalid_handshake_authentication)
42
+ expect(handshake).to be_finished
43
+ expect(handshake).not_to be_valid
44
+ expect(handshake.error).to eql(:invalid_handshake_authentication)
45
45
  end
46
46
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'rspec'
2
+ require 'rspec/its'
2
3
  require 'webrick'
3
4
 
4
5
  require 'websocket'
5
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
6
7
 
7
8
  RSpec.configure do |config|
9
+ config.disable_monkey_patching!
10
+
8
11
  config.before(:suite) do
9
12
  WebSocket.max_frame_size = 100 * 1024 # 100kb
10
13
  end
@@ -1,98 +1,108 @@
1
- shared_examples_for 'all client drafts' do
1
+ RSpec.shared_examples_for 'all client drafts' do
2
2
  def validate_request
3
- handshake.to_s.should eql(client_request)
3
+ expect(handshake.to_s).to eql(client_request)
4
4
 
5
5
  handshake << server_response
6
6
 
7
- handshake.error.should be_nil
8
- handshake.should be_finished
9
- handshake.should be_valid
7
+ expect(handshake.error).to be_nil
8
+ expect(handshake).to be_finished
9
+ expect(handshake).to be_valid
10
10
  end
11
11
 
12
- it "should be valid" do
12
+ it 'should be valid' do
13
13
  handshake << server_response
14
14
 
15
- handshake.error.should be_nil
16
- handshake.should be_finished
17
- handshake.should be_valid
15
+ expect(handshake.error).to be_nil
16
+ expect(handshake).to be_finished
17
+ expect(handshake).to be_valid
18
18
  end
19
19
 
20
- it "should return valid version" do
21
- handshake.version.should eql(version)
20
+ it 'should return valid version' do
21
+ expect(handshake.version).to eql(version)
22
22
  end
23
23
 
24
- it "should return valid host" do
25
- @request_params = { :host => "www.test.cc" }
26
- handshake.host.should eql('www.test.cc')
24
+ it 'should return valid host' do
25
+ @request_params = { host: 'www.test.cc' }
26
+ expect(handshake.host).to eql('www.test.cc')
27
27
  end
28
28
 
29
- it "should return valid path" do
30
- @request_params = { :path => "/custom" }
31
- handshake.path.should eql('/custom')
29
+ it 'should return valid path' do
30
+ @request_params = { path: '/custom' }
31
+ expect(handshake.path).to eql('/custom')
32
32
  end
33
33
 
34
- it "should return valid query" do
35
- @request_params = { :query => "aaa=bbb" }
36
- handshake.query.should eql("aaa=bbb")
34
+ it 'should return valid query' do
35
+ @request_params = { query: 'aaa=bbb' }
36
+ expect(handshake.query).to eql('aaa=bbb')
37
37
  end
38
38
 
39
- it "should return valid port" do
40
- @request_params = { :port => 123 }
41
- handshake.port.should eql(123)
39
+ it 'should return valid port' do
40
+ @request_params = { port: 123 }
41
+ expect(handshake.port).to eql(123)
42
42
  end
43
43
 
44
- it "should parse uri" do
45
- @request_params = { :uri => "ws://test.example.org:301/test_path?query=true" }
46
- handshake.host.should eql('test.example.org')
47
- handshake.port.should eql(301)
48
- handshake.path.should eql('/test_path')
49
- handshake.query.should eql('query=true')
44
+ it 'should return valid headers' do
45
+ @request_params = { headers: { 'aaa' => 'bbb' } }
46
+ expect(handshake.headers).to eql({ 'aaa' => 'bbb' })
50
47
  end
51
48
 
52
- it "should parse url" do
53
- @request_params = { :url => "ws://test.example.org:301/test_path?query=true" }
54
- handshake.host.should eql('test.example.org')
55
- handshake.port.should eql(301)
56
- handshake.path.should eql('/test_path')
57
- handshake.query.should eql('query=true')
49
+ it 'should parse uri' do
50
+ @request_params = { uri: 'ws://test.example.org:301/test_path?query=true' }
51
+ expect(handshake.host).to eql('test.example.org')
52
+ expect(handshake.port).to eql(301)
53
+ expect(handshake.path).to eql('/test_path')
54
+ expect(handshake.query).to eql('query=true')
58
55
  end
59
56
 
60
- it "should resolve correct path with root server provided" do
61
- @request_params = { :url => "ws://test.example.org" }
62
- handshake.path.should eql('/')
57
+ it 'should parse url' do
58
+ @request_params = { url: 'ws://test.example.org:301/test_path?query=true' }
59
+ expect(handshake.host).to eql('test.example.org')
60
+ expect(handshake.port).to eql(301)
61
+ expect(handshake.path).to eql('/test_path')
62
+ expect(handshake.query).to eql('query=true')
63
63
  end
64
64
 
65
- it "should return valid response" do
65
+ it 'should resolve correct path with root server provided' do
66
+ @request_params = { url: 'ws://test.example.org' }
67
+ expect(handshake.path).to eql('/')
68
+ end
69
+
70
+ it 'should return valid response' do
71
+ validate_request
72
+ end
73
+
74
+ it 'should allow custom path' do
75
+ @request_params = { path: '/custom' }
66
76
  validate_request
67
77
  end
68
78
 
69
- it "should allow custom path" do
70
- @request_params = { :path => "/custom" }
79
+ it 'should allow query in path' do
80
+ @request_params = { query: 'test=true' }
71
81
  validate_request
72
82
  end
73
83
 
74
- it "should allow query in path" do
75
- @request_params = { :query => "test=true" }
84
+ it 'should allow custom port' do
85
+ @request_params = { port: 123 }
76
86
  validate_request
77
87
  end
78
88
 
79
- it "should allow custom port" do
80
- @request_params = { :port => 123 }
89
+ it 'should allow custom headers' do
90
+ @request_params = { headers: { 'aaa' => 'bbb' } }
81
91
  validate_request
82
92
  end
83
93
 
84
- it "should recognize unfinished requests" do
94
+ it 'should recognize unfinished requests' do
85
95
  handshake << server_response[0..-20]
86
96
 
87
- handshake.should_not be_finished
88
- handshake.should_not be_valid
97
+ expect(handshake).not_to be_finished
98
+ expect(handshake).not_to be_valid
89
99
  end
90
100
 
91
- it "should disallow requests with invalid request method" do
101
+ it 'should disallow requests with invalid request method' do
92
102
  handshake << server_response.gsub('101', '404')
93
103
 
94
- handshake.should be_finished
95
- handshake.should_not be_valid
96
- handshake.error.should eql(:invalid_status_code)
104
+ expect(handshake).to be_finished
105
+ expect(handshake).not_to be_valid
106
+ expect(handshake.error).to eql(:invalid_status_code)
97
107
  end
98
108
  end
@@ -1,117 +1,117 @@
1
- shared_examples_for 'all server drafts' do
1
+ RSpec.shared_examples_for 'all server drafts' do
2
2
  def validate_request
3
3
  handshake << client_request
4
4
 
5
- handshake.error.should be_nil
6
- handshake.should be_finished
7
- handshake.should be_valid
8
- handshake.to_s.should eql(server_response)
5
+ expect(handshake.error).to be_nil
6
+ expect(handshake).to be_finished
7
+ expect(handshake).to be_valid
8
+ expect(handshake.to_s).to eql(server_response)
9
9
  end
10
10
 
11
- it "should be valid" do
11
+ it 'should be valid' do
12
12
  handshake << client_request
13
13
 
14
- handshake.error.should be_nil
15
- handshake.should be_finished
16
- handshake.should be_valid
14
+ expect(handshake.error).to be_nil
15
+ expect(handshake).to be_finished
16
+ expect(handshake).to be_valid
17
17
  end
18
18
 
19
- it "should return valid version" do
19
+ it 'should return valid version' do
20
20
  handshake << client_request
21
21
 
22
- handshake.version.should eql(version)
22
+ expect(handshake.version).to eql(version)
23
23
  end
24
24
 
25
- it "should return valid host" do
26
- @request_params = { :host => "www.test.cc" }
25
+ it 'should return valid host' do
26
+ @request_params = { host: 'www.test.cc' }
27
27
  handshake << client_request
28
28
 
29
- handshake.host.should eql('www.test.cc')
29
+ expect(handshake.host).to eql('www.test.cc')
30
30
  end
31
31
 
32
- it "should return valid path" do
33
- @request_params = { :path => "/custom" }
32
+ it 'should return valid path' do
33
+ @request_params = { path: '/custom' }
34
34
  handshake << client_request
35
35
 
36
- handshake.path.should eql('/custom')
36
+ expect(handshake.path).to eql('/custom')
37
37
  end
38
38
 
39
- it "should return valid query" do
40
- @request_params = { :path => "/custom?aaa=bbb" }
39
+ it 'should return valid query' do
40
+ @request_params = { path: '/custom?aaa=bbb' }
41
41
  handshake << client_request
42
42
 
43
- handshake.query.should eql('aaa=bbb')
43
+ expect(handshake.query).to eql('aaa=bbb')
44
44
  end
45
45
 
46
- it "should return valid port" do
47
- @request_params = { :port => 123 }
46
+ it 'should return valid port' do
47
+ @request_params = { port: 123 }
48
48
  handshake << client_request
49
49
 
50
- handshake.port.should eql("123")
50
+ expect(handshake.port).to eql('123')
51
51
  end
52
52
 
53
- it "should return valid response" do
53
+ it 'should return valid response' do
54
54
  validate_request
55
55
  end
56
56
 
57
- it "should allow custom path" do
58
- @request_params = { :path => "/custom" }
57
+ it 'should allow custom path' do
58
+ @request_params = { path: '/custom' }
59
59
  validate_request
60
60
  end
61
61
 
62
- it "should allow query in path" do
63
- @request_params = { :path => "/custom?test=true" }
62
+ it 'should allow query in path' do
63
+ @request_params = { path: '/custom?test=true' }
64
64
  validate_request
65
65
  end
66
66
 
67
- it "should allow custom port" do
68
- @request_params = { :port => 123 }
67
+ it 'should allow custom port' do
68
+ @request_params = { port: 123 }
69
69
  validate_request
70
70
  end
71
71
 
72
- it "should recognize unfinished requests" do
72
+ it 'should recognize unfinished requests' do
73
73
  handshake << client_request[0..-10]
74
74
 
75
- handshake.should_not be_finished
76
- handshake.should_not be_valid
75
+ expect(handshake).not_to be_finished
76
+ expect(handshake).not_to be_valid
77
77
  end
78
78
 
79
- it "should disallow requests with invalid request method" do
79
+ it 'should disallow requests with invalid request method' do
80
80
  handshake << client_request.gsub('GET', 'POST')
81
81
 
82
- handshake.should be_finished
83
- handshake.should_not be_valid
84
- handshake.error.should eql(:get_request_required)
82
+ expect(handshake).to be_finished
83
+ expect(handshake).not_to be_valid
84
+ expect(handshake.error).to eql(:get_request_required)
85
85
  end
86
86
 
87
- it "should parse a rack request" do
88
- request = WEBrick::HTTPRequest.new( :ServerSoftware => "rspec" )
89
- request.parse(StringIO.new(client_request)).should be_true
87
+ it 'should parse a rack request' do
88
+ request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
89
+ expect(request.parse(StringIO.new(client_request))).to be true
90
90
  rest = client_request.slice((request.to_s.length..-1))
91
91
 
92
92
  handshake.from_rack(request.meta_vars.merge(
93
- "rack.input" => StringIO.new(rest)
93
+ 'rack.input' => StringIO.new(rest)
94
94
  ))
95
95
  validate_request
96
96
  end
97
97
 
98
- it "should parse a hash request" do
99
- request = WEBrick::HTTPRequest.new( :ServerSoftware => "rspec" )
100
- request.parse(StringIO.new(client_request)).should be_true
98
+ it 'should parse a hash request' do
99
+ request = WEBrick::HTTPRequest.new(ServerSoftware: 'rspec')
100
+ expect(request.parse(StringIO.new(client_request))).to be true
101
101
  body = client_request.slice((request.to_s.length..-1))
102
102
 
103
103
  path = request.path
104
104
  query = request.query_string
105
- headers = request.header.inject({}) do |hash, header|
105
+ headers = request.header.reduce({}) do |hash, header|
106
106
  hash[header[0]] = header[1].first if header[0] && header[1]
107
107
  hash
108
108
  end
109
109
 
110
110
  handshake.from_hash({
111
- :headers => headers,
112
- :path => path,
113
- :query => query,
114
- :body => body
111
+ headers: headers,
112
+ path: path,
113
+ query: query,
114
+ body: body
115
115
  })
116
116
 
117
117
  validate_request