simple-websocket-vcr 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/{simple-websocket-vcr → simple_websocket_vcr}/cassette.rb +7 -8
- data/lib/{simple-websocket-vcr → simple_websocket_vcr}/configuration.rb +0 -0
- data/lib/{simple-websocket-vcr → simple_websocket_vcr}/errors.rb +0 -0
- data/lib/{simple-websocket-vcr → simple_websocket_vcr}/recordable_websocket_client.rb +16 -17
- data/lib/{simple-websocket-vcr → simple_websocket_vcr}/version.rb +1 -1
- data/lib/{simple-websocket-vcr.rb → simple_websocket_vcr.rb} +9 -9
- data/simple-websocket-vcr.gemspec +2 -2
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette.json +3 -3
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_also_the_outgoing_communication.json +1 -1
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_closing_event.json +1 -1
- data/spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_very_first_message_caught_on_the_client_yielded_by_the_connect_method.json +1 -1
- data/spec/vcr_spec.rb +1 -2
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b408bc5fa868fa39eadc1396ff489392afde72
|
4
|
+
data.tar.gz: 1efd70b10211a7b521670188ec85fbcedc6ff4fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fade33794fb192e477ede4ce59bf0d759faa5894ab4f84492bf188d22ebb0926d69976f0f27a4eddcbd86dbd7a5c10921238449ce55b25fbf28473187de4eb7
|
7
|
+
data.tar.gz: 9062c5a2735114ab8e76e6a0f80f16184bf1d4280abf9f442a577d6119b47ec2f20e5aa510a750024b8c28d187a40d2413f0ddc3869e87bc471d0063ffdc7dd9
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'simple_websocket_vcr/errors'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
module VCR
|
@@ -8,7 +8,7 @@ module VCR
|
|
8
8
|
class Cassette
|
9
9
|
attr_reader :name, :recording
|
10
10
|
|
11
|
-
|
11
|
+
alias_method :recording?, :recording
|
12
12
|
|
13
13
|
def initialize(name)
|
14
14
|
@name = name
|
@@ -28,17 +28,16 @@ module VCR
|
|
28
28
|
@sessions << []
|
29
29
|
@sessions.last
|
30
30
|
else
|
31
|
-
|
31
|
+
fail NoMoreSessionsError if @sessions.empty?
|
32
32
|
@sessions.shift
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def save
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
37
|
+
return unless recording?
|
38
|
+
dirname = File.dirname(filename)
|
39
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
40
|
+
File.open(filename, 'w') { |f| f.write(JSON.pretty_generate(@sessions)) }
|
42
41
|
end
|
43
42
|
|
44
43
|
protected
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
require 'websocket-client-simple'
|
3
3
|
require 'base64'
|
4
|
-
require '
|
4
|
+
require 'simple_websocket_vcr/errors'
|
5
5
|
|
6
6
|
module VCR
|
7
7
|
module WebSocket
|
@@ -14,7 +14,7 @@ module VCR
|
|
14
14
|
attr_accessor :recording, :open, :thread
|
15
15
|
|
16
16
|
def initialize(cassette, real_client)
|
17
|
-
|
17
|
+
fail NoCassetteError 'specify the cassette' unless cassette
|
18
18
|
|
19
19
|
if cassette.recording?
|
20
20
|
@live = true
|
@@ -26,15 +26,13 @@ module VCR
|
|
26
26
|
@recording = cassette.next_session
|
27
27
|
end
|
28
28
|
|
29
|
-
def send(
|
30
|
-
data = data_param.dup
|
31
|
-
data = Base64.encode64(data) if opt[:type] != :text
|
29
|
+
def send(data, opt = { type: :text })
|
32
30
|
_write(:send, data, opt)
|
33
31
|
end
|
34
32
|
|
35
33
|
def on(event, params = {}, &block)
|
36
34
|
super(event, params, &block) unless @live
|
37
|
-
_read(
|
35
|
+
_read(event, params, &block)
|
38
36
|
end
|
39
37
|
|
40
38
|
def emit(event, *data)
|
@@ -66,26 +64,26 @@ module VCR
|
|
66
64
|
private
|
67
65
|
|
68
66
|
def _write(method, data, opt)
|
67
|
+
text_data = opt[:type] == :text ? data.dup : Base64.encode64(data.dup)
|
69
68
|
if @live
|
70
69
|
@client.__send__(method, data, opt)
|
71
|
-
@recording << { operation: 'write', data:
|
70
|
+
@recording << { operation: 'write', data: text_data }
|
72
71
|
else
|
73
72
|
sleep 0.5 if @recording.first['operation'] != 'write'
|
74
73
|
record = @recording.shift
|
75
74
|
_ensure_operation('write', record['operation'])
|
76
|
-
_ensure_data(
|
75
|
+
_ensure_data(text_data, record['data'])
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
|
-
def _read(
|
79
|
+
def _read(event, params, &block)
|
81
80
|
if @live
|
82
81
|
rec = @recording
|
83
82
|
@client.on(event, params) do |msg|
|
84
|
-
|
85
|
-
rec << { operation: 'read', type: msg.type, data:
|
86
|
-
|
83
|
+
data = msg.type == :text ? msg.data : Base64.decode64(msg.data)
|
84
|
+
rec << { operation: 'read', type: msg.type, data: data }
|
85
|
+
block.call(msg)
|
87
86
|
end
|
88
|
-
@client.__send__(method, event, params, &block)
|
89
87
|
else
|
90
88
|
wait_for_reads(event, params[:once])
|
91
89
|
end
|
@@ -95,7 +93,7 @@ module VCR
|
|
95
93
|
@thread = Thread.new do
|
96
94
|
# if the next recorded operation is a 'read', take all the reads until next write
|
97
95
|
# and translate them to the events
|
98
|
-
while @open && !@recording.empty?
|
96
|
+
while @open && !@recording.empty?
|
99
97
|
begin
|
100
98
|
if @recording.first['operation'] == 'read'
|
101
99
|
record = @recording.shift
|
@@ -106,8 +104,9 @@ module VCR
|
|
106
104
|
self
|
107
105
|
end
|
108
106
|
emit(event, data)
|
107
|
+
break if once
|
109
108
|
else
|
110
|
-
sleep 0.1 # TODO config
|
109
|
+
sleep 0.1 # TODO: config
|
111
110
|
end
|
112
111
|
end
|
113
112
|
end
|
@@ -120,12 +119,12 @@ module VCR
|
|
120
119
|
|
121
120
|
def _ensure_operation(desired, actual)
|
122
121
|
string = "Expected to '#{desired}' but the next operation in recording was '#{actual}'"
|
123
|
-
|
122
|
+
fail string unless desired == actual
|
124
123
|
end
|
125
124
|
|
126
125
|
def _ensure_data(desired, actual)
|
127
126
|
string = "Expected data to be '#{desired}' but next data in recording was '#{actual}'"
|
128
|
-
|
127
|
+
fail string unless desired == actual
|
129
128
|
end
|
130
129
|
end
|
131
130
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
1
|
+
require 'simple_websocket_vcr/cassette'
|
2
|
+
require 'simple_websocket_vcr/configuration'
|
3
|
+
require 'simple_websocket_vcr/errors'
|
4
|
+
require 'simple_websocket_vcr/recordable_websocket_client'
|
5
|
+
require 'simple_websocket_vcr/version'
|
6
6
|
require 'json'
|
7
7
|
require 'websocket-client-simple'
|
8
8
|
|
@@ -36,7 +36,7 @@ module VCR
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def use_cassette(name, _options = {})
|
39
|
-
|
39
|
+
fail ArgumentError, '`VCR.use_cassette` requires a block.' unless block_given?
|
40
40
|
self.cassette = Cassette.new(name)
|
41
41
|
yield
|
42
42
|
cassette.save
|
@@ -44,12 +44,12 @@ module VCR
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def record(example, context, options = {}, &block)
|
47
|
-
|
47
|
+
fail ArgumentError, '`VCR.record` requires a block.' unless block_given?
|
48
48
|
name = filename_helper(example, context)
|
49
49
|
use_cassette(name, options, &block)
|
50
50
|
end
|
51
51
|
|
52
|
-
def turn_off!(
|
52
|
+
def turn_off!(_options = {})
|
53
53
|
# TODO: impl
|
54
54
|
end
|
55
55
|
|
@@ -85,7 +85,7 @@ end
|
|
85
85
|
|
86
86
|
module WebSocket::Client::Simple
|
87
87
|
class << self
|
88
|
-
|
88
|
+
alias_method :real_connect, :connect
|
89
89
|
|
90
90
|
def connect(url, options = {})
|
91
91
|
if VCR::WebSocket.configuration.hook_uris.any? { |u| url.include?(u) }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'simple_websocket_vcr/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'simple-websocket-vcr'
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ['Jirka Kremser']
|
10
10
|
gem.email = ['jkremser@redhat.com']
|
11
11
|
gem.description = 'Websocket VCR add-on'
|
12
|
-
gem.summary = '
|
12
|
+
gem.summary = 'simple_websocket_vcr is VCR add-on for websockets.'
|
13
13
|
gem.homepage = 'https://github.com/Jiri-Kremser/simple-websocket-vcr'
|
14
14
|
gem.license = 'Apache-2.0'
|
15
15
|
gem.required_ruby_version = '>= 2.0.0'
|
@@ -3,7 +3,7 @@
|
|
3
3
|
{
|
4
4
|
"operation": "read",
|
5
5
|
"type": "text",
|
6
|
-
"data": "WelcomeResponse={\"sessionId\":\"
|
6
|
+
"data": "WelcomeResponse={\"sessionId\":\"43RYOpJQT3ZpP5fHj_Nxs9Ef7QcOA79vPZtPjXn2\"}"
|
7
7
|
},
|
8
8
|
{
|
9
9
|
"operation": "write",
|
@@ -12,7 +12,7 @@
|
|
12
12
|
{
|
13
13
|
"operation": "read",
|
14
14
|
"type": "text",
|
15
|
-
"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.
|
15
|
+
"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.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\\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
16
|
},
|
17
17
|
{
|
18
18
|
"operation": "write",
|
@@ -21,7 +21,7 @@
|
|
21
21
|
{
|
22
22
|
"operation": "read",
|
23
23
|
"type": "text",
|
24
|
-
"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.
|
24
|
+
"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.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\\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
25
|
},
|
26
26
|
{
|
27
27
|
"operation": "close"
|
data/spec/vcr_spec.rb
CHANGED
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: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jirka Kremser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -139,12 +139,12 @@ files:
|
|
139
139
|
- LICENSE.txt
|
140
140
|
- README.md
|
141
141
|
- Rakefile
|
142
|
-
- lib/
|
143
|
-
- lib/
|
144
|
-
- lib/
|
145
|
-
- lib/
|
146
|
-
- lib/
|
147
|
-
- lib/
|
142
|
+
- lib/simple_websocket_vcr.rb
|
143
|
+
- lib/simple_websocket_vcr/cassette.rb
|
144
|
+
- lib/simple_websocket_vcr/configuration.rb
|
145
|
+
- lib/simple_websocket_vcr/errors.rb
|
146
|
+
- lib/simple_websocket_vcr/recordable_websocket_client.rb
|
147
|
+
- lib/simple_websocket_vcr/version.rb
|
148
148
|
- simple-websocket-vcr.gemspec
|
149
149
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette.json
|
150
150
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/automatically_picked_cassette_name_is_ok,_when_describing_parent_and_example_child1.json
|
@@ -178,7 +178,7 @@ rubyforge_project:
|
|
178
178
|
rubygems_version: 2.6.2
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
|
-
summary:
|
181
|
+
summary: simple_websocket_vcr is VCR add-on for websockets.
|
182
182
|
test_files:
|
183
183
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette.json
|
184
184
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/automatically_picked_cassette_name_is_ok,_when_describing_parent_and_example_child1.json
|