nebulous_stomp 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hgignore +2 -0
- data/.hgtags +1 -0
- data/README.md +225 -28
- data/feature/connection_example.yaml +24 -0
- data/feature/feature_test_spec.rb +247 -0
- data/feature/gimme.rb +91 -0
- data/lib/nebulous_stomp/listener.rb +107 -0
- data/lib/nebulous_stomp/message.rb +132 -265
- data/lib/nebulous_stomp/msg/body.rb +169 -0
- data/lib/nebulous_stomp/msg/header.rb +98 -0
- data/lib/nebulous_stomp/param.rb +16 -35
- data/lib/nebulous_stomp/redis_handler.rb +19 -29
- data/lib/nebulous_stomp/redis_handler_null.rb +12 -11
- data/lib/nebulous_stomp/redis_helper.rb +110 -0
- data/lib/nebulous_stomp/request.rb +212 -0
- data/lib/nebulous_stomp/stomp_handler.rb +30 -96
- data/lib/nebulous_stomp/stomp_handler_null.rb +8 -22
- data/lib/nebulous_stomp/target.rb +52 -0
- data/lib/nebulous_stomp/version.rb +1 -1
- data/lib/nebulous_stomp.rb +63 -50
- data/md/LICENSE.txt +20 -2
- data/md/nebulous_protocol.md +25 -18
- data/spec/listener_spec.rb +104 -0
- data/spec/message_spec.rb +227 -116
- data/spec/nebulous_spec.rb +44 -9
- data/spec/param_spec.rb +16 -33
- data/spec/redis_handler_null_spec.rb +0 -2
- data/spec/redis_handler_spec.rb +0 -2
- data/spec/redis_helper_spec.rb +107 -0
- data/spec/request_spec.rb +249 -0
- data/spec/stomp_handler_null_spec.rb +33 -34
- data/spec/stomp_handler_spec.rb +1 -74
- data/spec/target_spec.rb +97 -0
- metadata +20 -11
- data/lib/nebulous_stomp/nebrequest.rb +0 -259
- data/lib/nebulous_stomp/nebrequest_null.rb +0 -37
- data/spec/nebrequest_null_spec.rb +0 -219
- data/spec/nebrequest_spec.rb +0 -239
- data/spec/through_test_spec.rb +0 -80
data/spec/message_spec.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'stomp'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
1
|
require 'nebulous_stomp/message'
|
5
2
|
|
6
3
|
require_relative 'helpers'
|
@@ -20,6 +17,7 @@ describe Message do
|
|
20
17
|
# headers; we're stuck with that. So for comparison purposes this helper
|
21
18
|
# function deep-converts all keys in a hash to symbols.
|
22
19
|
def symbolise(hash)
|
20
|
+
return nil unless hash.is_a? Hash
|
23
21
|
|
24
22
|
hash.each_with_object({}) do |(k,v),m|
|
25
23
|
m[k.to_sym] = v.kind_of?(Hash) ? symbolise(v) : v
|
@@ -28,17 +26,26 @@ describe Message do
|
|
28
26
|
end
|
29
27
|
|
30
28
|
|
31
|
-
let(:
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
let(:new_hash_body) do
|
30
|
+
{ verb: 'Velma', parameters: 'Shaggy', description:'Scooby' }
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:new_hash) do
|
34
|
+
{ replyTo: 'Daphne',
|
35
|
+
inReplyTo: 'Fred',
|
36
|
+
verb: 'Velma',
|
37
|
+
parameters: 'Shaggy',
|
38
|
+
description: 'Scooby' }
|
39
|
+
|
35
40
|
end
|
36
41
|
|
42
|
+
let(:msg_new) { Message.new new_hash }
|
43
|
+
let(:msg_new2) { Message.new new_hash.merge(replyId: 42) }
|
44
|
+
|
37
45
|
let(:smess) { stomp_message('application/text', 'foo') }
|
38
46
|
let(:msg_stomp) { Message.from_stomp(smess) }
|
39
47
|
|
40
48
|
let(:json_hash) do
|
41
|
-
|
42
49
|
b = { verb: 'tom',
|
43
50
|
params: 'dick',
|
44
51
|
desc: 'harry' }.to_json
|
@@ -60,66 +67,101 @@ describe Message do
|
|
60
67
|
let(:msg_cache) { Message.from_cache( json_hash.to_json ) }
|
61
68
|
|
62
69
|
|
63
|
-
describe 'Message.
|
70
|
+
describe 'Message.new' do
|
64
71
|
|
65
72
|
it 'returns a Message object' do
|
66
|
-
expect(
|
73
|
+
expect( msg_new ).to be_a_kind_of(Message)
|
67
74
|
end
|
68
75
|
|
69
|
-
it 'sets protocol attributes
|
70
|
-
expect
|
76
|
+
it 'sets protocol attributes when they are given' do
|
77
|
+
expect( msg_new.reply_to ).to eq new_hash[:replyTo]
|
78
|
+
expect( msg_new.in_reply_to ).to eq new_hash[:inReplyTo]
|
79
|
+
expect( msg_new.verb ).to eq new_hash[:verb]
|
80
|
+
expect( msg_new.params ).to eq new_hash[:parameters]
|
81
|
+
expect( msg_new.desc ).to eq new_hash[:description]
|
82
|
+
expect( symbolise msg_new.body ).to eq new_hash_body
|
83
|
+
end
|
71
84
|
|
72
|
-
|
73
|
-
|
85
|
+
it "prefers to build a body from protocol attributes" do
|
86
|
+
m = Message.new new_hash.merge(body: "foo")
|
87
|
+
expect( m.verb ).to eq new_hash[:verb]
|
88
|
+
expect( m.params ).to eq new_hash[:parameters]
|
89
|
+
expect( m.desc ).to eq new_hash[:description]
|
90
|
+
expect( symbolise m.body ).to eq new_hash_body
|
91
|
+
end
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
93
|
+
it "takes the body attribute as given if there is no verb" do
|
94
|
+
m = Message.new(body: "foo", params: "bar", desc: "baz")
|
95
|
+
expect( m.verb ).to be_nil
|
96
|
+
expect( m.params ).to be_nil
|
97
|
+
expect( m.desc ).to be_nil
|
98
|
+
expect( m.body ).to eq "foo"
|
80
99
|
end
|
81
100
|
|
82
|
-
it "
|
83
|
-
|
101
|
+
it "builds the body and protocol from stompBody if they are missing" do
|
102
|
+
m = Message.new(stompBody: new_hash_body.to_json, contentType: 'application/json')
|
103
|
+
expect( m.verb ).to eq new_hash[:verb]
|
104
|
+
expect( m.params ).to eq new_hash[:parameters]
|
105
|
+
expect( m.desc ).to eq new_hash[:description]
|
106
|
+
expect( symbolise m.body ).to eq new_hash_body
|
84
107
|
end
|
85
108
|
|
86
|
-
|
87
|
-
|
109
|
+
it "sets body from stompbody if body/verb are missing, and stompbody is not protocol" do
|
110
|
+
m = Message.new(stompBody: "waga waga")
|
111
|
+
expect( m.verb ).to be_nil
|
112
|
+
expect( m.params ).to be_nil
|
113
|
+
expect( m.desc ).to be_nil
|
114
|
+
expect( m.body ).to eq "waga waga"
|
88
115
|
|
116
|
+
m = Message.new(stompBody: "wigi wigi", contentType: "text")
|
117
|
+
expect( m.verb ).to be_nil
|
118
|
+
expect( m.params ).to be_nil
|
119
|
+
expect( m.desc ).to be_nil
|
120
|
+
expect( m.body ).to eq "wigi wigi"
|
121
|
+
end
|
89
122
|
|
90
|
-
|
123
|
+
it 'takes the content type from the input arguments' do
|
124
|
+
msg = Message.new( new_hash.merge(contentType: 'foo') )
|
125
|
+
expect( msg.content_type ).to eq "foo"
|
126
|
+
end
|
91
127
|
|
92
|
-
|
93
|
-
|
128
|
+
it "assumes a content type of JSON if one is not given" do
|
129
|
+
expect( msg_new.content_type ).to match(/json$/i)
|
94
130
|
end
|
95
131
|
|
132
|
+
it "is fine with messages not having a replyTo or a verb" do
|
133
|
+
expect{ Message.new(verb: 'thing' ) }.not_to raise_exception
|
134
|
+
expect{ Message.new(replyTo: 'foo', body: 'bar') }.not_to raise_exception
|
135
|
+
expect{ Message.new(body: 'bar') }.not_to raise_exception
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
##
|
140
|
+
|
96
141
|
|
97
|
-
|
98
|
-
expect{ Message.in_reply_to('foo') }.to raise_exception ArgumentError
|
142
|
+
describe 'Message.in_reply_to' do
|
99
143
|
|
100
|
-
|
101
|
-
|
144
|
+
it "requires a message to reply to and a hash" do
|
145
|
+
expect{ Message.in_reply_to() }.to raise_error ArgumentError
|
146
|
+
expect{ Message.in_reply_to("foo") }.to raise_error ArgumentError
|
147
|
+
expect{ Message.in_reply_to(msg_new2) }.to raise_error ArgumentError
|
148
|
+
expect{ Message.in_reply_to(msg_new2, 14) }.to raise_error ArgumentError
|
102
149
|
|
103
|
-
expect{ Message.in_reply_to(
|
150
|
+
expect{ Message.in_reply_to(msg_new2, body: "foo") }.not_to raise_error
|
104
151
|
end
|
105
152
|
|
106
|
-
it
|
107
|
-
expect(
|
108
|
-
expect( msg ).not_to eq(msg_pts)
|
153
|
+
it "raises ArgumentError if the initial message has no reply_id" do
|
154
|
+
expect{ Message.in_reply_to(msg_stomp, verb: 'foo') }.to raise_exception ArgumentError
|
109
155
|
end
|
110
156
|
|
111
|
-
it
|
112
|
-
|
113
|
-
expect( msg.
|
114
|
-
expect( msg.desc ).to eq 'Xander'
|
115
|
-
expect( msg.reply_to ).to eq 'Ripper'
|
116
|
-
|
117
|
-
# NB the reply_id (message ID) not the reply_to (the queue)
|
118
|
-
expect( msg.in_reply_to ).to eq 42
|
157
|
+
it "sets the content type from the initial message" do
|
158
|
+
msg = Message.in_reply_to(msg_new2, body: 'foo')
|
159
|
+
expect( msg.content_type ).to eq msg_new.content_type
|
119
160
|
end
|
120
161
|
|
121
|
-
it
|
122
|
-
|
162
|
+
it "sets the in_reply_to to the initial message reply_id" do
|
163
|
+
msg = Message.in_reply_to(msg_new2, body: 'foo')
|
164
|
+
expect( msg.in_reply_to ).to eq msg_new2.reply_id
|
123
165
|
end
|
124
166
|
|
125
167
|
end
|
@@ -147,6 +189,14 @@ describe Message do
|
|
147
189
|
expect( msg_stomp.in_reply_to ).to eq nil
|
148
190
|
end
|
149
191
|
|
192
|
+
it 'sets the content type to whatever the headers say it is' do
|
193
|
+
b = { verb: 'tom',
|
194
|
+
params: 'dick',
|
195
|
+
desc: 'harry' }.to_json
|
196
|
+
|
197
|
+
x = Message.from_stomp( stomp_message('barry', b) )
|
198
|
+
expect( x.content_type ).to eq 'barry'
|
199
|
+
end
|
150
200
|
|
151
201
|
context "when the message body is text" do
|
152
202
|
|
@@ -303,7 +353,7 @@ describe Message do
|
|
303
353
|
|
304
354
|
describe '#parameters' do
|
305
355
|
it 'returns the same as @param' do
|
306
|
-
expect(
|
356
|
+
expect(msg_new.parameters).to eq msg_new.params
|
307
357
|
end
|
308
358
|
end
|
309
359
|
##
|
@@ -311,38 +361,31 @@ describe Message do
|
|
311
361
|
|
312
362
|
describe '#description' do
|
313
363
|
it 'returns the same as @desc' do
|
314
|
-
expect(
|
364
|
+
expect(msg_new.description).to eq msg_new.desc
|
315
365
|
end
|
316
366
|
end
|
317
367
|
##
|
318
368
|
|
319
369
|
|
320
|
-
describe '#content_is_json?' do
|
370
|
+
describe '#content_is_json?' do
|
321
371
|
|
322
|
-
it
|
323
|
-
expect(
|
372
|
+
it "returns true if the content type is JSON" do
|
373
|
+
expect( msg_new.content_is_json? ).to be true
|
324
374
|
end
|
325
375
|
|
326
|
-
it
|
327
|
-
|
328
|
-
|
329
|
-
expect( mess.content_is_json? ).to be false
|
330
|
-
|
331
|
-
mess = Message.from_cache( {contentType: 'dunno'}.to_json )
|
332
|
-
expect( mess.content_is_json? ).to be false
|
333
|
-
|
334
|
-
mess = Message.from_cache( {horse: 'badger'}.to_json )
|
335
|
-
expect( mess.content_is_json? ).to be false
|
376
|
+
it "returns false if the content type is non-json" do
|
377
|
+
msg = Message.new( new_hash.merge(contentType: 'foo') )
|
378
|
+
expect( msg.content_type ).to eq "foo"
|
336
379
|
end
|
337
380
|
|
338
381
|
end
|
339
382
|
##
|
340
383
|
|
341
384
|
|
342
|
-
describe '#
|
385
|
+
describe '#to_h' do
|
343
386
|
|
344
387
|
it 'returns the message as a hash' do
|
345
|
-
hash =
|
388
|
+
hash = msg_new.to_h
|
346
389
|
|
347
390
|
expect( hash ).to be_a_kind_of Hash
|
348
391
|
expect( hash ).to include( replyTo: 'Daphne',
|
@@ -355,15 +398,15 @@ describe Message do
|
|
355
398
|
end
|
356
399
|
|
357
400
|
it 'always returns all the keys' do
|
358
|
-
expect( msg_stomp.
|
401
|
+
expect( msg_stomp.to_h.keys ).to include(*json_hash.keys)
|
359
402
|
end
|
360
403
|
|
361
404
|
it "returns a hash that Message.from_cache doesn''t freak out over" do
|
362
|
-
expect{ Message.from_cache(msg_cache.
|
405
|
+
expect{ Message.from_cache(msg_cache.to_h.to_json) }.
|
363
406
|
not_to raise_exception
|
364
407
|
|
365
|
-
mess = Message.from_cache(msg_cache.
|
366
|
-
expect(mess.
|
408
|
+
mess = Message.from_cache(msg_cache.to_h.to_json)
|
409
|
+
expect(mess.to_h).to include symbolise(json_hash)
|
367
410
|
end
|
368
411
|
|
369
412
|
|
@@ -373,7 +416,7 @@ describe Message do
|
|
373
416
|
|
374
417
|
describe '#protocol_json' do
|
375
418
|
it "returns the Protocol as a JSON string" do
|
376
|
-
hash = JSON.parse(
|
419
|
+
hash = JSON.parse( msg_new.protocol_json, symbolize_names: true )
|
377
420
|
|
378
421
|
expect( hash ).to include(verb: 'Velma')
|
379
422
|
|
@@ -388,46 +431,29 @@ describe Message do
|
|
388
431
|
##
|
389
432
|
|
390
433
|
|
391
|
-
describe "#
|
392
|
-
|
393
|
-
context "if the body is in JSON" do
|
394
|
-
|
395
|
-
it "returns a hash" do
|
396
|
-
x = {}
|
397
|
-
x[:stompHeaders] = {}
|
398
|
-
x[:stompBody] = @datH.to_json # JSONd twice?
|
399
|
-
x[:contentType] = "JSON"
|
400
|
-
|
401
|
-
nr = Message.from_cache(x.to_json)
|
402
|
-
expect( nr.body_to_h ).to eq @datH
|
403
|
-
end
|
434
|
+
describe "#body" do
|
404
435
|
|
436
|
+
it "returns a hash if the stomp body is in JSON" do
|
437
|
+
nr = Message.new(stompBody: new_hash.to_json, contentType: "JSON")
|
438
|
+
expect( symbolise nr.body ).to eq new_hash
|
405
439
|
end
|
406
440
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
x = {}
|
411
|
-
x["body"] = @datS
|
412
|
-
x["content-type"] = "text"
|
413
|
-
|
414
|
-
nr = Message.from_cache(x.to_json)
|
415
|
-
expect( nr.body_to_h ).to be_nil
|
441
|
+
it "returns a hash if the stomp body is not in JSON" do
|
442
|
+
x = new_hash.map{|k,v| "#{k}: #{v}" }.join("\n")
|
416
443
|
|
417
|
-
|
444
|
+
nr = Message.new(stompBody: x, contentType: "text")
|
445
|
+
expect( symbolise nr.body ).to eq new_hash
|
418
446
|
end
|
419
447
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
nr = Message.from_cache(x.to_json)
|
448
|
+
it "returns nil if the stomp body is nil(!)" do
|
449
|
+
nr = Message.new(stompBody: nil, contentType: "JSON")
|
450
|
+
expect{ nr.body }.to_not raise_exception
|
451
|
+
expect( nr.body ).to be_nil
|
452
|
+
end
|
427
453
|
|
428
|
-
|
429
|
-
|
430
|
-
|
454
|
+
it "returns the body if given and no stomp_body or verb given" do
|
455
|
+
nr = Message.new(body: "foo")
|
456
|
+
expect( nr.body ).to eq "foo"
|
431
457
|
end
|
432
458
|
|
433
459
|
end
|
@@ -437,13 +463,13 @@ describe Message do
|
|
437
463
|
describe '#headers_for_stomp' do
|
438
464
|
|
439
465
|
it 'always returns a Hash' do
|
440
|
-
expect(
|
466
|
+
expect( msg_new.headers_for_stomp ).to be_a_kind_of Hash
|
441
467
|
expect( msg_stomp.headers_for_stomp ).to be_a_kind_of Hash
|
442
468
|
expect( msg_cache.headers_for_stomp ).to be_a_kind_of Hash
|
443
469
|
end
|
444
470
|
|
445
471
|
it "returns the custom headers for the Stomp gem" do
|
446
|
-
hdrs =
|
472
|
+
hdrs = msg_new2.headers_for_stomp
|
447
473
|
expect( hdrs ).to include("content-type" => 'application/json')
|
448
474
|
expect( hdrs ).to include("neb-reply-id" => 42)
|
449
475
|
expect( hdrs ).to include("neb-reply-to" => 'Daphne')
|
@@ -451,6 +477,8 @@ describe Message do
|
|
451
477
|
|
452
478
|
hdrs = msg_stomp.headers_for_stomp
|
453
479
|
expect( hdrs ).to include("content-type" => 'application/text')
|
480
|
+
|
481
|
+
# The point of this test is?
|
454
482
|
expect( hdrs ).to include("neb-reply-id" => nil)
|
455
483
|
end
|
456
484
|
|
@@ -503,71 +531,154 @@ describe Message do
|
|
503
531
|
##
|
504
532
|
|
505
533
|
|
506
|
-
describe '#
|
534
|
+
describe '#respond_with_success' do
|
507
535
|
|
508
536
|
it "raises an error if we have no @reply_to" do
|
509
|
-
expect{ msg_stomp.
|
537
|
+
expect{ msg_stomp.respond_with_success }.to raise_exception NebulousError
|
510
538
|
end
|
511
539
|
|
512
540
|
it "returns the queue to respond on" do
|
513
|
-
q,_ = msg_cache.
|
541
|
+
q,_ = msg_cache.respond_with_success
|
514
542
|
expect( q ).to eq '/queue/thing'
|
515
543
|
end
|
516
544
|
|
517
545
|
it "returns a new message that has the success verb" do
|
518
|
-
_,m = msg_cache.
|
546
|
+
_,m = msg_cache.respond_with_success
|
519
547
|
expect( m ).to be_a_kind_of Message
|
520
548
|
expect( m.verb ).to eq 'success'
|
521
549
|
end
|
522
550
|
|
551
|
+
it 'sets the content type from the source message' do
|
552
|
+
_,m = msg_cache.respond_with_success
|
553
|
+
expect( m.content_type ).to eq msg_cache.content_type
|
554
|
+
end
|
555
|
+
|
523
556
|
end
|
524
557
|
##
|
525
558
|
|
526
559
|
|
527
|
-
describe '#
|
560
|
+
describe '#respond_with_error' do
|
528
561
|
let(:err) { NebulousError.new("test error") }
|
529
562
|
|
530
563
|
it "raises an error if we have no @reply_to" do
|
531
|
-
expect{ msg_stomp.
|
564
|
+
expect{ msg_stomp.respond_with_error('foo') }.to raise_exception NebulousError
|
532
565
|
end
|
533
566
|
|
534
567
|
it "requires an error parameter" do
|
535
|
-
expect{ msg_cache.
|
536
|
-
expect{ msg_cache.
|
568
|
+
expect{ msg_cache.respond_with_error() }.to raise_exception ArgumentError
|
569
|
+
expect{ msg_cache.respond_with_error('foo') }.not_to raise_exception
|
537
570
|
end
|
538
571
|
|
539
572
|
it "accepts an exception object" do
|
540
|
-
expect{ msg_cache.
|
573
|
+
expect{ msg_cache.respond_with_error(err) }.not_to raise_exception
|
541
574
|
end
|
542
575
|
|
543
576
|
it "accepts an optional error field" do
|
544
|
-
expect{ msg_cache.
|
577
|
+
expect{ msg_cache.respond_with_error('foo', :bar) }.not_to raise_exception
|
545
578
|
end
|
546
579
|
|
547
580
|
it "returns the queue to respond on" do
|
548
|
-
q,_ = msg_cache.
|
581
|
+
q,_ = msg_cache.respond_with_error('foo')
|
549
582
|
expect( q ).to eq '/queue/thing'
|
550
583
|
|
551
|
-
q,_ = msg_cache.
|
584
|
+
q,_ = msg_cache.respond_with_error(err, :foo)
|
552
585
|
expect( q ).to eq '/queue/thing'
|
553
586
|
end
|
554
587
|
|
555
588
|
it "returns a new message with the failure verb and details" do
|
556
|
-
_,m = msg_cache.
|
589
|
+
_,m = msg_cache.respond_with_error('foo')
|
557
590
|
expect( m ).to be_a_kind_of Message
|
558
591
|
expect( m.verb ).to eq 'error'
|
559
592
|
expect( m.params ).to eq []
|
560
593
|
expect( m.desc ).to eq 'foo'
|
561
594
|
|
562
|
-
_,m = msg_cache.
|
595
|
+
_,m = msg_cache.respond_with_error(err, :foo)
|
563
596
|
expect( m ).to be_a_kind_of Message
|
564
597
|
expect( m.verb ).to eq 'error'
|
565
|
-
expect( m.params ).to eq "foo"
|
598
|
+
expect( m.params ).to eq ["foo"]
|
566
599
|
expect( m.desc ).to eq err.message
|
567
600
|
end
|
568
601
|
|
602
|
+
it 'sets the content type from the source message' do
|
603
|
+
_,m = msg_cache.respond_with_error('foo')
|
604
|
+
expect( m.content_type ).to eq msg_cache.content_type
|
605
|
+
end
|
606
|
+
|
607
|
+
end
|
608
|
+
##
|
609
|
+
|
610
|
+
|
611
|
+
describe '#respond_with_protocol' do
|
612
|
+
|
613
|
+
it "raises an error if we have no @reply_to" do
|
614
|
+
expect{ msg_stomp.respond_with_protocol('foo') }.to raise_exception NebulousError
|
615
|
+
end
|
616
|
+
|
617
|
+
it "requires a verb parameter" do
|
618
|
+
expect{ msg_cache.respond_with_protocol() }.to raise_exception ArgumentError
|
619
|
+
expect{ msg_cache.respond_with_protocol('foo') }.not_to raise_exception
|
620
|
+
end
|
621
|
+
|
622
|
+
it "accepts optional 'parameters' and 'description' parameters" do
|
623
|
+
expect{ msg_cache.respond_with_protocol('foo', "bar") }.not_to raise_exception
|
624
|
+
expect{ msg_cache.respond_with_protocol('foo', [:a, :b]) }.not_to raise_exception
|
625
|
+
expect{ msg_cache.respond_with_protocol('foo', 'bar', 'baz') }.not_to raise_exception
|
626
|
+
end
|
627
|
+
|
628
|
+
it "returns a queue to respond on" do
|
629
|
+
q,_ = msg_cache.respond_with_protocol('foo')
|
630
|
+
expect( q ).to eq '/queue/thing'
|
631
|
+
end
|
632
|
+
|
633
|
+
it "returns a new message with the verb, params, and desc" do
|
634
|
+
_,m = msg_cache.respond_with_protocol('bleem', 'drort', 'flang')
|
635
|
+
expect( m ).to be_a_kind_of Message
|
636
|
+
expect( m.verb ).to eq 'bleem'
|
637
|
+
expect( m.params ).to eq 'drort'
|
638
|
+
expect( m.desc ).to eq 'flang'
|
639
|
+
end
|
640
|
+
|
641
|
+
it 'sets the content type from the source message' do
|
642
|
+
_,m = msg_cache.respond_with_protocol('bleem', 'drort', 'flang')
|
643
|
+
expect( m.content_type ).to eq msg_cache.content_type
|
644
|
+
end
|
645
|
+
|
646
|
+
end
|
647
|
+
##
|
648
|
+
|
649
|
+
|
650
|
+
describe '#respond' do
|
651
|
+
|
652
|
+
let(:msg) { msg_cache.respond("desmond") }
|
653
|
+
|
654
|
+
it "raises an error if we have no @reply_to" do
|
655
|
+
expect{ msg_stomp.respond('foo') }.to raise_exception NebulousError
|
656
|
+
end
|
657
|
+
|
658
|
+
it "requires a message body" do
|
659
|
+
expect{ msg_cache.respond() }.to raise_exception ArgumentError
|
660
|
+
expect{ msg }.not_to raise_exception
|
661
|
+
end
|
662
|
+
|
663
|
+
it "returns a queue to respond on" do
|
664
|
+
q,_ = msg
|
665
|
+
expect( q ).to eq '/queue/thing'
|
666
|
+
end
|
667
|
+
|
668
|
+
it "returns a new message with the given body" do
|
669
|
+
_,m = msg
|
670
|
+
expect( m ).to be_a_kind_of Message
|
671
|
+
expect( m.body ).to eq 'desmond'
|
672
|
+
end
|
673
|
+
|
674
|
+
it 'sets the content type from the source message' do
|
675
|
+
_,m = msg
|
676
|
+
expect( m.content_type ).to eq msg_cache.content_type
|
677
|
+
end
|
678
|
+
|
569
679
|
end
|
570
680
|
##
|
681
|
+
|
571
682
|
|
572
683
|
end
|
573
684
|
|
data/spec/nebulous_spec.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
1
|
require 'nebulous_stomp/param'
|
6
2
|
|
7
3
|
|
8
4
|
describe NebulousStomp do
|
9
5
|
|
10
|
-
before { NebulousStomp::Param.reset }
|
11
|
-
after(:all) { NebulousStomp::Param.reset }
|
6
|
+
before { NebulousStomp::Param.send :reset }
|
7
|
+
after(:all) { NebulousStomp::Param.send :reset }
|
12
8
|
|
13
9
|
|
14
10
|
# Magically replaces the real Param module
|
15
11
|
let(:param) { class_double(NebulousStomp::Param).as_stubbed_const }
|
16
12
|
|
13
|
+
let(:tname) {:foo}
|
14
|
+
let(:thash) { {sendQueue: "foo", receiveQueue: "bar"} }
|
15
|
+
|
17
16
|
|
18
17
|
it 'has a version number' do
|
19
18
|
expect(NebulousStomp::VERSION).not_to be nil
|
@@ -66,15 +65,50 @@ describe NebulousStomp do
|
|
66
65
|
describe 'NebulousStomp.add_target' do
|
67
66
|
|
68
67
|
it 'calls Param.add_target' do
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
expect(param).to receive(:add_target) do | t|
|
69
|
+
expect(t.name).to eq tname
|
70
|
+
expect(t.send_queue).to eq thash[:sendQueue]
|
71
|
+
expect(t.receive_queue).to eq thash[:receiveQueue]
|
72
|
+
end
|
73
|
+
|
74
|
+
NebulousStomp.add_target(tname, thash)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'returns the target object' do
|
78
|
+
t = NebulousStomp.add_target(tname, thash)
|
79
|
+
expect( t ).to be_kind_of(NebulousStomp::Target)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "adds the name to the target hash" do
|
83
|
+
t = NebulousStomp.add_target(tname, thash)
|
84
|
+
expect( t.name ).to eq tname
|
72
85
|
end
|
73
86
|
|
74
87
|
end
|
75
88
|
##
|
76
89
|
|
77
90
|
|
91
|
+
describe 'NebulousStomp.get_target' do
|
92
|
+
|
93
|
+
before do
|
94
|
+
NebulousStomp.add_target(tname, thash)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "calls Param.get_target" do
|
98
|
+
expect(param).to receive(:get_target).with(tname)
|
99
|
+
NebulousStomp.get_target(tname)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns the target object" do
|
103
|
+
t = NebulousStomp.get_target(tname)
|
104
|
+
expect( t ).to be_kind_of(NebulousStomp::Target)
|
105
|
+
expect( t.name ).to eq tname
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
##
|
110
|
+
|
111
|
+
|
78
112
|
describe 'NebulousStomp.on?' do
|
79
113
|
|
80
114
|
it 'should be true if there is anything in the stomp hash' do
|
@@ -119,6 +153,7 @@ describe NebulousStomp do
|
|
119
153
|
end
|
120
154
|
##
|
121
155
|
|
156
|
+
|
122
157
|
end
|
123
158
|
|
124
159
|
|