pubnub 3.5.8 → 3.5.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

@@ -0,0 +1,564 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#subscribe" do
4
+ before(:each) do
5
+
6
+ EM.stop if EM.reactor_running?
7
+ while EM.reactor_running? do end
8
+ sleep(0.1)
9
+
10
+ @response_output = StringIO.new
11
+ @message_output = StringIO.new
12
+
13
+ @callback = lambda { |envelope|
14
+ $logger.debug 'FIRING CALLBACK FROM TEST'
15
+ @response_output.write envelope.response
16
+ @message_output.write envelope.msg
17
+ @after_callback = true
18
+ }
19
+
20
+ @error_callback = lambda { |envelope|
21
+ $logger.debug 'FIRING ERROR CALLBACK FROM TEST'
22
+ @response_output.write envelope.response
23
+ @message_output.write envelope.msg
24
+ @after_error_callback = true
25
+ }
26
+
27
+ @pn = nil
28
+ @pn = Pubnub.new(:disable_persistent_connection => true, :max_retries => 0, :subscribe_key => :demo, :publish_key => :demo, :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
29
+ @pn.uuid = 'rubytests'
30
+
31
+ end
32
+ context "uses ssl" do
33
+ before(:each) { @ssl = true }
34
+ context "passess callback as block" do
35
+ context "gets valid json in response" do
36
+ context "gets status 200 in response" do
37
+ context "uses sync connection" do
38
+ it 'works fine' do
39
+ VCR.use_cassette("subscribe-ssl-block-valid-200-sync", :record => :none) do
40
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
41
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
42
+
43
+ @after_callback.should eq true
44
+ @response_output.seek 0
45
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
46
+ @message_output.seek 0
47
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
48
+ end
49
+ end
50
+ end
51
+ context "uses async connection" do
52
+ it 'works fine' do
53
+ VCR.use_cassette("subscribe-ssl-block-valid-200-async", :record => :none) do
54
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
55
+
56
+ eventually do
57
+ @after_callback.should eq true
58
+ @response_output.seek 0
59
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
60
+ @message_output.seek 0
61
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ context "gets status non-200 in response" do
68
+ context "uses sync connection" do
69
+ it 'works fine' do
70
+ VCR.use_cassette("subscribe-ssl-block-valid-non-200-sync", :record => :none) do
71
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
72
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
73
+
74
+ @after_error_callback.should eq true
75
+ @response_output.seek 0
76
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
77
+ @message_output.seek 0
78
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
79
+ end
80
+ end
81
+ end
82
+ context "uses async connection" do
83
+ it 'works fine' do
84
+ VCR.use_cassette("subscribe-ssl-block-valid-non-200-async", :record => :none) do
85
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
86
+
87
+ eventually do
88
+ @after_error_callback.should eq true
89
+ @response_output.seek 0
90
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
91
+ @message_output.seek 0
92
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ context "gets invalid json in response" do
100
+ context "gets status 200 in response" do
101
+ context "uses sync connection" do
102
+ it 'works fine' do
103
+ VCR.use_cassette("subscribe-ssl-block-invalid-200-sync", :record => :none) do
104
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
105
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
106
+
107
+ @after_error_callback.should eq true
108
+ @response_output.seek 0
109
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
110
+ @message_output.seek 0
111
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
112
+ end
113
+ end
114
+ end
115
+ context "uses async connection" do
116
+ it 'works fine' do
117
+ VCR.use_cassette("subscribe-ssl-block-invalid-200-async", :record => :none) do
118
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
119
+
120
+ eventually do
121
+ @after_error_callback.should eq true
122
+ @response_output.seek 0
123
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
124
+ @message_output.seek 0
125
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ context "gets status non-200 in response" do
132
+ context "uses sync connection" do
133
+ it 'works fine' do
134
+ VCR.use_cassette("subscribe-ssl-block-invalid-non-200-sync", :record => :none) do
135
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
136
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
137
+
138
+ @after_error_callback.should eq true
139
+ @response_output.seek 0
140
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
141
+ @message_output.seek 0
142
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
143
+ end
144
+ end
145
+ end
146
+ context "uses async connection" do
147
+ it 'works fine' do
148
+ VCR.use_cassette("subscribe-ssl-block-invalid-non-200-async", :record => :none) do
149
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
150
+
151
+ eventually do
152
+ @after_error_callback.should eq true
153
+ @response_output.seek 0
154
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
155
+ @message_output.seek 0
156
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ context "passess callback as parameter" do
165
+ context "gets valid json in response" do
166
+ context "gets status 200 in response" do
167
+ context "uses sync connection" do
168
+ it 'works fine' do
169
+ VCR.use_cassette("subscribe-ssl-parameter-valid-200-sync", :record => :none) do
170
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
171
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
172
+
173
+ @after_callback.should eq true
174
+ @response_output.seek 0
175
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
176
+ @message_output.seek 0
177
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
178
+ end
179
+ end
180
+ end
181
+ context "uses async connection" do
182
+ it 'works fine' do
183
+ VCR.use_cassette("subscribe-ssl-parameter-valid-200-async", :record => :none) do
184
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
185
+
186
+ eventually do
187
+ @after_callback.should eq true
188
+ @response_output.seek 0
189
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
190
+ @message_output.seek 0
191
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ context "gets status non-200 in response" do
198
+ context "uses sync connection" do
199
+ it 'works fine' do
200
+ VCR.use_cassette("subscribe-ssl-parameter-valid-non-200-sync", :record => :none) do
201
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
202
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
203
+
204
+ @after_error_callback.should eq true
205
+ @response_output.seek 0
206
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
207
+ @message_output.seek 0
208
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
209
+ end
210
+ end
211
+ end
212
+ context "uses async connection" do
213
+ it 'works fine' do
214
+ VCR.use_cassette("subscribe-ssl-parameter-valid-non-200-async", :record => :none) do
215
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
216
+
217
+ eventually do
218
+ @after_error_callback.should eq true
219
+ @response_output.seek 0
220
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
221
+ @message_output.seek 0
222
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
229
+ context "gets invalid json in response" do
230
+ context "gets status 200 in response" do
231
+ context "uses sync connection" do
232
+ it 'works fine' do
233
+ VCR.use_cassette("subscribe-ssl-parameter-invalid-200-sync", :record => :none) do
234
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
235
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
236
+
237
+ @after_error_callback.should eq true
238
+ @response_output.seek 0
239
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
240
+ @message_output.seek 0
241
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
242
+ end
243
+ end
244
+ end
245
+ context "uses async connection" do
246
+ it 'works fine' do
247
+ VCR.use_cassette("subscribe-ssl-parameter-invalid-200-async", :record => :none) do
248
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
249
+
250
+ eventually do
251
+ @after_error_callback.should eq true
252
+ @response_output.seek 0
253
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
254
+ @message_output.seek 0
255
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end
261
+ context "gets status non-200 in response" do
262
+ context "uses sync connection" do
263
+ it 'works fine' do
264
+ VCR.use_cassette("subscribe-ssl-parameter-invalid-non-200-sync", :record => :none) do
265
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
266
+ @pn.subscribe(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
267
+
268
+ @after_error_callback.should eq true
269
+ @response_output.seek 0
270
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
271
+ @message_output.seek 0
272
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
273
+ end
274
+ end
275
+ end
276
+ context "uses async connection" do
277
+ it 'works fine' do
278
+ VCR.use_cassette("subscribe-ssl-parameter-invalid-non-200-async", :record => :none) do
279
+ @pn.subscribe(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
280
+
281
+ eventually do
282
+ @after_error_callback.should eq true
283
+ @response_output.seek 0
284
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
285
+ @message_output.seek 0
286
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
294
+ end
295
+ context "uses non-ssl" do
296
+ before(:each) { @ssl = false }
297
+ context "passess callback as block" do
298
+ context "gets valid json in response" do
299
+ context "gets status 200 in response" do
300
+ context "uses sync connection" do
301
+ it 'works fine' do
302
+ VCR.use_cassette("subscribe-nonssl-block-valid-200-sync", :record => :none) do
303
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
304
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
305
+
306
+ @after_callback.should eq true
307
+ @response_output.seek 0
308
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
309
+ @message_output.seek 0
310
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
311
+ end
312
+ end
313
+ end
314
+ context "uses async connection" do
315
+ it 'works fine' do
316
+ VCR.use_cassette("subscribe-nonssl-block-valid-200-async", :record => :none) do
317
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
318
+
319
+ eventually do
320
+ @after_callback.should eq true
321
+ @response_output.seek 0
322
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
323
+ @message_output.seek 0
324
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
325
+ end
326
+ end
327
+ end
328
+ end
329
+ end
330
+ context "gets status non-200 in response" do
331
+ context "uses sync connection" do
332
+ it 'works fine' do
333
+ VCR.use_cassette("subscribe-nonssl-block-valid-non-200-sync", :record => :none) do
334
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
335
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
336
+
337
+ @after_error_callback.should eq true
338
+ @response_output.seek 0
339
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
340
+ @message_output.seek 0
341
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
342
+ end
343
+ end
344
+ end
345
+ context "uses async connection" do
346
+ it 'works fine' do
347
+ VCR.use_cassette("subscribe-nonssl-block-valid-non-200-async", :record => :none) do
348
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
349
+
350
+ eventually do
351
+ @after_error_callback.should eq true
352
+ @response_output.seek 0
353
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
354
+ @message_output.seek 0
355
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end
361
+ end
362
+ context "gets invalid json in response" do
363
+ context "gets status 200 in response" do
364
+ context "uses sync connection" do
365
+ it 'works fine' do
366
+ VCR.use_cassette("subscribe-nonssl-block-invalid-200-sync", :record => :none) do
367
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
368
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
369
+
370
+ eventually do
371
+ @after_error_callback.should eq true
372
+ @response_output.seek 0
373
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
374
+ @message_output.seek 0
375
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
376
+ end
377
+ end
378
+ end
379
+ end
380
+ context "uses async connection" do
381
+ it 'works fine' do
382
+ VCR.use_cassette("subscribe-nonssl-block-invalid-200-async", :record => :none) do
383
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
384
+
385
+ eventually do
386
+ @after_error_callback.should eq true
387
+ @response_output.seek 0
388
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
389
+ @message_output.seek 0
390
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
391
+ end
392
+ end
393
+ end
394
+ end
395
+ end
396
+ context "gets status non-200 in response" do
397
+ context "uses sync connection" do
398
+ it 'works fine' do
399
+ VCR.use_cassette("subscribe-nonssl-block-invalid-non-200-sync", :record => :none) do
400
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
401
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
402
+
403
+ eventually do
404
+ @after_error_callback.should eq true
405
+ @response_output.seek 0
406
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
407
+ @message_output.seek 0
408
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
409
+ end
410
+ end
411
+ end
412
+ end
413
+ context "uses async connection" do
414
+ it 'works fine' do
415
+ VCR.use_cassette("subscribe-nonssl-block-invalid-non-200-async", :record => :none) do
416
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
417
+
418
+ eventually do
419
+ @after_error_callback.should eq true
420
+ @response_output.seek 0
421
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
422
+ @message_output.seek 0
423
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
424
+ end
425
+ end
426
+ end
427
+ end
428
+ end
429
+ end
430
+ end
431
+ context "passess callback as parameter" do
432
+ context "gets valid json in response" do
433
+ context "gets status 200 in response" do
434
+ context "uses sync connection" do
435
+ it 'works fine' do
436
+ VCR.use_cassette("subscribe-nonssl-parameter-valid-200-sync", :record => :none) do
437
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
438
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
439
+
440
+ @after_callback.should eq true
441
+ @response_output.seek 0
442
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
443
+ @message_output.seek 0
444
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
445
+ end
446
+ end
447
+ end
448
+ context "uses async connection" do
449
+ it 'works fine' do
450
+ VCR.use_cassette("subscribe-nonssl-parameter-valid-200-async", :record => :none) do
451
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
452
+
453
+ eventually do
454
+ @after_callback.should eq true
455
+ @response_output.seek 0
456
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"][[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
457
+ @message_output.seek 0
458
+ @message_output.read.should eq '{"text"=>"hey"}{"text"=>"hey"}'
459
+ end
460
+ end
461
+ end
462
+ end
463
+ end
464
+ context "gets status non-200 in response" do
465
+ context "uses sync connection" do
466
+ it 'works fine' do
467
+ VCR.use_cassette("subscribe-nonssl-parameter-valid-non-200-sync", :record => :none) do
468
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
469
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
470
+
471
+ eventually do
472
+ @after_error_callback.should eq true
473
+ @response_output.seek 0
474
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
475
+ @message_output.seek 0
476
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
477
+ end
478
+ end
479
+ end
480
+ end
481
+ context "uses async connection" do
482
+ it 'works fine' do
483
+ VCR.use_cassette("subscribe-nonssl-parameter-valid-non-200-async", :record => :none) do
484
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
485
+
486
+ eventually do
487
+ @after_error_callback.should eq true
488
+ @response_output.seek 0
489
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"13904299332319098"]'
490
+ @message_output.seek 0
491
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
492
+ end
493
+ end
494
+ end
495
+ end
496
+ end
497
+ end
498
+ context "gets invalid json in response" do
499
+ context "gets status 200 in response" do
500
+ context "uses sync connection" do
501
+ it 'works fine' do
502
+ VCR.use_cassette("subscribe-nonssl-parameter-invalid-200-sync", :record => :none) do
503
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
504
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
505
+
506
+ @after_error_callback.should eq true
507
+ @response_output.seek 0
508
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
509
+ @message_output.seek 0
510
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
511
+ end
512
+ end
513
+ end
514
+ context "uses async connection" do
515
+ it 'works fine' do
516
+ VCR.use_cassette("subscribe-nonssl-parameter-invalid-200-async", :record => :none) do
517
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
518
+
519
+ eventually do
520
+ @after_error_callback.should eq true
521
+ @response_output.seek 0
522
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
523
+ @message_output.seek 0
524
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
525
+ end
526
+ end
527
+ end
528
+ end
529
+ end
530
+ context "gets status non-200 in response" do
531
+ context "uses sync connection" do
532
+ it 'works fine' do
533
+ VCR.use_cassette("subscribe-nonssl-parameter-invalid-non-200-sync", :record => :none) do
534
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
535
+ @pn.subscribe(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
536
+
537
+ @after_error_callback.should eq true
538
+ @response_output.seek 0
539
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
540
+ @message_output.seek 0
541
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
542
+ end
543
+ end
544
+ end
545
+ context "uses async connection" do
546
+ it 'works fine' do
547
+ VCR.use_cassette("subscribe-nonssl-parameter-invalid-non-200-async", :record => :none) do
548
+ @pn.subscribe(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
549
+
550
+ eventually do
551
+ @after_error_callback.should eq true
552
+ @response_output.seek 0
553
+ @response_output.read.should eq '[[{"text":"hey"},{"text":"hey"}],"'
554
+ @message_output.seek 0
555
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
556
+ end
557
+ end
558
+ end
559
+ end
560
+ end
561
+ end
562
+ end
563
+ end
564
+ end