em-websocket 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,86 @@ shared_examples_for "a websocket server" do
29
29
  }
30
30
  end
31
31
 
32
+ it "should send messages successfully" do
33
+ em {
34
+ start_server { |ws|
35
+ ws.onmessage { |message|
36
+ message.should == "hello server"
37
+ done
38
+ }
39
+ }
40
+
41
+ start_client { |client|
42
+ client.onopen {
43
+ client.send("hello server")
44
+ }
45
+ }
46
+ }
47
+ end
48
+
49
+ it "should allow connection to be closed with valid close code" do
50
+ em {
51
+ start_server { |ws|
52
+ ws.onopen {
53
+ ws.close(4004, "Bye bye")
54
+ done
55
+ }
56
+ }
57
+
58
+ start_client
59
+ # TODO: Use a real client which understands how to respond to closing
60
+ # handshakes, sending the handshake currently untested
61
+ }
62
+ end
63
+
64
+ it "should raise error if if invalid close code is used" do
65
+ em {
66
+ start_server { |ws|
67
+ ws.onopen {
68
+ lambda {
69
+ ws.close(2000)
70
+ }.should raise_error("Application code may only use codes from 1000, 3000-4999")
71
+ done
72
+ }
73
+ }
74
+
75
+ start_client
76
+ }
77
+ end
78
+
79
+ it "should call onclose with was_clean set to false if connection closed without closing handshake by server" do
80
+ em {
81
+ start_server { |ws|
82
+ ws.onopen {
83
+ # Close tcp connection (no close handshake)
84
+ ws.close_connection
85
+ }
86
+ ws.onclose { |event|
87
+ event.should == {:code => 1006, :was_clean => false}
88
+ done
89
+ }
90
+ }
91
+ start_client
92
+ }
93
+ end
94
+
95
+ it "should call onclose with was_clean set to false if connection closed without closing handshake by client" do
96
+ em {
97
+ start_server { |ws|
98
+ ws.onclose { |event|
99
+ event.should == {:code => 1006, :was_clean => false}
100
+ done
101
+ }
102
+ }
103
+ start_client { |client|
104
+ client.onopen {
105
+ # Close tcp connection (no close handshake)
106
+ client.close_connection
107
+ }
108
+ }
109
+ }
110
+ end
111
+
32
112
  it "should call onerror if an application error raised in onopen" do
33
113
  em {
34
114
  start_server { |ws|
@@ -1,3 +1,5 @@
1
+ # encoding: BINARY
2
+
1
3
  require 'helper'
2
4
 
3
5
  describe EM::WebSocket::Framing03 do
@@ -265,7 +267,7 @@ describe EM::WebSocket::Framing07 do
265
267
  lambda {
266
268
  # Opcode 3 is not supported by this draft
267
269
  @f << "\x83\x05Hello"
268
- }.should raise_error(EventMachine::WebSocket::WSProtocolError, "Unknown opcode")
270
+ }.should raise_error(EventMachine::WebSocket::WSProtocolError, "Unknown opcode 3")
269
271
  end
270
272
 
271
273
  it "should accept a fragmented unmasked text message in 3 frames" do
@@ -23,5 +23,7 @@ describe EM::WebSocket::MaskedString do
23
23
  t.getbyte(4).should == 0x03
24
24
  t.read_mask
25
25
  t.getbyte(4).should == 0x01
26
+ t.unset_mask
27
+ t.getbyte(4).should == 0x03
26
28
  end
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-22 00:00:00.000000000 Z
13
+ date: 2013-03-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -198,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
198
  version: '0'
199
199
  segments:
200
200
  - 0
201
- hash: 3969961455966824026
201
+ hash: 3271699693430314189
202
202
  required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  none: false
204
204
  requirements:
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  version: '0'
208
208
  segments:
209
209
  - 0
210
- hash: 3969961455966824026
210
+ hash: 3271699693430314189
211
211
  requirements: []
212
212
  rubyforge_project: em-websocket
213
213
  rubygems_version: 1.8.24