simple-websocket-vcr 0.0.7 → 0.1.0
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/.travis.yml +2 -4
- data/lib/simple_websocket_vcr.rb +1 -8
- data/lib/simple_websocket_vcr/cassette.rb +18 -17
- data/lib/simple_websocket_vcr/recordable_websocket_client.rb +5 -5
- data/lib/simple_websocket_vcr/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette_should_be_re-recorded.yml +46 -0
- data/spec/vcr_spec.rb +19 -9
- metadata +5 -6
- data/spec/fixtures/vcr_cassettes/EXPLICIT/.gitignore +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7afb7894a207b315a358e261bf424af389b4ff6
|
4
|
+
data.tar.gz: c89e7986e60e765c8c635141bf2088e0f97c1e29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c5bb740f4b7771a25eb472a58b90d0a9fa9811ad16d5065cdc15d76e322eabd95366d48933a4559df193d3483af0bd3d2216352b6358b0ba370fe590eef40c
|
7
|
+
data.tar.gz: f94270cdcc1f91d34d4d8d0db6bfde3934e75066a834fc263c8139bfa19272a6a2ef22b354a79d93f6489c08bb3d2fc17ff43335d3a4fd902017f7b2a9c6c52d
|
data/.travis.yml
CHANGED
data/lib/simple_websocket_vcr.rb
CHANGED
@@ -10,6 +10,7 @@ require 'simple_websocket_vcr/monkey_patch'
|
|
10
10
|
|
11
11
|
module WebSocketVCR
|
12
12
|
extend self
|
13
|
+
attr_accessor :cassette
|
13
14
|
|
14
15
|
# @return [String] the current version.
|
15
16
|
# @note This string also has singleton methods:
|
@@ -50,14 +51,6 @@ module WebSocketVCR
|
|
50
51
|
@configuration ||= Configuration.new
|
51
52
|
end
|
52
53
|
|
53
|
-
def cassette
|
54
|
-
@cassette
|
55
|
-
end
|
56
|
-
|
57
|
-
def cassette=(v)
|
58
|
-
@cassette = v
|
59
|
-
end
|
60
|
-
|
61
54
|
def disabled
|
62
55
|
@disabled || false
|
63
56
|
end
|
@@ -65,20 +65,13 @@ module WebSocketVCR
|
|
65
65
|
def initialize_sessions(filename)
|
66
66
|
file_content = File.open(filename, &:read)
|
67
67
|
|
68
|
-
# do the ERB substitution
|
69
|
-
unless @options[:erb].nil?
|
70
|
-
require 'ostruct'
|
71
|
-
namespace = OpenStruct.new(@options[:erb])
|
72
|
-
file_content = ERB.new(file_content).result(namespace.instance_eval { binding })
|
73
|
-
end
|
74
|
-
|
75
68
|
# parse JSON/YAML
|
76
69
|
if @using_json
|
77
70
|
parsed_content = JSON.parse(file_content)
|
78
|
-
sessions = RecordedJsonSession.load(parsed_content)
|
71
|
+
sessions = RecordedJsonSession.load(parsed_content, @options[:erb])
|
79
72
|
else
|
80
73
|
parsed_content = YAML.load(file_content)
|
81
|
-
sessions = RecordedYamlSession.load(parsed_content)
|
74
|
+
sessions = RecordedYamlSession.load(parsed_content, @options[:erb])
|
82
75
|
end
|
83
76
|
sessions
|
84
77
|
end
|
@@ -94,7 +87,7 @@ module WebSocketVCR
|
|
94
87
|
|
95
88
|
def store(entry)
|
96
89
|
hash = entry.is_a?(RecordEntry) ? entry.attributes.map(&:to_s) : Hash[entry.map { |k, v| [k.to_s, v.to_s] }]
|
97
|
-
if !hash['data'].nil? && !@erb_variables.nil?
|
90
|
+
if !hash['data'].nil? && !@erb_variables.nil? && hash['type'] != 'binary'
|
98
91
|
@erb_variables.each do |k, v|
|
99
92
|
hash['data'].gsub! v.to_s, "<%= #{k} %>"
|
100
93
|
end
|
@@ -103,11 +96,11 @@ module WebSocketVCR
|
|
103
96
|
end
|
104
97
|
|
105
98
|
def next
|
106
|
-
RecordEntry.parse(@record_entries.shift)
|
99
|
+
RecordEntry.parse(@record_entries.shift, @erb_variables)
|
107
100
|
end
|
108
101
|
|
109
102
|
def head
|
110
|
-
@record_entries.empty? ? nil : RecordEntry.parse(@record_entries.first)
|
103
|
+
@record_entries.empty? ? nil : RecordEntry.parse(@record_entries.first, @erb_variables)
|
111
104
|
end
|
112
105
|
|
113
106
|
def method_missing(method_name, *args, &block)
|
@@ -116,25 +109,33 @@ module WebSocketVCR
|
|
116
109
|
end
|
117
110
|
|
118
111
|
class RecordedJsonSession < RecordedSession
|
119
|
-
def self.load(json)
|
120
|
-
json.map { |session| RecordedJsonSession.new(session) }
|
112
|
+
def self.load(json, erb_variables = nil)
|
113
|
+
json.map { |session| RecordedJsonSession.new(session, erb_variables) }
|
121
114
|
end
|
122
115
|
end
|
123
116
|
|
124
117
|
class RecordedYamlSession < RecordedSession
|
125
|
-
def self.load(yaml)
|
126
|
-
yaml['websocket_interactions'].map { |session| RecordedYamlSession.new(session) }
|
118
|
+
def self.load(yaml, erb_variables = nil)
|
119
|
+
yaml['websocket_interactions'].map { |session| RecordedYamlSession.new(session, erb_variables) }
|
127
120
|
end
|
128
121
|
end
|
129
122
|
|
130
123
|
class RecordEntry
|
131
124
|
attr_accessor :operation, :type, :data
|
132
125
|
|
133
|
-
def self.parse(obj)
|
126
|
+
def self.parse(obj, erb_variables = nil)
|
134
127
|
record_entry = RecordEntry.new
|
135
128
|
record_entry.operation = obj['operation']
|
136
129
|
record_entry.type = obj['type'] if obj['type']
|
137
130
|
record_entry.data = obj['data'] if obj['data']
|
131
|
+
|
132
|
+
# do the ERB substitution
|
133
|
+
if erb_variables && record_entry.type != 'binary'
|
134
|
+
require 'ostruct'
|
135
|
+
namespace = OpenStruct.new(erb_variables)
|
136
|
+
record_entry.data = ERB.new(record_entry.data).result(namespace.instance_eval { binding })
|
137
|
+
end
|
138
|
+
|
138
139
|
record_entry
|
139
140
|
end
|
140
141
|
end
|
@@ -79,16 +79,16 @@ module WebSocketVCR
|
|
79
79
|
if @live
|
80
80
|
rec = @session
|
81
81
|
@client.on(event, params) do |msg|
|
82
|
-
data = msg.type ==
|
82
|
+
data = msg.type.to_s == 'text' ? msg.data : Base64.encode64(msg.data)
|
83
83
|
rec.store(operation: 'read', type: msg.type, data: data)
|
84
84
|
yield(msg)
|
85
85
|
end
|
86
86
|
else
|
87
|
-
wait_for_reads(event
|
87
|
+
wait_for_reads(event) unless @thread && @thread.alive?
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
def wait_for_reads(event
|
91
|
+
def wait_for_reads(event)
|
92
92
|
@thread = Thread.new do
|
93
93
|
# if the next recorded operation is a 'read', take all the reads until next write
|
94
94
|
# and translate them to the events
|
@@ -97,7 +97,7 @@ module WebSocketVCR
|
|
97
97
|
if @session.head.operation == 'read'
|
98
98
|
record = @session.next
|
99
99
|
data = record.data
|
100
|
-
data = Base64.decode64(
|
100
|
+
data = Base64.decode64(data) if record.type != 'text'
|
101
101
|
data = ::WebSocket::Frame::Data.new(data)
|
102
102
|
|
103
103
|
def data.data
|
@@ -105,7 +105,7 @@ module WebSocketVCR
|
|
105
105
|
end
|
106
106
|
|
107
107
|
emit(event, data)
|
108
|
-
break if
|
108
|
+
break if __events.empty?
|
109
109
|
else
|
110
110
|
sleep 0.1 # TODO: config
|
111
111
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
websocket_interactions:
|
3
|
+
- - operation: read
|
4
|
+
type: text
|
5
|
+
data: WelcomeResponse={"sessionId":"_Q8LZN4jeyX27Qb2qjiz_3HR9Ckoa1S-pHMaJi9q"}
|
6
|
+
- operation: write
|
7
|
+
data: something_1
|
8
|
+
- operation: read
|
9
|
+
type: text
|
10
|
+
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
11
|
+
Cannot deserialize: [something_1]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
12
|
+
org.hawkular.cmdgw.api.ApiDeserializer.deserialize(ApiDeserializer.java:84)\n\tat
|
13
|
+
org.hawkular.cmdgw.command.ws.server.AbstractGatewayWebSocket.onMessage(AbstractGatewayWebSocket.java:213)\n\tat
|
14
|
+
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat
|
15
|
+
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat
|
16
|
+
java.lang.reflect.Method.invoke(Method.java:497)\n\tat io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:87)\n\tat
|
17
|
+
io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2$1.run(AnnotatedEndpoint.java:150)\n\tat
|
18
|
+
io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\n\tat
|
19
|
+
io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2.onMessage(AnnotatedEndpoint.java:145)\n\tat
|
20
|
+
io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:283)\n\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\n\tat
|
21
|
+
io.undertow.websockets.jsr.ServerWebSocketContainer$5.run(ServerWebSocketContainer.java:538)\n\tat
|
22
|
+
io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:67)\n\tat
|
23
|
+
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat
|
24
|
+
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
25
|
+
java.lang.Thread.run(Thread.java:745)\n"}'
|
26
|
+
- operation: write
|
27
|
+
data: something_2
|
28
|
+
- operation: read
|
29
|
+
type: text
|
30
|
+
data: 'GenericErrorResponse={"errorMessage":"Failed to process message [?]","stackTrace":"java.lang.IllegalArgumentException:
|
31
|
+
Cannot deserialize: [something_2]\n\tat org.hawkular.cmdgw.api.ApiDeserializer.fromHawkularFormat(ApiDeserializer.java:68)\n\tat
|
32
|
+
org.hawkular.cmdgw.api.ApiDeserializer.deserialize(ApiDeserializer.java:84)\n\tat
|
33
|
+
org.hawkular.cmdgw.command.ws.server.AbstractGatewayWebSocket.onMessage(AbstractGatewayWebSocket.java:213)\n\tat
|
34
|
+
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat
|
35
|
+
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat
|
36
|
+
java.lang.reflect.Method.invoke(Method.java:497)\n\tat io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:87)\n\tat
|
37
|
+
io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2$1.run(AnnotatedEndpoint.java:150)\n\tat
|
38
|
+
io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\n\tat
|
39
|
+
io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2.onMessage(AnnotatedEndpoint.java:145)\n\tat
|
40
|
+
io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:283)\n\tat io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)\n\tat
|
41
|
+
io.undertow.websockets.jsr.ServerWebSocketContainer$5.run(ServerWebSocketContainer.java:538)\n\tat
|
42
|
+
io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:67)\n\tat
|
43
|
+
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat
|
44
|
+
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat
|
45
|
+
java.lang.Thread.run(Thread.java:745)\n"}'
|
46
|
+
- operation: close
|
data/spec/vcr_spec.rb
CHANGED
@@ -157,20 +157,30 @@ describe 'VCR for WS' do
|
|
157
157
|
WebSocketVCR.configure do |c|
|
158
158
|
c.hook_uris = [HOST]
|
159
159
|
end
|
160
|
-
cassette_path = '/EXPLICIT/
|
160
|
+
cassette_path = '/EXPLICIT/some_explicitly_specified_cassette_should_be_re-recorded'
|
161
|
+
|
162
|
+
# run the test for the 1st time
|
161
163
|
WebSocketVCR.use_cassette(cassette_path) do
|
162
164
|
test_complex
|
163
165
|
end
|
166
|
+
if ON_TRAVIS
|
167
|
+
expect do
|
168
|
+
WebSocketVCR.use_cassette(cassette_path, record: :all) do
|
169
|
+
test_complex
|
170
|
+
end
|
171
|
+
fail 'this code should not be reachable'
|
172
|
+
end.to raise_error(/Connection refused/)
|
173
|
+
else
|
174
|
+
file_path = "#{WebSocketVCR.configuration.cassette_library_dir}#{cassette_path}.yml"
|
175
|
+
original_last_modified = File.mtime(file_path)
|
164
176
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
177
|
+
# run the test again w/ record: :all option set
|
178
|
+
WebSocketVCR.use_cassette(cassette_path, record: :all) do
|
179
|
+
test_complex
|
180
|
+
end
|
181
|
+
new_last_modified = File.mtime(file_path)
|
182
|
+
expect(original_last_modified).to be < new_last_modified
|
171
183
|
end
|
172
|
-
new_last_modified = File.mtime(file_path)
|
173
|
-
expect(original_last_modified).to be < new_last_modified
|
174
184
|
end
|
175
185
|
|
176
186
|
context 'automatically picked cassette name is ok, when using context foo' do
|
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.1.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: 2017-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-client-simple
|
@@ -147,7 +147,7 @@ files:
|
|
147
147
|
- lib/simple_websocket_vcr/recordable_websocket_client.rb
|
148
148
|
- lib/simple_websocket_vcr/version.rb
|
149
149
|
- simple-websocket-vcr.gemspec
|
150
|
-
- spec/fixtures/vcr_cassettes/EXPLICIT
|
150
|
+
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette_should_be_re-recorded.yml
|
151
151
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_json_cassette.json
|
152
152
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_yaml_cassette.yml
|
153
153
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_other_template.yml
|
@@ -184,12 +184,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.6.
|
187
|
+
rubygems_version: 2.6.12
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: simple_websocket_vcr is VCR add-on for websockets.
|
191
191
|
test_files:
|
192
|
-
- spec/fixtures/vcr_cassettes/EXPLICIT
|
192
|
+
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_cassette_should_be_re-recorded.yml
|
193
193
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_json_cassette.json
|
194
194
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_explicitly_specified_yaml_cassette.yml
|
195
195
|
- spec/fixtures/vcr_cassettes/EXPLICIT/some_other_template.yml
|
@@ -206,4 +206,3 @@ test_files:
|
|
206
206
|
- spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_the_very_first_message_caught_on_the_client_yielded_by_the_connect_method.yml
|
207
207
|
- spec/spec_helper.rb
|
208
208
|
- spec/vcr_spec.rb
|
209
|
-
has_rdoc:
|
@@ -1 +0,0 @@
|
|
1
|
-
some_explicitly_specified_cassette_that_should_be_re-recorded.*
|