adhearsion 2.5.4 → 2.6.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/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/README.markdown +2 -1
- data/Rakefile +1 -6
- data/adhearsion.gemspec +4 -3
- data/features/cli_daemon.feature +2 -4
- data/features/cli_restart.feature +14 -5
- data/features/cli_start.feature +0 -2
- data/features/cli_stop.feature +15 -6
- data/lib/adhearsion.rb +21 -23
- data/lib/adhearsion/call.rb +49 -5
- data/lib/adhearsion/call_controller.rb +29 -11
- data/lib/adhearsion/call_controller/dial.rb +21 -9
- data/lib/adhearsion/call_controller/menu_dsl.rb +12 -12
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +1 -0
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/output.rb +36 -7
- data/lib/adhearsion/call_controller/output/abstract_player.rb +4 -0
- data/lib/adhearsion/call_controller/record.rb +1 -0
- data/lib/adhearsion/cli_commands/ahn_command.rb +7 -4
- data/lib/adhearsion/cli_commands/plugin_command.rb +2 -0
- data/lib/adhearsion/generators.rb +2 -4
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +20 -20
- data/lib/adhearsion/initializer.rb +2 -2
- data/lib/adhearsion/plugin.rb +6 -6
- data/lib/adhearsion/punchblock_plugin.rb +3 -4
- data/lib/adhearsion/punchblock_plugin/initializer.rb +2 -1
- data/lib/adhearsion/router.rb +7 -7
- data/lib/adhearsion/router/route.rb +10 -4
- data/lib/adhearsion/rspec.rb +2 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +589 -557
- data/spec/adhearsion/call_controller/input_spec.rb +91 -91
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +29 -29
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +19 -19
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +1 -1
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +21 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +96 -83
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +5 -5
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +9 -9
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +14 -4
- data/spec/adhearsion/call_controller/output/formatter_spec.rb +14 -14
- data/spec/adhearsion/call_controller/output/player_spec.rb +15 -5
- data/spec/adhearsion/call_controller/output_spec.rb +126 -78
- data/spec/adhearsion/call_controller/record_spec.rb +38 -26
- data/spec/adhearsion/call_controller/utility_spec.rb +11 -11
- data/spec/adhearsion/call_controller_spec.rb +176 -136
- data/spec/adhearsion/call_spec.rb +443 -218
- data/spec/adhearsion/calls_spec.rb +33 -33
- data/spec/adhearsion/configuration_spec.rb +61 -61
- data/spec/adhearsion/console_spec.rb +29 -29
- data/spec/adhearsion/events_spec.rb +14 -14
- data/spec/adhearsion/generators_spec.rb +1 -1
- data/spec/adhearsion/initializer_spec.rb +42 -42
- data/spec/adhearsion/logging_spec.rb +33 -33
- data/spec/adhearsion/outbound_call_spec.rb +69 -55
- data/spec/adhearsion/plugin_spec.rb +53 -44
- data/spec/adhearsion/process_spec.rb +21 -21
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +68 -52
- data/spec/adhearsion/punchblock_plugin_spec.rb +6 -6
- data/spec/adhearsion/router/evented_route_spec.rb +2 -2
- data/spec/adhearsion/router/openended_route_spec.rb +9 -9
- data/spec/adhearsion/router/route_spec.rb +61 -31
- data/spec/adhearsion/router/unaccepting_route_spec.rb +13 -13
- data/spec/adhearsion/router_spec.rb +47 -33
- data/spec/adhearsion/statistics/dump_spec.rb +6 -6
- data/spec/adhearsion/statistics_spec.rb +9 -9
- data/spec/adhearsion_spec.rb +23 -20
- data/spec/spec_helper.rb +3 -6
- data/spec/support/call_controller_test_helpers.rb +7 -7
- data/spec/support/initializer_stubs.rb +1 -1
- data/spec/support/punchblock_mocks.rb +1 -1
- metadata +22 -10
- data/features/support/utils.rb +0 -9
@@ -32,7 +32,7 @@ module Adhearsion
|
|
32
32
|
subject { Adhearsion::Call.new offer }
|
33
33
|
|
34
34
|
before do
|
35
|
-
offer.
|
35
|
+
allow(offer).to receive(:client).and_return(mock_client)
|
36
36
|
end
|
37
37
|
|
38
38
|
after do
|
@@ -50,49 +50,91 @@ module Adhearsion
|
|
50
50
|
foo = :bar
|
51
51
|
subject.after(1) { foo = :baz }
|
52
52
|
sleep 1.1
|
53
|
-
foo.
|
53
|
+
expect(foo).to eq(:baz)
|
54
54
|
end
|
55
55
|
|
56
|
-
it {
|
56
|
+
it { is_expected.to respond_to :<< }
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
describe '#end_reason' do
|
59
|
+
subject { super().end_reason }
|
60
|
+
it { is_expected.to eq(nil) }
|
61
|
+
end
|
62
|
+
it { is_expected.to be_active }
|
63
|
+
|
64
|
+
describe '#commands' do
|
65
|
+
subject { super().commands }
|
66
|
+
it { is_expected.to be_empty }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#id' do
|
70
|
+
subject { super().id }
|
71
|
+
it { is_expected.to eq(call_id) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#domain' do
|
75
|
+
subject { super().domain }
|
76
|
+
it { is_expected.to eq(domain) }
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#uri' do
|
80
|
+
subject { super().uri }
|
81
|
+
it { is_expected.to eq("footransport:#{call_id}@#{domain}") }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#to' do
|
85
|
+
subject { super().to }
|
86
|
+
it { is_expected.to eq(to) }
|
87
|
+
end
|
60
88
|
|
61
|
-
|
89
|
+
describe '#from' do
|
90
|
+
subject { super().from }
|
91
|
+
it { is_expected.to eq(from) }
|
92
|
+
end
|
62
93
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
its(:from) { should be == from }
|
94
|
+
describe '#auto_hangup' do
|
95
|
+
subject { super().auto_hangup }
|
96
|
+
it { is_expected.to be_truthy }
|
97
|
+
end
|
68
98
|
|
69
|
-
|
99
|
+
describe '#after_hangup_lifetime' do
|
100
|
+
subject { super().after_hangup_lifetime }
|
101
|
+
it { is_expected.to eq(nil) }
|
102
|
+
end
|
70
103
|
|
71
104
|
context "when the ID is nil" do
|
72
105
|
let(:call_id) { nil }
|
73
106
|
|
74
|
-
|
107
|
+
describe '#uri' do
|
108
|
+
subject { super().uri }
|
109
|
+
it { is_expected.to eq(nil) }
|
110
|
+
end
|
75
111
|
end
|
76
112
|
|
77
113
|
context "when the domain is nil" do
|
78
114
|
let(:domain) { nil }
|
79
115
|
|
80
|
-
|
116
|
+
describe '#uri' do
|
117
|
+
subject { super().uri }
|
118
|
+
it { is_expected.to eq("footransport:#{call_id}") }
|
119
|
+
end
|
81
120
|
end
|
82
121
|
|
83
122
|
context "when the transport is nil" do
|
84
123
|
let(:transport) { nil }
|
85
124
|
|
86
|
-
|
125
|
+
describe '#uri' do
|
126
|
+
subject { super().uri }
|
127
|
+
it { is_expected.to eq("#{call_id}@#{domain}") }
|
128
|
+
end
|
87
129
|
end
|
88
130
|
|
89
131
|
it "should mark its start time" do
|
90
|
-
subject.start_time.
|
132
|
+
expect(subject.start_time).to eq(base_time)
|
91
133
|
end
|
92
134
|
|
93
135
|
describe "#commands" do
|
94
136
|
it "should use a duplicating accessor for the command registry" do
|
95
|
-
subject.commands.
|
137
|
+
expect(subject.commands).not_to be subject.commands
|
96
138
|
end
|
97
139
|
end
|
98
140
|
|
@@ -100,15 +142,19 @@ module Adhearsion
|
|
100
142
|
context "with an offer" do
|
101
143
|
context "with headers" do
|
102
144
|
let(:headers) { {'X-foo' => 'bar'} }
|
103
|
-
|
145
|
+
|
146
|
+
describe '#variables' do
|
147
|
+
subject { super().variables }
|
148
|
+
it { is_expected.to eq({'x_foo' => 'bar'}) }
|
149
|
+
end
|
104
150
|
|
105
151
|
it "should be made available via []" do
|
106
|
-
subject[:x_foo].
|
152
|
+
expect(subject[:x_foo]).to eq('bar')
|
107
153
|
end
|
108
154
|
|
109
155
|
it "should be alterable using []=" do
|
110
156
|
subject[:x_foo] = 'baz'
|
111
|
-
subject[:x_foo].
|
157
|
+
expect(subject[:x_foo]).to eq('baz')
|
112
158
|
end
|
113
159
|
|
114
160
|
context "when receiving an event with headers" do
|
@@ -116,7 +162,7 @@ module Adhearsion
|
|
116
162
|
|
117
163
|
it "should merge later headers" do
|
118
164
|
subject << event
|
119
|
-
subject.variables.
|
165
|
+
expect(subject.variables).to eq({'x_foo' => 'bar', 'x_bar' => 'foo'})
|
120
166
|
end
|
121
167
|
|
122
168
|
context "with have symbol names" do
|
@@ -124,7 +170,7 @@ module Adhearsion
|
|
124
170
|
|
125
171
|
it "should merge later headers" do
|
126
172
|
subject << event
|
127
|
-
subject.variables.
|
173
|
+
expect(subject.variables).to eq({'x_foo' => 'bar', 'x_bar' => 'foo'})
|
128
174
|
end
|
129
175
|
end
|
130
176
|
end
|
@@ -134,26 +180,34 @@ module Adhearsion
|
|
134
180
|
|
135
181
|
it "should merge later headers" do
|
136
182
|
subject.write_command command
|
137
|
-
subject.variables.
|
183
|
+
expect(subject.variables).to eq({'x_foo' => 'bar', 'x_bar' => 'foo'})
|
138
184
|
end
|
139
185
|
end
|
140
186
|
end
|
141
187
|
|
142
188
|
context "without headers" do
|
143
189
|
let(:headers) { nil }
|
144
|
-
|
190
|
+
|
191
|
+
describe '#variables' do
|
192
|
+
subject { super().variables }
|
193
|
+
it { is_expected.to eq({}) }
|
194
|
+
end
|
145
195
|
end
|
146
196
|
end
|
147
197
|
|
148
198
|
context "without an offer" do
|
149
199
|
let(:offer) { nil }
|
150
|
-
|
200
|
+
|
201
|
+
describe '#variables' do
|
202
|
+
subject { super().variables }
|
203
|
+
it { is_expected.to eq({}) }
|
204
|
+
end
|
151
205
|
end
|
152
206
|
end
|
153
207
|
|
154
208
|
describe 'without an offer' do
|
155
209
|
it 'should not raise an exception' do
|
156
|
-
|
210
|
+
expect { Adhearsion::Call.new }.not_to raise_error
|
157
211
|
end
|
158
212
|
end
|
159
213
|
|
@@ -162,8 +216,8 @@ module Adhearsion
|
|
162
216
|
let(:response) { double 'Response' }
|
163
217
|
|
164
218
|
it 'are called when messages are delivered' do
|
165
|
-
event.
|
166
|
-
response.
|
219
|
+
expect(event).to receive(:foo?).and_return true
|
220
|
+
expect(response).to receive(:call).once
|
167
221
|
subject.register_event_handler(:foo?) { response.call }
|
168
222
|
subject << event
|
169
223
|
end
|
@@ -172,18 +226,18 @@ module Adhearsion
|
|
172
226
|
it 'does not cause the call actor to crash' do
|
173
227
|
subject.register_event_handler { raise 'Boom' }
|
174
228
|
subject << event
|
175
|
-
subject.
|
229
|
+
expect(subject).to be_alive
|
176
230
|
end
|
177
231
|
|
178
232
|
it "triggers an exception event" do
|
179
233
|
e = StandardError.new('Boom')
|
180
|
-
Events.
|
234
|
+
expect(Events).to receive(:trigger).once.with(:exception, [e, subject.logger])
|
181
235
|
subject.register_event_handler { raise e }
|
182
236
|
subject << event
|
183
237
|
end
|
184
238
|
|
185
239
|
it 'executes all handlers for each event' do
|
186
|
-
response.
|
240
|
+
expect(response).to receive(:call).once
|
187
241
|
subject.register_event_handler { raise 'Boom' }
|
188
242
|
subject.register_event_handler { response.call }
|
189
243
|
subject << event
|
@@ -201,33 +255,33 @@ module Adhearsion
|
|
201
255
|
end
|
202
256
|
|
203
257
|
it "should trigger any on_joined callbacks set for the matching call ID" do
|
204
|
-
response.
|
258
|
+
expect(response).to receive(:call).once.with(event)
|
205
259
|
subject.on_joined(:call_uri => 'footransport:foobar@rayo.net') { |event| response.call event }
|
206
260
|
subject << event
|
207
261
|
end
|
208
262
|
|
209
263
|
it "should trigger any on_joined callbacks set for the matching call ID as a string" do
|
210
|
-
response.
|
264
|
+
expect(response).to receive(:call).once.with(event)
|
211
265
|
subject.on_joined('foobar') { |event| response.call event }
|
212
266
|
subject << event
|
213
267
|
end
|
214
268
|
|
215
269
|
it "should trigger any on_joined callbacks set for the matching call" do
|
216
|
-
response.
|
270
|
+
expect(response).to receive(:call).once.with(event)
|
217
271
|
call = Call.new
|
218
|
-
call.wrapped_object.
|
272
|
+
allow(call.wrapped_object).to receive_messages id: 'foobar', domain: 'rayo.net', transport: 'footransport'
|
219
273
|
subject.on_joined(call) { |event| response.call event }
|
220
274
|
subject << event
|
221
275
|
end
|
222
276
|
|
223
277
|
it "should not trigger on_joined callbacks for other call IDs" do
|
224
|
-
response.
|
278
|
+
expect(response).to receive(:call).never
|
225
279
|
subject.on_joined(:call_uri => 'barfoo') { |event| response.call event }
|
226
280
|
subject << event
|
227
281
|
end
|
228
282
|
|
229
283
|
it "should not trigger on_joined callbacks for mixers" do
|
230
|
-
response.
|
284
|
+
expect(response).to receive(:call).never
|
231
285
|
subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
|
232
286
|
subject << event
|
233
287
|
end
|
@@ -239,33 +293,33 @@ module Adhearsion
|
|
239
293
|
end
|
240
294
|
|
241
295
|
it "should trigger on_joined callbacks for the matching mixer name" do
|
242
|
-
response.
|
296
|
+
expect(response).to receive(:call).once.with(event)
|
243
297
|
subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
|
244
298
|
subject << event
|
245
299
|
end
|
246
300
|
|
247
301
|
it "should not trigger on_joined callbacks for other mixer names" do
|
248
|
-
response.
|
302
|
+
expect(response).to receive(:call).never
|
249
303
|
subject.on_joined(:mixer_name => 'barfoo') { |event| response.call event }
|
250
304
|
subject << event
|
251
305
|
end
|
252
306
|
|
253
307
|
it "should not trigger any on_joined callbacks set for calls" do
|
254
|
-
response.
|
308
|
+
expect(response).to receive(:call).never
|
255
309
|
subject.on_joined(:call_uri => 'foobar') { |event| response.call event }
|
256
310
|
subject << event
|
257
311
|
end
|
258
312
|
|
259
313
|
it "should not trigger any on_joined callbacks set for the matching call ID as a string" do
|
260
|
-
response.
|
314
|
+
expect(response).to receive(:call).never
|
261
315
|
subject.on_joined('foobar') { |event| response.call event }
|
262
316
|
subject << event
|
263
317
|
end
|
264
318
|
|
265
319
|
it "should not trigger any on_joined callbacks set for the matching call" do
|
266
|
-
response.
|
320
|
+
expect(response).to receive(:call).never
|
267
321
|
call = Call.new
|
268
|
-
call.wrapped_object.
|
322
|
+
allow(call.wrapped_object).to receive_messages :id => 'foobar'
|
269
323
|
subject.on_joined(call) { |event| response.call event }
|
270
324
|
subject << event
|
271
325
|
end
|
@@ -279,33 +333,33 @@ module Adhearsion
|
|
279
333
|
end
|
280
334
|
|
281
335
|
it "should trigger any on_unjoined callbacks set for the matching call ID" do
|
282
|
-
response.
|
336
|
+
expect(response).to receive(:call).once.with(event)
|
283
337
|
subject.on_unjoined(:call_uri => 'footransport:foobar@rayo.net') { |event| response.call event }
|
284
338
|
subject << event
|
285
339
|
end
|
286
340
|
|
287
341
|
it "should trigger any on_unjoined callbacks set for the matching call ID as a string" do
|
288
|
-
response.
|
342
|
+
expect(response).to receive(:call).once.with(event)
|
289
343
|
subject.on_unjoined('foobar') { |event| response.call event }
|
290
344
|
subject << event
|
291
345
|
end
|
292
346
|
|
293
347
|
it "should trigger any on_unjoined callbacks set for the matching call" do
|
294
|
-
response.
|
348
|
+
expect(response).to receive(:call).once.with(event)
|
295
349
|
call = Call.new
|
296
|
-
call.wrapped_object.
|
350
|
+
allow(call.wrapped_object).to receive_messages id: 'foobar', domain: 'rayo.net', transport: 'footransport'
|
297
351
|
subject.on_unjoined(call) { |event| response.call event }
|
298
352
|
subject << event
|
299
353
|
end
|
300
354
|
|
301
355
|
it "should not trigger on_unjoined callbacks for other call IDs" do
|
302
|
-
response.
|
356
|
+
expect(response).to receive(:call).never
|
303
357
|
subject.on_unjoined(:call_uri => 'barfoo') { |event| response.call event }
|
304
358
|
subject << event
|
305
359
|
end
|
306
360
|
|
307
361
|
it "should not trigger on_unjoined callbacks for mixers" do
|
308
|
-
response.
|
362
|
+
expect(response).to receive(:call).never
|
309
363
|
subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
|
310
364
|
subject << event
|
311
365
|
end
|
@@ -317,33 +371,33 @@ module Adhearsion
|
|
317
371
|
end
|
318
372
|
|
319
373
|
it "should trigger on_unjoined callbacks for the matching mixer name" do
|
320
|
-
response.
|
374
|
+
expect(response).to receive(:call).once.with(event)
|
321
375
|
subject.on_unjoined(:mixer_name => 'foobar') { |event| response.call event }
|
322
376
|
subject << event
|
323
377
|
end
|
324
378
|
|
325
379
|
it "should not trigger on_unjoined callbacks for other mixer names" do
|
326
|
-
response.
|
380
|
+
expect(response).to receive(:call).never
|
327
381
|
subject.on_unjoined(:mixer_name => 'barfoo') { |event| response.call event }
|
328
382
|
subject << event
|
329
383
|
end
|
330
384
|
|
331
385
|
it "should not trigger any on_unjoined callbacks set for calls" do
|
332
|
-
response.
|
386
|
+
expect(response).to receive(:call).never
|
333
387
|
subject.on_unjoined(:call_uri => 'foobar') { |event| response.call event }
|
334
388
|
subject << event
|
335
389
|
end
|
336
390
|
|
337
391
|
it "should not trigger any on_unjoined callbacks set for the matching call ID as a string" do
|
338
|
-
response.
|
392
|
+
expect(response).to receive(:call).never
|
339
393
|
subject.on_unjoined('foobar') { |event| response.call event }
|
340
394
|
subject << event
|
341
395
|
end
|
342
396
|
|
343
397
|
it "should not trigger any on_unjoined callbacks set for the matching call" do
|
344
|
-
response.
|
398
|
+
expect(response).to receive(:call).never
|
345
399
|
call = Call.new
|
346
|
-
call.wrapped_object.
|
400
|
+
allow(call.wrapped_object).to receive_messages :id => 'foobar'
|
347
401
|
subject.on_unjoined(call) { |event| response.call event }
|
348
402
|
subject << event
|
349
403
|
end
|
@@ -356,7 +410,7 @@ module Adhearsion
|
|
356
410
|
end
|
357
411
|
|
358
412
|
it "should trigger any on_end callbacks set" do
|
359
|
-
response.
|
413
|
+
expect(response).to receive(:call).once.with(event)
|
360
414
|
subject.on_end { |event| response.call event }
|
361
415
|
subject << event
|
362
416
|
end
|
@@ -365,21 +419,21 @@ module Adhearsion
|
|
365
419
|
context "when raising an exception" do
|
366
420
|
it "does not kill the call actor" do
|
367
421
|
subject.register_event_handler { |e| raise 'foo' }
|
368
|
-
|
422
|
+
expect { subject << :foo }.not_to raise_error
|
369
423
|
sleep 1
|
370
|
-
subject.
|
424
|
+
expect(subject).to be_alive
|
371
425
|
end
|
372
426
|
|
373
427
|
it 'passes the exception through the Events system' do
|
374
428
|
latch = CountDownLatch.new 1
|
375
429
|
Adhearsion::Events.exception do |e, l|
|
376
|
-
e.
|
377
|
-
l.
|
430
|
+
expect(e).to be_a RuntimeError
|
431
|
+
expect(l).to be subject.logger
|
378
432
|
latch.countdown!
|
379
433
|
end
|
380
434
|
subject.register_event_handler { |e| raise 'foo' }
|
381
|
-
|
382
|
-
latch.wait(3).
|
435
|
+
expect { subject << :foo }.not_to raise_error
|
436
|
+
expect(latch.wait(3)).to be true
|
383
437
|
Adhearsion::Events.clear_handlers :exception
|
384
438
|
end
|
385
439
|
end
|
@@ -389,7 +443,7 @@ module Adhearsion
|
|
389
443
|
let(:other_call_uri) { 'xmpp:foobar@example.com' }
|
390
444
|
let(:other_call) { Call.new }
|
391
445
|
|
392
|
-
before { other_call.
|
446
|
+
before { allow(other_call).to receive_messages uri: other_call_uri }
|
393
447
|
|
394
448
|
let :joined_event do
|
395
449
|
Punchblock::Event::Joined.new call_uri: other_call_uri
|
@@ -405,7 +459,7 @@ module Adhearsion
|
|
405
459
|
|
406
460
|
it "should add the peer to its registry" do
|
407
461
|
subject << joined_event
|
408
|
-
subject.peers.
|
462
|
+
expect(subject.peers).to eq({'xmpp:foobar@example.com' => other_call})
|
409
463
|
end
|
410
464
|
|
411
465
|
context "in a handler for the joined event" do
|
@@ -418,7 +472,7 @@ module Adhearsion
|
|
418
472
|
|
419
473
|
subject << joined_event
|
420
474
|
|
421
|
-
peer.
|
475
|
+
expect(peer).to eq(other_call_uri)
|
422
476
|
end
|
423
477
|
end
|
424
478
|
|
@@ -426,9 +480,9 @@ module Adhearsion
|
|
426
480
|
before { subject << joined_event }
|
427
481
|
|
428
482
|
it "should remove the peer from its registry" do
|
429
|
-
subject.peers.
|
483
|
+
expect(subject.peers).not_to eql({})
|
430
484
|
subject << unjoined_event
|
431
|
-
subject.peers.
|
485
|
+
expect(subject.peers).to eql({})
|
432
486
|
end
|
433
487
|
|
434
488
|
context "in a handler for the unjoined event" do
|
@@ -441,7 +495,7 @@ module Adhearsion
|
|
441
495
|
|
442
496
|
subject << unjoined_event
|
443
497
|
|
444
|
-
peer_count.
|
498
|
+
expect(peer_count).to eq(0)
|
445
499
|
end
|
446
500
|
end
|
447
501
|
end
|
@@ -450,7 +504,7 @@ module Adhearsion
|
|
450
504
|
context "when we don't know about the joined call" do
|
451
505
|
it "should add a nil entry to its registry" do
|
452
506
|
subject << joined_event
|
453
|
-
subject.peers.
|
507
|
+
expect(subject.peers).to eq({'xmpp:foobar@example.com' => nil})
|
454
508
|
end
|
455
509
|
|
456
510
|
context "in a handler for the joined event" do
|
@@ -463,7 +517,7 @@ module Adhearsion
|
|
463
517
|
|
464
518
|
subject << joined_event
|
465
519
|
|
466
|
-
peer.
|
520
|
+
expect(peer).to eq(other_call_uri)
|
467
521
|
end
|
468
522
|
end
|
469
523
|
|
@@ -471,9 +525,9 @@ module Adhearsion
|
|
471
525
|
before { subject << joined_event }
|
472
526
|
|
473
527
|
it "should remove the peer from its registry" do
|
474
|
-
subject.peers.
|
528
|
+
expect(subject.peers).not_to eql({})
|
475
529
|
subject << unjoined_event
|
476
|
-
subject.peers.
|
530
|
+
expect(subject.peers).to eql({})
|
477
531
|
end
|
478
532
|
|
479
533
|
context "in a handler for the unjoined event" do
|
@@ -486,14 +540,14 @@ module Adhearsion
|
|
486
540
|
|
487
541
|
subject << unjoined_event
|
488
542
|
|
489
|
-
peer_count.
|
543
|
+
expect(peer_count).to eq(0)
|
490
544
|
end
|
491
545
|
end
|
492
546
|
end
|
493
547
|
end
|
494
548
|
|
495
549
|
it "should not return the same registry every call" do
|
496
|
-
subject.peers.
|
550
|
+
expect(subject.peers).not_to be subject.peers
|
497
551
|
end
|
498
552
|
end
|
499
553
|
|
@@ -505,25 +559,25 @@ module Adhearsion
|
|
505
559
|
|
506
560
|
it "should mark the call as ended" do
|
507
561
|
subject << end_event
|
508
|
-
subject.
|
562
|
+
expect(subject).not_to be_active
|
509
563
|
end
|
510
564
|
|
511
565
|
it "should set the end reason" do
|
512
566
|
subject << end_event
|
513
|
-
subject.end_reason.
|
567
|
+
expect(subject.end_reason).to eq(:hangup)
|
514
568
|
end
|
515
569
|
|
516
570
|
it "should set the end code" do
|
517
571
|
subject << end_event
|
518
|
-
subject.end_code.
|
572
|
+
expect(subject.end_code).to eq('arbitrary_code')
|
519
573
|
end
|
520
574
|
|
521
575
|
it "should set the end time" do
|
522
576
|
finish_time = Time.local(2008, 9, 1, 12, 1, 3)
|
523
577
|
Timecop.freeze finish_time
|
524
|
-
subject.end_time.
|
578
|
+
expect(subject.end_time).to eq(nil)
|
525
579
|
subject << end_event
|
526
|
-
subject.end_time.
|
580
|
+
expect(subject.end_time).to eq(finish_time)
|
527
581
|
end
|
528
582
|
|
529
583
|
it "should set the call duration" do
|
@@ -534,7 +588,7 @@ module Adhearsion
|
|
534
588
|
mid_point_time = Time.local(2008, 9, 1, 12, 0, 37)
|
535
589
|
Timecop.freeze mid_point_time
|
536
590
|
|
537
|
-
subject.duration.
|
591
|
+
expect(subject.duration).to eq(37.0)
|
538
592
|
|
539
593
|
finish_time = Time.local(2008, 9, 1, 12, 1, 3)
|
540
594
|
Timecop.freeze finish_time
|
@@ -544,7 +598,7 @@ module Adhearsion
|
|
544
598
|
future_time = Time.local(2008, 9, 1, 12, 2, 3)
|
545
599
|
Timecop.freeze finish_time
|
546
600
|
|
547
|
-
subject.duration.
|
601
|
+
expect(subject.duration).to eq(63.0)
|
548
602
|
end
|
549
603
|
|
550
604
|
it "should instruct the command registry to terminate" do
|
@@ -552,25 +606,58 @@ module Adhearsion
|
|
552
606
|
command.request!
|
553
607
|
subject.future.write_and_await_response command
|
554
608
|
subject << end_event
|
555
|
-
command.response(1).
|
609
|
+
expect(command.response(1)).to be_a Call::Hangup
|
556
610
|
end
|
557
611
|
|
558
612
|
it "removes itself from the active calls" do
|
559
613
|
size_before = Adhearsion.active_calls.size
|
560
614
|
|
561
615
|
Adhearsion.active_calls << subject
|
562
|
-
Adhearsion.active_calls.size.
|
616
|
+
expect(Adhearsion.active_calls.size).to be > size_before
|
563
617
|
|
564
618
|
subject << end_event
|
565
|
-
Adhearsion.active_calls.size.
|
619
|
+
expect(Adhearsion.active_calls.size).to eq(size_before)
|
566
620
|
end
|
567
621
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
622
|
+
context "with no custom lifetime" do
|
623
|
+
around do |example|
|
624
|
+
old_val = Adhearsion.config.platform.after_hangup_lifetime
|
625
|
+
begin
|
626
|
+
example.run
|
627
|
+
rescue
|
628
|
+
Adhearsion.config.platform.after_hangup_lifetime = old_val
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
it "shuts down the actor using platform config" do
|
633
|
+
Adhearsion.config.platform.after_hangup_lifetime = 2
|
634
|
+
subject << end_event
|
635
|
+
sleep 2.1
|
636
|
+
expect(subject.alive?).to be false
|
637
|
+
expect { subject.id }.to raise_error Call::ExpiredError, /expired and is no longer accessible/
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
context "with a custom lifetime" do
|
642
|
+
around do |example|
|
643
|
+
old_val = Adhearsion.config.platform.after_hangup_lifetime
|
644
|
+
begin
|
645
|
+
example.run
|
646
|
+
rescue
|
647
|
+
Adhearsion.config.platform.after_hangup_lifetime = old_val
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
it "shuts down the actor using the Call#after_hangup_lifetime" do
|
652
|
+
Adhearsion.config.platform.after_hangup_lifetime = 1
|
653
|
+
subject.after_hangup_lifetime = 2
|
654
|
+
subject << end_event
|
655
|
+
sleep 1.1
|
656
|
+
expect(subject.alive?).to be true
|
657
|
+
sleep 1
|
658
|
+
expect(subject.alive?).to be false
|
659
|
+
expect { subject.id }.to raise_error Call::ExpiredError, /expired and is no longer accessible/
|
660
|
+
end
|
574
661
|
end
|
575
662
|
end
|
576
663
|
end
|
@@ -584,7 +671,7 @@ module Adhearsion
|
|
584
671
|
before { subject << end_event }
|
585
672
|
|
586
673
|
it "should return the end reason" do
|
587
|
-
subject.wait_for_end.
|
674
|
+
expect(subject.wait_for_end).to eq(:hangup)
|
588
675
|
end
|
589
676
|
end
|
590
677
|
|
@@ -593,35 +680,35 @@ module Adhearsion
|
|
593
680
|
fut = subject.future.wait_for_end
|
594
681
|
|
595
682
|
sleep 0.5
|
596
|
-
fut.
|
683
|
+
expect(fut).not_to be_ready
|
597
684
|
|
598
685
|
subject << end_event
|
599
686
|
|
600
|
-
fut.value.
|
687
|
+
expect(fut.value).to eq(:hangup)
|
601
688
|
end
|
602
689
|
end
|
603
690
|
end
|
604
691
|
|
605
692
|
describe "tagging a call" do
|
606
693
|
it 'with a single Symbol' do
|
607
|
-
|
694
|
+
expect {
|
608
695
|
subject.tag :moderator
|
609
|
-
}.
|
696
|
+
}.not_to raise_error
|
610
697
|
end
|
611
698
|
|
612
699
|
it 'with multiple Symbols' do
|
613
|
-
|
700
|
+
expect {
|
614
701
|
subject.tag :moderator
|
615
702
|
subject.tag :female
|
616
|
-
}.
|
703
|
+
}.not_to raise_error
|
617
704
|
end
|
618
705
|
|
619
706
|
it 'with a non-Symbol, non-String object' do
|
620
707
|
bad_objects = [123, Object.new, 888.88, nil, true, false, StringIO.new]
|
621
708
|
bad_objects.each do |bad_object|
|
622
|
-
|
709
|
+
expect {
|
623
710
|
subject.tag bad_object
|
624
|
-
}.
|
711
|
+
}.to raise_error ArgumentError
|
625
712
|
end
|
626
713
|
end
|
627
714
|
end
|
@@ -631,21 +718,21 @@ module Adhearsion
|
|
631
718
|
subject.tag :female
|
632
719
|
subject.remove_tag :female
|
633
720
|
subject.tag :male
|
634
|
-
subject.tags.
|
721
|
+
expect(subject.tags).to eq([:moderator, :male])
|
635
722
|
end
|
636
723
|
|
637
724
|
describe "#tagged_with?" do
|
638
725
|
it 'with one tag' do
|
639
726
|
subject.tag :guest
|
640
|
-
subject.tagged_with?(:guest).
|
641
|
-
subject.tagged_with?(:authorized).
|
727
|
+
expect(subject.tagged_with?(:guest)).to be true
|
728
|
+
expect(subject.tagged_with?(:authorized)).to be false
|
642
729
|
end
|
643
730
|
|
644
731
|
it 'with many tags' do
|
645
732
|
subject.tag :customer
|
646
733
|
subject.tag :authorized
|
647
|
-
subject.tagged_with?(:customer).
|
648
|
-
subject.tagged_with?(:authorized).
|
734
|
+
expect(subject.tagged_with?(:customer)).to be true
|
735
|
+
expect(subject.tagged_with?(:authorized)).to be true
|
649
736
|
end
|
650
737
|
end
|
651
738
|
|
@@ -653,25 +740,25 @@ module Adhearsion
|
|
653
740
|
let(:command) { Punchblock::Command::Answer.new }
|
654
741
|
|
655
742
|
it "should write the command to the Punchblock connection" do
|
656
|
-
subject.wrapped_object.
|
657
|
-
mock_client.
|
743
|
+
expect(subject.wrapped_object).to receive(:client).once.and_return mock_client
|
744
|
+
expect(mock_client).to receive(:execute_command).once.with(Punchblock::Command::Answer.new(target_call_id: call_id, domain: domain)).and_return true
|
658
745
|
subject.write_command command
|
659
746
|
end
|
660
747
|
|
661
748
|
describe "with a hungup call" do
|
662
749
|
before do
|
663
|
-
subject.wrapped_object.
|
750
|
+
expect(subject.wrapped_object).to receive(:active?).and_return(false)
|
664
751
|
end
|
665
752
|
|
666
753
|
it "should raise a Hangup exception" do
|
667
|
-
|
754
|
+
expect { subject.write_command command }.to raise_error(Call::Hangup)
|
668
755
|
end
|
669
756
|
|
670
757
|
describe "if the command is a Hangup" do
|
671
758
|
let(:command) { Punchblock::Command::Hangup.new }
|
672
759
|
|
673
760
|
it "should not raise a Hangup exception" do
|
674
|
-
|
761
|
+
expect { subject.write_command command }.not_to raise_error
|
675
762
|
end
|
676
763
|
end
|
677
764
|
end
|
@@ -682,18 +769,18 @@ module Adhearsion
|
|
682
769
|
let(:response) { :foo }
|
683
770
|
|
684
771
|
before do
|
685
|
-
message.
|
772
|
+
expect(message).to receive(:execute!).and_return true
|
686
773
|
message.response = response
|
687
774
|
end
|
688
775
|
|
689
776
|
it "writes a command to the call" do
|
690
|
-
subject.wrapped_object.
|
777
|
+
expect(subject.wrapped_object).to receive(:write_command).once.with(message)
|
691
778
|
subject.write_and_await_response message
|
692
779
|
end
|
693
780
|
|
694
781
|
it "removes the command from the registry after execution" do
|
695
782
|
subject.write_and_await_response message
|
696
|
-
subject.commands.
|
783
|
+
expect(subject.commands).to be_empty
|
697
784
|
end
|
698
785
|
|
699
786
|
it "blocks until a response is received" do
|
@@ -705,7 +792,7 @@ module Adhearsion
|
|
705
792
|
end
|
706
793
|
starting_time = Time.now
|
707
794
|
subject.write_and_await_response slow_command
|
708
|
-
(Time.now - starting_time).
|
795
|
+
expect(Time.now - starting_time).to be >= 0.5
|
709
796
|
end
|
710
797
|
|
711
798
|
context "while waiting for a response" do
|
@@ -715,7 +802,7 @@ module Adhearsion
|
|
715
802
|
|
716
803
|
it "does not block the whole actor while waiting for a response" do
|
717
804
|
fut = subject.future.write_and_await_response slow_command
|
718
|
-
subject.id.
|
805
|
+
expect(subject.id).to eq(call_id)
|
719
806
|
slow_command.response = response
|
720
807
|
fut.value
|
721
808
|
end
|
@@ -723,14 +810,14 @@ module Adhearsion
|
|
723
810
|
it "adds the command to the registry" do
|
724
811
|
subject.future.write_and_await_response slow_command
|
725
812
|
sleep 0.2
|
726
|
-
subject.commands.
|
727
|
-
subject.commands.first.
|
813
|
+
expect(subject.commands).not_to be_empty
|
814
|
+
expect(subject.commands.first).to be slow_command
|
728
815
|
end
|
729
816
|
end
|
730
817
|
|
731
818
|
describe "with a successful response" do
|
732
819
|
it "returns the executed command" do
|
733
|
-
subject.write_and_await_response(message).
|
820
|
+
expect(subject.write_and_await_response(message)).to be message
|
734
821
|
end
|
735
822
|
end
|
736
823
|
|
@@ -739,16 +826,16 @@ module Adhearsion
|
|
739
826
|
let(:response) { new_exception.new }
|
740
827
|
|
741
828
|
it "raises the error" do
|
742
|
-
Events.
|
743
|
-
|
829
|
+
expect(Events).to receive(:trigger).never
|
830
|
+
expect { subject.write_and_await_response message }.to raise_error new_exception
|
744
831
|
end
|
745
832
|
|
746
833
|
context "where the name is :item_not_found" do
|
747
834
|
let(:response) { new_exception.new.setup :item_not_found }
|
748
835
|
|
749
836
|
it "should raise a Hangup exception" do
|
750
|
-
Events.
|
751
|
-
|
837
|
+
expect(Events).to receive(:trigger).never
|
838
|
+
expect { subject.write_and_await_response message }.to raise_error Call::Hangup
|
752
839
|
end
|
753
840
|
end
|
754
841
|
end
|
@@ -757,34 +844,34 @@ module Adhearsion
|
|
757
844
|
before do
|
758
845
|
message.target_call_id = call_id
|
759
846
|
message.domain = domain
|
760
|
-
message.
|
847
|
+
expect(message).to receive(:response).and_raise Timeout::Error
|
761
848
|
end
|
762
849
|
|
763
850
|
it "should raise the error in the caller but not crash the actor" do
|
764
|
-
|
851
|
+
expect { subject.write_and_await_response message }.to raise_error Call::CommandTimeout, message.to_s
|
765
852
|
sleep 0.5
|
766
|
-
subject.
|
853
|
+
expect(subject).to be_alive
|
767
854
|
end
|
768
855
|
end
|
769
856
|
end
|
770
857
|
|
771
858
|
describe "#send_message" do
|
772
859
|
it "should send a message through the Punchblock connection using the call ID and domain" do
|
773
|
-
subject.wrapped_object.
|
774
|
-
mock_client.
|
860
|
+
expect(subject.wrapped_object).to receive(:client).once.and_return mock_client
|
861
|
+
expect(mock_client).to receive(:send_message).once.with(subject.id, subject.domain, "Hello World!", {})
|
775
862
|
subject.send_message "Hello World!"
|
776
863
|
end
|
777
864
|
|
778
865
|
it "should send a message with the given subject" do
|
779
|
-
subject.wrapped_object.
|
780
|
-
mock_client.
|
866
|
+
expect(subject.wrapped_object).to receive(:client).once.and_return mock_client
|
867
|
+
expect(mock_client).to receive(:send_message).once.with(subject.id, subject.domain, nil, :subject => "Important Message")
|
781
868
|
subject.send_message nil, :subject => "Important Message"
|
782
869
|
end
|
783
870
|
end
|
784
871
|
|
785
872
|
describe "basic control commands" do
|
786
873
|
def expect_message_waiting_for_response(message = nil, fail = false, &block)
|
787
|
-
expectation = subject.wrapped_object.
|
874
|
+
expectation = expect(subject.wrapped_object).to receive(:write_and_await_response, &block).once
|
788
875
|
expectation = expectation.with message if message
|
789
876
|
if fail
|
790
877
|
expectation.and_raise fail
|
@@ -816,6 +903,16 @@ module Adhearsion
|
|
816
903
|
subject.accept
|
817
904
|
end
|
818
905
|
end
|
906
|
+
|
907
|
+
context "with a failure response" do
|
908
|
+
it 'should raise the error but not crash the actor' do
|
909
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
910
|
+
expect_message_waiting_for_response Punchblock::Command::Accept.new, error
|
911
|
+
expect { subject.accept }.to raise_error error
|
912
|
+
sleep 0.2
|
913
|
+
expect(subject.alive?).to be true
|
914
|
+
end
|
915
|
+
end
|
819
916
|
end
|
820
917
|
|
821
918
|
describe '#answer' do
|
@@ -833,6 +930,16 @@ module Adhearsion
|
|
833
930
|
subject.answer headers
|
834
931
|
end
|
835
932
|
end
|
933
|
+
|
934
|
+
context "with a failure response" do
|
935
|
+
it 'should raise the error but not crash the actor' do
|
936
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
937
|
+
expect_message_waiting_for_response Punchblock::Command::Answer.new, error
|
938
|
+
expect { subject.answer }.to raise_error error
|
939
|
+
sleep 0.2
|
940
|
+
expect(subject.alive?).to be true
|
941
|
+
end
|
942
|
+
end
|
836
943
|
end
|
837
944
|
|
838
945
|
describe '#reject' do
|
@@ -871,20 +978,74 @@ module Adhearsion
|
|
871
978
|
|
872
979
|
it "should immediately fire the :call_rejected event giving the call and the reason" do
|
873
980
|
expect_message_waiting_for_response kind_of(Punchblock::Command::Reject)
|
874
|
-
Adhearsion::Events.
|
981
|
+
expect(Adhearsion::Events).to receive(:trigger_immediately).once.with(:call_rejected, :call => subject, :reason => :decline)
|
875
982
|
subject.reject :decline
|
876
983
|
end
|
984
|
+
|
985
|
+
context "with a failure response" do
|
986
|
+
it 'should raise the error but not crash the actor' do
|
987
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
988
|
+
expect_message_waiting_for_response Punchblock::Command::Reject.new(reason: :busy), error
|
989
|
+
expect { subject.reject }.to raise_error error
|
990
|
+
sleep 0.2
|
991
|
+
expect(subject.alive?).to be true
|
992
|
+
end
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
describe '#redirect' do
|
997
|
+
describe "with a target given" do
|
998
|
+
it 'should send a Redirect message with the correct target' do
|
999
|
+
expect_message_waiting_for_response Punchblock::Command::Redirect.new(to: 'sip:foo@bar.com')
|
1000
|
+
subject.redirect 'sip:foo@bar.com'
|
1001
|
+
end
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
describe "with no target given" do
|
1005
|
+
it 'should raise with ArgumentError' do
|
1006
|
+
expect { subject.redirect }.to raise_error(ArgumentError)
|
1007
|
+
end
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
describe "with no headers" do
|
1011
|
+
it 'should send a Redirect message' do
|
1012
|
+
expect_message_waiting_for_response do |c|
|
1013
|
+
c.is_a?(Punchblock::Command::Redirect) && c.headers == {}
|
1014
|
+
end
|
1015
|
+
subject.redirect 'sip:foo@bar.com'
|
1016
|
+
end
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
describe "with headers set" do
|
1020
|
+
it 'should send a Redirect message with the correct headers' do
|
1021
|
+
headers = {:foo => 'bar'}
|
1022
|
+
expect_message_waiting_for_response do |c|
|
1023
|
+
c.is_a?(Punchblock::Command::Redirect) && c.headers == headers
|
1024
|
+
end
|
1025
|
+
subject.redirect 'sip:foo@bar.com', headers
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
context "with a failure response" do
|
1030
|
+
it 'should raise the error but not crash the actor' do
|
1031
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1032
|
+
expect_message_waiting_for_response Punchblock::Command::Redirect.new(to: 'sip:foo@bar.com'), error
|
1033
|
+
expect { subject.redirect 'sip:foo@bar.com' }.to raise_error error
|
1034
|
+
sleep 0.2
|
1035
|
+
expect(subject.alive?).to be true
|
1036
|
+
end
|
1037
|
+
end
|
877
1038
|
end
|
878
1039
|
|
879
1040
|
describe "#hangup" do
|
880
1041
|
describe "if the call is not active" do
|
881
1042
|
before do
|
882
|
-
subject.wrapped_object.
|
1043
|
+
expect(subject.wrapped_object).to receive(:active?).and_return false
|
883
1044
|
end
|
884
1045
|
|
885
1046
|
it "should do nothing and return false" do
|
886
|
-
subject.
|
887
|
-
subject.hangup.
|
1047
|
+
expect(subject).to receive(:write_and_await_response).never
|
1048
|
+
expect(subject.hangup).to be false
|
888
1049
|
end
|
889
1050
|
end
|
890
1051
|
|
@@ -892,7 +1053,7 @@ module Adhearsion
|
|
892
1053
|
it "should mark the call inactive" do
|
893
1054
|
expect_message_waiting_for_response Punchblock::Command::Hangup.new
|
894
1055
|
subject.hangup
|
895
|
-
subject.
|
1056
|
+
expect(subject).not_to be_active
|
896
1057
|
end
|
897
1058
|
|
898
1059
|
describe "with no headers" do
|
@@ -910,6 +1071,16 @@ module Adhearsion
|
|
910
1071
|
end
|
911
1072
|
end
|
912
1073
|
end
|
1074
|
+
|
1075
|
+
context "with a failure response" do
|
1076
|
+
it 'should raise the error but not crash the actor' do
|
1077
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1078
|
+
expect_message_waiting_for_response Punchblock::Command::Hangup.new, error
|
1079
|
+
expect { subject.hangup }.to raise_error error
|
1080
|
+
sleep 0.2
|
1081
|
+
expect(subject.alive?).to be true
|
1082
|
+
end
|
1083
|
+
end
|
913
1084
|
end
|
914
1085
|
|
915
1086
|
describe "#join" do
|
@@ -925,7 +1096,7 @@ module Adhearsion
|
|
925
1096
|
let(:uri) { "footransport:#{call_id}@#{domain}" }
|
926
1097
|
let(:target) { described_class.new }
|
927
1098
|
|
928
|
-
before { target.wrapped_object.
|
1099
|
+
before { allow(target.wrapped_object).to receive_messages uri: uri }
|
929
1100
|
|
930
1101
|
it "should send a join command joining to the provided call ID" do
|
931
1102
|
expect_join_with_options call_uri: uri
|
@@ -942,45 +1113,45 @@ module Adhearsion
|
|
942
1113
|
it "should return the command" do
|
943
1114
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
944
1115
|
result = subject.join target, :media => :bridge, :direction => :recv
|
945
|
-
result[:command].
|
946
|
-
result[:command].call_uri.
|
947
|
-
result[:command].media.
|
948
|
-
result[:command].direction.
|
1116
|
+
expect(result[:command]).to be_a Punchblock::Command::Join
|
1117
|
+
expect(result[:command].call_uri).to eql(uri)
|
1118
|
+
expect(result[:command].media).to eql(:bridge)
|
1119
|
+
expect(result[:command].direction).to eql(:recv)
|
949
1120
|
end
|
950
1121
|
|
951
1122
|
it "should return something that can be blocked on until the join is complete" do
|
952
1123
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
953
1124
|
result = subject.join target, :media => :bridge, :direction => :recv
|
954
1125
|
|
955
|
-
result[:joined_condition].wait(0.5).
|
1126
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
956
1127
|
|
957
1128
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
958
|
-
result[:joined_condition].wait(0.5).
|
1129
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
959
1130
|
end
|
960
1131
|
|
961
1132
|
it "should return something that can be blocked on until the entities are unjoined" do
|
962
1133
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
963
1134
|
result = subject.join target, :media => :bridge, :direction => :recv
|
964
1135
|
|
965
|
-
result[:unjoined_condition].wait(0.5).
|
1136
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
966
1137
|
|
967
1138
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
968
|
-
result[:unjoined_condition].wait(0.5).
|
1139
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
969
1140
|
|
970
1141
|
subject << Punchblock::Event::Unjoined.new(call_uri: uri)
|
971
|
-
result[:unjoined_condition].wait(0.5).
|
1142
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
972
1143
|
end
|
973
1144
|
|
974
1145
|
it "should unblock all conditions on call end if no joined/unjoined events are received" do
|
975
1146
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
976
1147
|
result = subject.join target, :media => :bridge, :direction => :recv
|
977
1148
|
|
978
|
-
result[:joined_condition].wait(0.5).
|
979
|
-
result[:unjoined_condition].wait(0.5).
|
1149
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1150
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
980
1151
|
|
981
1152
|
subject << Punchblock::Event::End.new
|
982
|
-
result[:joined_condition].wait(0.5).
|
983
|
-
result[:unjoined_condition].wait(0.5).
|
1153
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1154
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
984
1155
|
end
|
985
1156
|
|
986
1157
|
it "should not error on call end when joined/unjoined events are received correctly" do
|
@@ -1000,7 +1171,7 @@ module Adhearsion
|
|
1000
1171
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1001
1172
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1002
1173
|
|
1003
|
-
subject.
|
1174
|
+
expect(subject).to be_alive
|
1004
1175
|
end
|
1005
1176
|
end
|
1006
1177
|
|
@@ -1023,45 +1194,45 @@ module Adhearsion
|
|
1023
1194
|
it "should return the command" do
|
1024
1195
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1025
1196
|
result = subject.join target, :media => :bridge, :direction => :recv
|
1026
|
-
result[:command].
|
1027
|
-
result[:command].call_uri.
|
1028
|
-
result[:command].media.
|
1029
|
-
result[:command].direction.
|
1197
|
+
expect(result[:command]).to be_a Punchblock::Command::Join
|
1198
|
+
expect(result[:command].call_uri).to eql(uri)
|
1199
|
+
expect(result[:command].media).to eql(:bridge)
|
1200
|
+
expect(result[:command].direction).to eql(:recv)
|
1030
1201
|
end
|
1031
1202
|
|
1032
1203
|
it "should return something that can be blocked on until the join is complete" do
|
1033
1204
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1034
1205
|
result = subject.join target, :media => :bridge, :direction => :recv
|
1035
1206
|
|
1036
|
-
result[:joined_condition].wait(0.5).
|
1207
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1037
1208
|
|
1038
1209
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1039
|
-
result[:joined_condition].wait(0.5).
|
1210
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1040
1211
|
end
|
1041
1212
|
|
1042
1213
|
it "should return something that can be blocked on until the entities are unjoined" do
|
1043
1214
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1044
1215
|
result = subject.join target, :media => :bridge, :direction => :recv
|
1045
1216
|
|
1046
|
-
result[:unjoined_condition].wait(0.5).
|
1217
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1047
1218
|
|
1048
1219
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1049
|
-
result[:unjoined_condition].wait(0.5).
|
1220
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1050
1221
|
|
1051
1222
|
subject << Punchblock::Event::Unjoined.new(call_uri: uri)
|
1052
|
-
result[:unjoined_condition].wait(0.5).
|
1223
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1053
1224
|
end
|
1054
1225
|
|
1055
1226
|
it "should unblock all conditions on call end if no joined/unjoined events are received" do
|
1056
1227
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1057
1228
|
result = subject.join target, :media => :bridge, :direction => :recv
|
1058
1229
|
|
1059
|
-
result[:joined_condition].wait(0.5).
|
1060
|
-
result[:unjoined_condition].wait(0.5).
|
1230
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1231
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1061
1232
|
|
1062
1233
|
subject << Punchblock::Event::End.new
|
1063
|
-
result[:joined_condition].wait(0.5).
|
1064
|
-
result[:unjoined_condition].wait(0.5).
|
1234
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1235
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1065
1236
|
end
|
1066
1237
|
|
1067
1238
|
it "should not error on call end when joined/unjoined events are received correctly" do
|
@@ -1081,7 +1252,7 @@ module Adhearsion
|
|
1081
1252
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1082
1253
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1083
1254
|
|
1084
|
-
subject.
|
1255
|
+
expect(subject).to be_alive
|
1085
1256
|
end
|
1086
1257
|
end
|
1087
1258
|
|
@@ -1105,45 +1276,45 @@ module Adhearsion
|
|
1105
1276
|
it "should return the command" do
|
1106
1277
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1107
1278
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1108
|
-
result[:command].
|
1109
|
-
result[:command].call_uri.
|
1110
|
-
result[:command].media.
|
1111
|
-
result[:command].direction.
|
1279
|
+
expect(result[:command]).to be_a Punchblock::Command::Join
|
1280
|
+
expect(result[:command].call_uri).to eql(uri)
|
1281
|
+
expect(result[:command].media).to eql(:bridge)
|
1282
|
+
expect(result[:command].direction).to eql(:recv)
|
1112
1283
|
end
|
1113
1284
|
|
1114
1285
|
it "should return something that can be blocked on until the join is complete" do
|
1115
1286
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1116
1287
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1117
1288
|
|
1118
|
-
result[:joined_condition].wait(0.5).
|
1289
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1119
1290
|
|
1120
1291
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1121
|
-
result[:joined_condition].wait(0.5).
|
1292
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1122
1293
|
end
|
1123
1294
|
|
1124
1295
|
it "should return something that can be blocked on until the entities are unjoined" do
|
1125
1296
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1126
1297
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1127
1298
|
|
1128
|
-
result[:unjoined_condition].wait(0.5).
|
1299
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1129
1300
|
|
1130
1301
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1131
|
-
result[:unjoined_condition].wait(0.5).
|
1302
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1132
1303
|
|
1133
1304
|
subject << Punchblock::Event::Unjoined.new(call_uri: uri)
|
1134
|
-
result[:unjoined_condition].wait(0.5).
|
1305
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1135
1306
|
end
|
1136
1307
|
|
1137
1308
|
it "should unblock all conditions on call end if no joined/unjoined events are received" do
|
1138
1309
|
expect_join_with_options :call_id => uri, :media => :bridge, :direction => :recv
|
1139
1310
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1140
1311
|
|
1141
|
-
result[:joined_condition].wait(0.5).
|
1142
|
-
result[:unjoined_condition].wait(0.5).
|
1312
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1313
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1143
1314
|
|
1144
1315
|
subject << Punchblock::Event::End.new
|
1145
|
-
result[:joined_condition].wait(0.5).
|
1146
|
-
result[:unjoined_condition].wait(0.5).
|
1316
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1317
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1147
1318
|
end
|
1148
1319
|
|
1149
1320
|
it "should not error on call end when joined/unjoined events are received correctly" do
|
@@ -1163,7 +1334,7 @@ module Adhearsion
|
|
1163
1334
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1164
1335
|
subject << Punchblock::Event::Joined.new(call_uri: uri)
|
1165
1336
|
|
1166
|
-
subject.
|
1337
|
+
expect(subject).to be_alive
|
1167
1338
|
end
|
1168
1339
|
end
|
1169
1340
|
|
@@ -1186,45 +1357,45 @@ module Adhearsion
|
|
1186
1357
|
it "should return the command" do
|
1187
1358
|
expect_join_with_options :mixer_name => mixer_name, :media => :bridge, :direction => :recv
|
1188
1359
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1189
|
-
result[:command].
|
1190
|
-
result[:command].mixer_name.
|
1191
|
-
result[:command].media.
|
1192
|
-
result[:command].direction.
|
1360
|
+
expect(result[:command]).to be_a Punchblock::Command::Join
|
1361
|
+
expect(result[:command].mixer_name).to eql(mixer_name)
|
1362
|
+
expect(result[:command].media).to eql(:bridge)
|
1363
|
+
expect(result[:command].direction).to eql(:recv)
|
1193
1364
|
end
|
1194
1365
|
|
1195
1366
|
it "should return something that can be blocked on until the join is complete" do
|
1196
1367
|
expect_join_with_options :mixer_name => mixer_name, :media => :bridge, :direction => :recv
|
1197
1368
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1198
1369
|
|
1199
|
-
result[:joined_condition].wait(0.5).
|
1370
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1200
1371
|
|
1201
1372
|
subject << Punchblock::Event::Joined.new(mixer_name: mixer_name)
|
1202
|
-
result[:joined_condition].wait(0.5).
|
1373
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1203
1374
|
end
|
1204
1375
|
|
1205
1376
|
it "should return something that can be blocked on until the entities are unjoined" do
|
1206
1377
|
expect_join_with_options :mixer_name => mixer_name, :media => :bridge, :direction => :recv
|
1207
1378
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1208
1379
|
|
1209
|
-
result[:unjoined_condition].wait(0.5).
|
1380
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1210
1381
|
|
1211
1382
|
subject << Punchblock::Event::Joined.new(mixer_name: mixer_name)
|
1212
|
-
result[:unjoined_condition].wait(0.5).
|
1383
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1213
1384
|
|
1214
1385
|
subject << Punchblock::Event::Unjoined.new(mixer_name: mixer_name)
|
1215
|
-
result[:unjoined_condition].wait(0.5).
|
1386
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1216
1387
|
end
|
1217
1388
|
|
1218
1389
|
it "should unblock all conditions on call end if no joined/unjoined events are received" do
|
1219
1390
|
expect_join_with_options :mixer_name => mixer_name, :media => :bridge, :direction => :recv
|
1220
1391
|
result = subject.join target.merge({:media => :bridge, :direction => :recv})
|
1221
1392
|
|
1222
|
-
result[:joined_condition].wait(0.5).
|
1223
|
-
result[:unjoined_condition].wait(0.5).
|
1393
|
+
expect(result[:joined_condition].wait(0.5)).to be_falsey
|
1394
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_falsey
|
1224
1395
|
|
1225
1396
|
subject << Punchblock::Event::End.new
|
1226
|
-
result[:joined_condition].wait(0.5).
|
1227
|
-
result[:unjoined_condition].wait(0.5).
|
1397
|
+
expect(result[:joined_condition].wait(0.5)).to be_truthy
|
1398
|
+
expect(result[:unjoined_condition].wait(0.5)).to be_truthy
|
1228
1399
|
end
|
1229
1400
|
|
1230
1401
|
it "should not error on call end when joined/unjoined events are received correctly" do
|
@@ -1244,7 +1415,7 @@ module Adhearsion
|
|
1244
1415
|
subject << Punchblock::Event::Joined.new(mixer_name: mixer_name)
|
1245
1416
|
subject << Punchblock::Event::Joined.new(mixer_name: mixer_name)
|
1246
1417
|
|
1247
|
-
subject.
|
1418
|
+
expect(subject).to be_alive
|
1248
1419
|
end
|
1249
1420
|
end
|
1250
1421
|
|
@@ -1254,7 +1425,17 @@ module Adhearsion
|
|
1254
1425
|
let(:target) { { :call_uri => call_id, :mixer_name => mixer_name } }
|
1255
1426
|
|
1256
1427
|
it "should raise an ArgumentError" do
|
1257
|
-
|
1428
|
+
expect { subject.join target }.to raise_error ArgumentError, /call URI and mixer name/
|
1429
|
+
end
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
context "with a failure response" do
|
1433
|
+
it 'should raise the error but not crash the actor' do
|
1434
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1435
|
+
expect_message_waiting_for_response Punchblock::Command::Join.new(call_id: 'footransport:foo@rayo.net'), error
|
1436
|
+
expect { subject.join 'foo' }.to raise_error error
|
1437
|
+
sleep 0.2
|
1438
|
+
expect(subject.alive?).to be true
|
1258
1439
|
end
|
1259
1440
|
end
|
1260
1441
|
end
|
@@ -1266,13 +1447,20 @@ module Adhearsion
|
|
1266
1447
|
end
|
1267
1448
|
end
|
1268
1449
|
|
1450
|
+
context "without a target" do
|
1451
|
+
it "should send an unjoin command unjoining from every existing join" do
|
1452
|
+
expect_unjoin_with_options nil
|
1453
|
+
subject.unjoin
|
1454
|
+
end
|
1455
|
+
end
|
1456
|
+
|
1269
1457
|
context "with a call" do
|
1270
1458
|
let(:call_id) { rand.to_s }
|
1271
1459
|
let(:domain) { 'rayo.net' }
|
1272
1460
|
let(:uri) { "footransport:#{call_id}@#{domain}" }
|
1273
1461
|
let(:target) { described_class.new }
|
1274
1462
|
|
1275
|
-
before { target.wrapped_object.
|
1463
|
+
before { allow(target.wrapped_object).to receive_messages uri: uri }
|
1276
1464
|
|
1277
1465
|
it "should send an unjoin command unjoining from the provided call ID" do
|
1278
1466
|
expect_unjoin_with_options call_uri: "footransport:#{call_id}@#{domain}"
|
@@ -1315,7 +1503,17 @@ module Adhearsion
|
|
1315
1503
|
let(:target) { { call_uri: call_id, mixer_name: mixer_name } }
|
1316
1504
|
|
1317
1505
|
it "should raise an ArgumentError" do
|
1318
|
-
|
1506
|
+
expect { subject.unjoin target }.to raise_error ArgumentError, /call URI and mixer name/
|
1507
|
+
end
|
1508
|
+
end
|
1509
|
+
|
1510
|
+
context "with a failure response" do
|
1511
|
+
it 'should raise the error but not crash the actor' do
|
1512
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1513
|
+
expect_message_waiting_for_response Punchblock::Command::Unjoin.new(call_id: 'footransport:foo@rayo.net'), error
|
1514
|
+
expect { subject.unjoin 'foo' }.to raise_error error
|
1515
|
+
sleep 0.2
|
1516
|
+
expect(subject.alive?).to be true
|
1319
1517
|
end
|
1320
1518
|
end
|
1321
1519
|
end
|
@@ -1325,6 +1523,16 @@ module Adhearsion
|
|
1325
1523
|
expect_message_waiting_for_response Punchblock::Command::Mute.new
|
1326
1524
|
subject.mute
|
1327
1525
|
end
|
1526
|
+
|
1527
|
+
context "with a failure response" do
|
1528
|
+
it 'should raise the error but not crash the actor' do
|
1529
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1530
|
+
expect_message_waiting_for_response Punchblock::Command::Mute.new, error
|
1531
|
+
expect { subject.mute }.to raise_error error
|
1532
|
+
sleep 0.2
|
1533
|
+
expect(subject.alive?).to be true
|
1534
|
+
end
|
1535
|
+
end
|
1328
1536
|
end
|
1329
1537
|
|
1330
1538
|
describe "#unmute" do
|
@@ -1332,6 +1540,16 @@ module Adhearsion
|
|
1332
1540
|
expect_message_waiting_for_response Punchblock::Command::Unmute.new
|
1333
1541
|
subject.unmute
|
1334
1542
|
end
|
1543
|
+
|
1544
|
+
context "with a failure response" do
|
1545
|
+
it 'should raise the error but not crash the actor' do
|
1546
|
+
error = Punchblock::ProtocolError.new.setup(:service_unavailable)
|
1547
|
+
expect_message_waiting_for_response Punchblock::Command::Unmute.new, error
|
1548
|
+
expect { subject.unmute }.to raise_error error
|
1549
|
+
sleep 0.2
|
1550
|
+
expect(subject.alive?).to be true
|
1551
|
+
end
|
1552
|
+
end
|
1335
1553
|
end
|
1336
1554
|
|
1337
1555
|
describe "#execute_controller" do
|
@@ -1339,52 +1557,59 @@ module Adhearsion
|
|
1339
1557
|
let(:mock_controller) { CallController.new(subject) }
|
1340
1558
|
|
1341
1559
|
before do
|
1342
|
-
subject.wrapped_object.
|
1560
|
+
allow(subject.wrapped_object).to receive_messages :write_and_await_response => true
|
1343
1561
|
end
|
1344
1562
|
|
1345
1563
|
it "should call #bg_exec on the controller instance" do
|
1346
|
-
mock_controller.
|
1564
|
+
expect(mock_controller).to receive(:exec).once
|
1347
1565
|
subject.execute_controller mock_controller, lambda { |call| latch.countdown! }
|
1348
|
-
latch.wait(3).
|
1566
|
+
expect(latch.wait(3)).to be_truthy
|
1349
1567
|
end
|
1350
1568
|
|
1351
1569
|
it "should use the passed block as a controller if none is specified" do
|
1352
|
-
mock_controller.
|
1353
|
-
CallController.
|
1570
|
+
expect(mock_controller).to receive(:exec).once
|
1571
|
+
expect(CallController).to receive(:new).once.and_return mock_controller
|
1354
1572
|
subject.execute_controller nil, lambda { |call| latch.countdown! } do
|
1355
1573
|
foo
|
1356
1574
|
end
|
1357
|
-
latch.wait(3).
|
1575
|
+
expect(latch.wait(3)).to be_truthy
|
1358
1576
|
end
|
1359
1577
|
|
1360
1578
|
it "should raise ArgumentError if both a controller and a block are passed" do
|
1361
|
-
|
1579
|
+
expect { subject.execute_controller(mock_controller) { foo } }.to raise_error(ArgumentError)
|
1362
1580
|
end
|
1363
1581
|
|
1364
1582
|
it "should pass the exception to the events system" do
|
1365
1583
|
latch = CountDownLatch.new 1
|
1366
1584
|
Adhearsion::Events.exception do |e, l|
|
1367
|
-
e.
|
1368
|
-
l.
|
1585
|
+
expect(e).to be_a RuntimeError
|
1586
|
+
expect(l).to be subject.logger
|
1369
1587
|
latch.countdown!
|
1370
1588
|
end
|
1371
1589
|
subject.execute_controller BrokenController.new(subject), lambda { |call| latch.countdown! }
|
1372
|
-
latch.wait(3).
|
1590
|
+
expect(latch.wait(3)).to be true
|
1373
1591
|
Adhearsion::Events.clear_handlers :exception
|
1374
1592
|
end
|
1375
1593
|
|
1376
1594
|
it "should execute a callback after the controller executes" do
|
1377
1595
|
foo = nil
|
1378
1596
|
subject.execute_controller mock_controller, lambda { |call| foo = call; latch.countdown! }
|
1379
|
-
latch.wait(3).
|
1380
|
-
foo.
|
1597
|
+
expect(latch.wait(3)).to be_truthy
|
1598
|
+
expect(foo).to be subject
|
1599
|
+
end
|
1600
|
+
|
1601
|
+
it "should prevent exceptions in controllers from being raised" do
|
1602
|
+
expect(mock_controller).to receive(:run).once.ordered.and_raise StandardError
|
1603
|
+
expect { subject.execute_controller mock_controller, lambda { |call| latch.countdown! } }.to_not raise_error
|
1604
|
+
expect(latch.wait(3)).to be_truthy
|
1605
|
+
expect(subject.alive?).to be true
|
1381
1606
|
end
|
1382
1607
|
end
|
1383
1608
|
|
1384
1609
|
describe "#register_controller" do
|
1385
1610
|
it "should add the controller to a list on the call" do
|
1386
1611
|
subject.register_controller :foo
|
1387
|
-
subject.controllers.
|
1612
|
+
expect(subject.controllers).to include :foo
|
1388
1613
|
end
|
1389
1614
|
end
|
1390
1615
|
|
@@ -1396,8 +1621,8 @@ module Adhearsion
|
|
1396
1621
|
|
1397
1622
|
describe "#pause_controllers" do
|
1398
1623
|
it "should pause each of the registered controllers" do
|
1399
|
-
controller1.
|
1400
|
-
controller2.
|
1624
|
+
expect(controller1).to receive(:pause!).once
|
1625
|
+
expect(controller2).to receive(:pause!).once
|
1401
1626
|
|
1402
1627
|
subject.pause_controllers
|
1403
1628
|
end
|
@@ -1405,8 +1630,8 @@ module Adhearsion
|
|
1405
1630
|
|
1406
1631
|
describe "#resume_controllers" do
|
1407
1632
|
it "should resume each of the registered controllers" do
|
1408
|
-
controller1.
|
1409
|
-
controller2.
|
1633
|
+
expect(controller1).to receive(:resume!).once
|
1634
|
+
expect(controller2).to receive(:resume!).once
|
1410
1635
|
|
1411
1636
|
subject.resume_controllers
|
1412
1637
|
end
|
@@ -1417,7 +1642,7 @@ module Adhearsion
|
|
1417
1642
|
it "should delete its logger" do
|
1418
1643
|
logger = subject.logger
|
1419
1644
|
subject.terminate
|
1420
|
-
::Logging::Repository.instance[logger.name].
|
1645
|
+
expect(::Logging::Repository.instance[logger.name]).to be_nil
|
1421
1646
|
end
|
1422
1647
|
end
|
1423
1648
|
end
|
@@ -1425,21 +1650,21 @@ module Adhearsion
|
|
1425
1650
|
describe Call::CommandRegistry do
|
1426
1651
|
subject { Call::CommandRegistry.new }
|
1427
1652
|
|
1428
|
-
it {
|
1653
|
+
it { is_expected.to be_empty }
|
1429
1654
|
|
1430
1655
|
describe "#<<" do
|
1431
1656
|
it "should add a command to the registry" do
|
1432
1657
|
subject << :foo
|
1433
|
-
subject.
|
1658
|
+
expect(subject).not_to be_empty
|
1434
1659
|
end
|
1435
1660
|
end
|
1436
1661
|
|
1437
1662
|
describe "#delete" do
|
1438
1663
|
it "should remove a command from the registry" do
|
1439
1664
|
subject << :foo
|
1440
|
-
subject.
|
1665
|
+
expect(subject).not_to be_empty
|
1441
1666
|
subject.delete :foo
|
1442
|
-
subject.
|
1667
|
+
expect(subject).to be_empty
|
1443
1668
|
end
|
1444
1669
|
end
|
1445
1670
|
|
@@ -1462,9 +1687,9 @@ module Adhearsion
|
|
1462
1687
|
end
|
1463
1688
|
subject.terminate
|
1464
1689
|
commands.each do |command|
|
1465
|
-
command.response.
|
1690
|
+
expect(command.response).to be_a Call::Hangup
|
1466
1691
|
end
|
1467
|
-
finished_command.response.
|
1692
|
+
expect(finished_command.response).to eq(:foo)
|
1468
1693
|
end
|
1469
1694
|
end
|
1470
1695
|
end
|