simple-websocket-vcr 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +3 -1
- data/lib/simple_websocket_vcr/cassette.rb +2 -1
- data/lib/simple_websocket_vcr/recordable_websocket_client.rb +35 -18
- data/lib/simple_websocket_vcr/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette_should_be_re-recorded.yml +7 -1
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_json_cassette.json +8 -2
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_yaml_cassette.yml +7 -1
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_other_template.yml +2 -0
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_template.json +3 -1
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_template.yml +3 -0
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_also_the_outgoing_communication.yml +4 -0
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(json).json +4 -2
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(yaml).yml +3 -1
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_very_first_message_caught_on_the_client_yielded_by_the_connect_method.yml +1 -0
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/when_server_closes_connection_works.yml +34 -0
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/with_multiple_kinds_of_events_works.yml +36 -0
- data/spec/vcr_spec.rb +71 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3647e6aa28e20c2c4f4a2a77d8b4fe217a25efaaea2db8d23cd68ab700765fde
|
4
|
+
data.tar.gz: ee99fd6d3cbabf1972202163345ac3675cb69bdd45458db1bbf0a6fe2c89b854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b0f687df578c80f9e79c5cc1e83c864bf7651b419b1f621abf55dfe44d7ffbf02863c5efa0149cb4fa6ba199087f43a8c3666775c4d5ac7b3e58362abf0d05e
|
7
|
+
data.tar.gz: 5614945f3bec587644a69ed07c425b4a22c55c2aa99831b16fdb5a54d70a45d3fe3f2b1bd3a8b6e3c78fdd1931cc84b176781f3d1821171f53b9736a7da1667b
|
data/README.md
CHANGED
@@ -6,4 +6,6 @@
|
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/simple-websocket-vcr.svg)](https://badge.fury.io/rb/simple-websocket-vcr)
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
Based on the idea of [vcr](https://github.com/vcr/vcr) project which record the http interactions and store them as files that can be replayed later and simulate the real communication counterpart (mostly server).
|
10
|
+
|
11
|
+
However, this projects aims on the web socket protocol where normally there is only a single HTTP connection and multiple messages or frames being sent over the channel.
|
@@ -121,11 +121,12 @@ module WebSocketVCR
|
|
121
121
|
end
|
122
122
|
|
123
123
|
class RecordEntry
|
124
|
-
attr_accessor :operation, :type, :data
|
124
|
+
attr_accessor :operation, :event, :type, :data
|
125
125
|
|
126
126
|
def self.parse(obj, erb_variables = nil)
|
127
127
|
record_entry = RecordEntry.new
|
128
128
|
record_entry.operation = obj['operation']
|
129
|
+
record_entry.event = obj['event'] if obj['event']
|
129
130
|
record_entry.type = obj['type'] if obj['type']
|
130
131
|
record_entry.data = obj['data'] if obj['data']
|
131
132
|
|
@@ -35,7 +35,7 @@ module WebSocketVCR
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def emit(event, *data)
|
38
|
-
@session.store(operation: 'read', data: data) if @live
|
38
|
+
@session.store(operation: 'read', event: event, data: data) if @live
|
39
39
|
super(event, *data)
|
40
40
|
end
|
41
41
|
|
@@ -49,12 +49,15 @@ module WebSocketVCR
|
|
49
49
|
|
50
50
|
def close
|
51
51
|
if @live
|
52
|
-
@session.store(operation: 'close')
|
52
|
+
@session.store(operation: 'write', event: 'close')
|
53
53
|
@client.close
|
54
54
|
else
|
55
|
-
sleep 0.5 if @session.head.
|
56
|
-
|
57
|
-
|
55
|
+
sleep 0.5 if @session.head && @session.head.event != 'close'
|
56
|
+
@session.record_entries.size.times do
|
57
|
+
record = @session.next
|
58
|
+
_ensure_event('close', record.event)
|
59
|
+
emit(record.event, record.data) if record.operation == 'read'
|
60
|
+
end
|
58
61
|
Thread.kill @thread if @thread
|
59
62
|
@open = false
|
60
63
|
end
|
@@ -66,7 +69,7 @@ module WebSocketVCR
|
|
66
69
|
text_data = opt[:type] == :text ? data.dup : Base64.encode64(data.dup)
|
67
70
|
if @live
|
68
71
|
@client.__send__(method, data, opt)
|
69
|
-
@session.store(operation: 'write', data: text_data)
|
72
|
+
@session.store(operation: 'write', event: method, data: text_data)
|
70
73
|
else
|
71
74
|
sleep 0.5 if @session.head.operation != 'write'
|
72
75
|
record = @session.next
|
@@ -79,16 +82,20 @@ module WebSocketVCR
|
|
79
82
|
if @live
|
80
83
|
rec = @session
|
81
84
|
@client.on(event, params) do |msg|
|
82
|
-
|
83
|
-
|
85
|
+
params = { operation: 'read', event: event }
|
86
|
+
unless msg.nil?
|
87
|
+
data = msg.type.to_s == 'text' ? msg.data : Base64.encode64(msg.data)
|
88
|
+
params.merge!(type: msg.type, data: data)
|
89
|
+
end
|
90
|
+
rec.store(params)
|
84
91
|
yield(msg)
|
85
92
|
end
|
86
93
|
else
|
87
|
-
wait_for_reads
|
94
|
+
wait_for_reads unless @thread && @thread.alive?
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
91
|
-
def wait_for_reads
|
98
|
+
def wait_for_reads
|
92
99
|
@thread = Thread.new do
|
93
100
|
# if the next recorded operation is a 'read', take all the reads until next write
|
94
101
|
# and translate them to the events
|
@@ -96,15 +103,8 @@ module WebSocketVCR
|
|
96
103
|
begin
|
97
104
|
if @session.head.operation == 'read'
|
98
105
|
record = @session.next
|
99
|
-
data = record.data
|
100
|
-
data = Base64.decode64(data) if record.type != 'text'
|
101
|
-
data = ::WebSocket::Frame::Data.new(data)
|
102
106
|
|
103
|
-
|
104
|
-
self
|
105
|
-
end
|
106
|
-
|
107
|
-
emit(event, data)
|
107
|
+
emit(record.event, parse_data(record))
|
108
108
|
break if __events.empty?
|
109
109
|
else
|
110
110
|
sleep 0.1 # TODO: config
|
@@ -114,6 +114,18 @@ module WebSocketVCR
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
def parse_data(record)
|
118
|
+
if (data = record.data)
|
119
|
+
data = Base64.decode64(data) if record.type != 'text'
|
120
|
+
data = ::WebSocket::Frame::Data.new(data)
|
121
|
+
|
122
|
+
def data.data
|
123
|
+
self
|
124
|
+
end
|
125
|
+
end
|
126
|
+
data
|
127
|
+
end
|
128
|
+
|
117
129
|
def _take_first_read
|
118
130
|
@session.delete_at(@session.index { |record| record.operation == 'read' } || @session.length)
|
119
131
|
end
|
@@ -123,6 +135,11 @@ module WebSocketVCR
|
|
123
135
|
fail string unless desired == actual
|
124
136
|
end
|
125
137
|
|
138
|
+
def _ensure_event(desired, actual)
|
139
|
+
string = "Expected to '#{desired}' but the next event in recording was '#{actual}'"
|
140
|
+
fail string unless desired == actual
|
141
|
+
end
|
142
|
+
|
126
143
|
def _ensure_data(desired, actual)
|
127
144
|
string = "Expected data to be '#{desired}' but next data in recording was '#{actual}'"
|
128
145
|
fail string unless desired == actual
|
@@ -1,11 +1,14 @@
|
|
1
1
|
---
|
2
2
|
websocket_interactions:
|
3
3
|
- - operation: read
|
4
|
+
event: message
|
4
5
|
type: text
|
5
6
|
data: WelcomeResponse={"sessionId":"_Q8LZN4jeyX27Qb2qjiz_3HR9Ckoa1S-pHMaJi9q"}
|
6
7
|
- operation: write
|
8
|
+
event: send
|
7
9
|
data: something_1
|
8
10
|
- operation: read
|
11
|
+
event: message
|
9
12
|
type: text
|
10
13
|
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
11
14
|
Cannot deserialize: [something_1]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
@@ -24,8 +27,10 @@ websocket_interactions:
|
|
24
27
|
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
25
28
|
java.lang.Thread.run(Thread.java:745)\n"}'
|
26
29
|
- operation: write
|
30
|
+
event: send
|
27
31
|
data: something_2
|
28
32
|
- operation: read
|
33
|
+
event: message
|
29
34
|
type: text
|
30
35
|
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
31
36
|
Cannot deserialize: [something_2]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
@@ -43,4 +48,5 @@ websocket_interactions:
|
|
43
48
|
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat
|
44
49
|
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
45
50
|
java.lang.Thread.run(Thread.java:745)\n"}'
|
46
|
-
- operation:
|
51
|
+
- operation: write
|
52
|
+
event: close
|
@@ -2,29 +2,35 @@
|
|
2
2
|
[
|
3
3
|
{
|
4
4
|
"operation": "read",
|
5
|
+
"event": "message",
|
5
6
|
"type": "text",
|
6
7
|
"data": "WelcomeResponse={\"sessionId\":\"6lLLtFyPAUmpeh3JiSUW3b1D1YN6FTLGHc2Yt8dI\"}"
|
7
8
|
},
|
8
9
|
{
|
9
10
|
"operation": "write",
|
11
|
+
"event": "send",
|
10
12
|
"data": "something_1"
|
11
13
|
},
|
12
14
|
{
|
13
15
|
"operation": "read",
|
16
|
+
"event": "message",
|
14
17
|
"type": "text",
|
15
18
|
"data": "GenericErrorResponse={\"errorMessage\":\"Failed to process message [?]\",\"stackTrace\":\"java.lang.IllegalArgumentException: Cannot deserialize: [something_1]\\n\\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\\n\\tat org.hawkular.cmdgw.api.ApiDeserializer.deserialize(ApiDeserializer.java:84)\\n\\tat org.hawkular.cmdgw.command.ws.server.AbstractGatewayWebSocket.onMessage(AbstractGatewayWebSocket.java:213)\\n\\tat sun.reflect.GeneratedMethodAccessor686.invoke(Unknown Source)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:497)\\n\\tat io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:87)\\n\\tat io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2$1.run(AnnotatedEndpoint.java:150)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\\n\\tat io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2.onMessage(AnnotatedEndpoint.java:145)\\n\\tat io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:283)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer$5.run(ServerWebSocketContainer.java:538)\\n\\tat io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:67)\\n\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\\n\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\\n\\tat java.lang.Thread.run(Thread.java:745)\\n\"}"
|
16
19
|
},
|
17
20
|
{
|
18
21
|
"operation": "write",
|
22
|
+
"event": "send",
|
19
23
|
"data": "something_2"
|
20
24
|
},
|
21
25
|
{
|
22
26
|
"operation": "read",
|
27
|
+
"event": "message",
|
23
28
|
"type": "text",
|
24
29
|
"data": "GenericErrorResponse={\"errorMessage\":\"Failed to process message [?]\",\"stackTrace\":\"java.lang.IllegalArgumentException: Cannot deserialize: [something_2]\\n\\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\\n\\tat org.hawkular.cmdgw.api.ApiDeserializer.deserialize(ApiDeserializer.java:84)\\n\\tat org.hawkular.cmdgw.command.ws.server.AbstractGatewayWebSocket.onMessage(AbstractGatewayWebSocket.java:213)\\n\\tat sun.reflect.GeneratedMethodAccessor686.invoke(Unknown Source)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:497)\\n\\tat io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:87)\\n\\tat io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2$1.run(AnnotatedEndpoint.java:150)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\\n\\tat io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2.onMessage(AnnotatedEndpoint.java:145)\\n\\tat io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:283)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\\n\\tat io.undertow.websockets.jsr.ServerWebSocketContainer$5.run(ServerWebSocketContainer.java:538)\\n\\tat io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:67)\\n\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\\n\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\\n\\tat java.lang.Thread.run(Thread.java:745)\\n\"}"
|
25
30
|
},
|
26
31
|
{
|
27
|
-
"operation": "
|
32
|
+
"operation": "write",
|
33
|
+
"event": "close"
|
28
34
|
}
|
29
35
|
]
|
30
|
-
]
|
36
|
+
]
|
@@ -1,11 +1,14 @@
|
|
1
1
|
---
|
2
2
|
websocket_interactions:
|
3
3
|
- - operation: read
|
4
|
+
event: message
|
4
5
|
type: text
|
5
6
|
data: WelcomeResponse={"sessionId":"<%= foobar %>"}
|
6
7
|
- operation: write
|
8
|
+
event: send
|
7
9
|
data: something_1
|
8
10
|
- operation: read
|
11
|
+
event: message
|
9
12
|
type: text
|
10
13
|
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
11
14
|
Cannot deserialize: [something_1]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
@@ -23,8 +26,10 @@ websocket_interactions:
|
|
23
26
|
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
24
27
|
java.lang.Thread.run(Thread.java:745)\n"}'
|
25
28
|
- operation: write
|
29
|
+
event: send
|
26
30
|
data: something_2
|
27
31
|
- operation: read
|
32
|
+
event: message
|
28
33
|
type: text
|
29
34
|
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
30
35
|
Cannot deserialize: [something_2]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
@@ -41,4 +46,5 @@ websocket_interactions:
|
|
41
46
|
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat
|
42
47
|
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
43
48
|
java.lang.Thread.run(Thread.java:745)\n"}'
|
44
|
-
- operation:
|
49
|
+
- operation: write
|
50
|
+
event: close
|
@@ -2,12 +2,14 @@
|
|
2
2
|
[
|
3
3
|
{
|
4
4
|
"operation": "read",
|
5
|
+
"event": "message",
|
5
6
|
"type": "text",
|
6
7
|
"data": "WelcomeResponse={\"<%= something %>\":\"I_XSiCb1wcQgARIzJ_jRU8k2-kPVblJuNCxhYBnb\"}"
|
7
8
|
},
|
8
9
|
{
|
9
10
|
"operation": "write",
|
11
|
+
"event": "send",
|
10
12
|
"data": "<%= bar %>"
|
11
13
|
}
|
12
14
|
]
|
13
|
-
]
|
15
|
+
]
|
@@ -1,11 +1,14 @@
|
|
1
1
|
---
|
2
2
|
websocket_interactions:
|
3
3
|
- - operation: read
|
4
|
+
event: message
|
4
5
|
type: text
|
5
6
|
data: WelcomeResponse={"<%= something %>":"KOrViCF_93axNx-WyGlhT6yktwqbJIl97mrxQXC5"}
|
6
7
|
- operation: write
|
8
|
+
event: send
|
7
9
|
data: something_1
|
8
10
|
- operation: read
|
11
|
+
event: message
|
9
12
|
type: text
|
10
13
|
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
11
14
|
Cannot deserialize: [something_1]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_also_the_outgoing_communication.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
---
|
2
2
|
websocket_interactions:
|
3
3
|
- - operation: read
|
4
|
+
event: message
|
4
5
|
type: text
|
5
6
|
data: WelcomeResponse={"sessionId":"XQVVtE53wxz1lmMsqz2TbmR68ilFzDxLOOpkKGpd"}
|
6
7
|
- operation: write
|
8
|
+
send: message
|
7
9
|
data: something 1
|
8
10
|
- operation: write
|
11
|
+
send: message
|
9
12
|
data: something 2
|
10
13
|
- operation: write
|
14
|
+
send: message
|
11
15
|
data: something 3
|
@@ -2,11 +2,13 @@
|
|
2
2
|
[
|
3
3
|
{
|
4
4
|
"operation": "read",
|
5
|
+
"event": "message",
|
5
6
|
"type": "text",
|
6
7
|
"data": "WelcomeResponse={\"sessionId\":\"rfynzN_MQHaFvhedHpqiQj1zFo0hBHsiICU4pmX-\"}"
|
7
8
|
},
|
8
9
|
{
|
9
|
-
"operation": "
|
10
|
+
"operation": "write",
|
11
|
+
"event": "close"
|
10
12
|
}
|
11
13
|
]
|
12
|
-
]
|
14
|
+
]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
websocket_interactions:
|
3
|
+
- - operation: read
|
4
|
+
event: open
|
5
|
+
- operation: write
|
6
|
+
event: send
|
7
|
+
data: hello
|
8
|
+
- operation: write
|
9
|
+
event: send
|
10
|
+
data: how
|
11
|
+
- operation: write
|
12
|
+
event: send
|
13
|
+
data: are
|
14
|
+
- operation: write
|
15
|
+
event: send
|
16
|
+
data: you
|
17
|
+
- operation: read
|
18
|
+
event: message
|
19
|
+
type: text
|
20
|
+
data: hello
|
21
|
+
- operation: read
|
22
|
+
event: message
|
23
|
+
type: text
|
24
|
+
data: how
|
25
|
+
- operation: read
|
26
|
+
event: message
|
27
|
+
type: text
|
28
|
+
data: are
|
29
|
+
- operation: read
|
30
|
+
event: message
|
31
|
+
type: text
|
32
|
+
data: you
|
33
|
+
- operation: read
|
34
|
+
event: close
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
websocket_interactions:
|
3
|
+
- - operation: read
|
4
|
+
event: open
|
5
|
+
- operation: write
|
6
|
+
event: send
|
7
|
+
data: hello
|
8
|
+
- operation: write
|
9
|
+
event: send
|
10
|
+
data: how
|
11
|
+
- operation: write
|
12
|
+
event: send
|
13
|
+
data: are
|
14
|
+
- operation: write
|
15
|
+
event: send
|
16
|
+
data: you
|
17
|
+
- operation: read
|
18
|
+
event: message
|
19
|
+
type: text
|
20
|
+
data: hello
|
21
|
+
- operation: read
|
22
|
+
event: message
|
23
|
+
type: text
|
24
|
+
data: how
|
25
|
+
- operation: read
|
26
|
+
event: message
|
27
|
+
type: text
|
28
|
+
data: are
|
29
|
+
- operation: read
|
30
|
+
event: message
|
31
|
+
type: text
|
32
|
+
data: you
|
33
|
+
- operation: write
|
34
|
+
event: close
|
35
|
+
- operation: read
|
36
|
+
event: close
|
data/spec/vcr_spec.rb
CHANGED
@@ -319,6 +319,76 @@ describe 'VCR for WS' do
|
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
322
|
+
describe 'with multiple kinds of events' do
|
323
|
+
it 'works' do
|
324
|
+
WebSocketVCR.configure do |c|
|
325
|
+
c.hook_uris = ['echo.websocket.org']
|
326
|
+
end
|
327
|
+
opened = false
|
328
|
+
messages = []
|
329
|
+
closed = false
|
330
|
+
WebSocketVCR.record(example, self) do
|
331
|
+
url = 'ws://echo.websocket.org'
|
332
|
+
c = WebSocket::Client::Simple.connect url do |client|
|
333
|
+
client.on(:open) do
|
334
|
+
opened = true
|
335
|
+
end
|
336
|
+
client.on(:message) do |event|
|
337
|
+
messages << event.data
|
338
|
+
end
|
339
|
+
client.on(:close) do
|
340
|
+
closed = true
|
341
|
+
end
|
342
|
+
end
|
343
|
+
sleep 5 if WebSocketVCR.live?
|
344
|
+
c.send('hello')
|
345
|
+
c.send('how')
|
346
|
+
c.send('are')
|
347
|
+
c.send('you')
|
348
|
+
sleep 20 if WebSocketVCR.live?
|
349
|
+
c.close
|
350
|
+
expect(c.open?).to be false
|
351
|
+
end
|
352
|
+
expect(opened).to eq(true)
|
353
|
+
expect(messages).to eq(%w(hello how are you))
|
354
|
+
expect(closed).to eq(true)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe 'when server closes the connection' do
|
359
|
+
it 'works' do
|
360
|
+
WebSocketVCR.configure do |c|
|
361
|
+
c.hook_uris = ['echo.websocket.org']
|
362
|
+
end
|
363
|
+
opened = false
|
364
|
+
messages = []
|
365
|
+
closed = false
|
366
|
+
cassette_path = 'VCR_for_WS/when_server_closes_connection_works'
|
367
|
+
WebSocketVCR.use_cassette(cassette_path) do
|
368
|
+
url = 'ws://echo.websocket.org'
|
369
|
+
c = WebSocket::Client::Simple.connect url do |client|
|
370
|
+
client.on(:open) do
|
371
|
+
opened = true
|
372
|
+
end
|
373
|
+
client.on(:message) do |event|
|
374
|
+
messages << event.data
|
375
|
+
end
|
376
|
+
client.on(:close) do
|
377
|
+
closed = true
|
378
|
+
end
|
379
|
+
end
|
380
|
+
c.send('hello')
|
381
|
+
c.send('how')
|
382
|
+
c.send('are')
|
383
|
+
c.send('you')
|
384
|
+
expect { c.close }.not_to raise_error
|
385
|
+
end
|
386
|
+
expect(opened).to eq(true)
|
387
|
+
expect(messages).to eq(%w(hello how are you))
|
388
|
+
expect(closed).to eq(true)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
322
392
|
describe 'version' do
|
323
393
|
it 'should return the major, minor and micro components correctly' do
|
324
394
|
expect(WebSocketVCR.version).to include(WebSocketVCR.version.major.to_s)
|
@@ -332,7 +402,7 @@ describe 'VCR for WS' do
|
|
332
402
|
expect(File.readlines(file_path).grep(/how/).size).to eq(2)
|
333
403
|
expect(File.readlines(file_path).grep(/are/).size).to eq(2)
|
334
404
|
expect(File.readlines(file_path).grep(/you/).size).to eq(2)
|
335
|
-
expect(File.readlines(file_path).grep(/write/).size).to eq(
|
405
|
+
expect(File.readlines(file_path).grep(/write/).size).to eq(5)
|
336
406
|
expect(File.readlines(file_path).grep(/read/).size).to eq(4)
|
337
407
|
expect(File.readlines(file_path).grep(/close/).size).to eq(1)
|
338
408
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-websocket-vcr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jirka Kremser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-client-simple
|
@@ -162,6 +162,8 @@ files:
|
|
162
162
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(json).json
|
163
163
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(yaml).yml
|
164
164
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_very_first_message_caught_on_the_client_yielded_by_the_connect_method.yml
|
165
|
+
- spec/fixtures/vcr_cassettes/VCR_for_WS/when_server_closes_connection_works.yml
|
166
|
+
- spec/fixtures/vcr_cassettes/VCR_for_WS/with_multiple_kinds_of_events_works.yml
|
165
167
|
- spec/spec_helper.rb
|
166
168
|
- spec/vcr_spec.rb
|
167
169
|
homepage: https://github.com/Jiri-Kremser/simple-websocket-vcr
|
@@ -184,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
186
|
version: '0'
|
185
187
|
requirements: []
|
186
188
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.6
|
189
|
+
rubygems_version: 2.7.6
|
188
190
|
signing_key:
|
189
191
|
specification_version: 4
|
190
192
|
summary: simple_websocket_vcr is VCR add-on for websockets.
|
@@ -204,5 +206,7 @@ test_files:
|
|
204
206
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(json).json
|
205
207
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event(yaml).yml
|
206
208
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_very_first_message_caught_on_the_client_yielded_by_the_connect_method.yml
|
209
|
+
- spec/fixtures/vcr_cassettes/VCR_for_WS/when_server_closes_connection_works.yml
|
210
|
+
- spec/fixtures/vcr_cassettes/VCR_for_WS/with_multiple_kinds_of_events_works.yml
|
207
211
|
- spec/spec_helper.rb
|
208
212
|
- spec/vcr_spec.rb
|