punchblock 1.6.1 → 1.7.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.
- data/CHANGELOG.md +8 -0
- data/Guardfile +1 -1
- data/Rakefile +1 -1
- data/lib/punchblock/client.rb +5 -8
- data/lib/punchblock/client/component_registry.rb +8 -1
- data/lib/punchblock/component/component_node.rb +1 -0
- data/lib/punchblock/component/output.rb +15 -1
- data/lib/punchblock/translator/asterisk.rb +1 -1
- data/lib/punchblock/translator/asterisk/call.rb +1 -1
- data/lib/punchblock/translator/asterisk/component/output.rb +5 -1
- data/lib/punchblock/translator/freeswitch.rb +7 -1
- data/lib/punchblock/translator/freeswitch/call.rb +10 -6
- data/lib/punchblock/translator/freeswitch/component.rb +1 -1
- data/lib/punchblock/version.rb +1 -1
- data/punchblock.gemspec +1 -2
- data/spec/punchblock/client/component_registry_spec.rb +7 -0
- data/spec/punchblock/client_spec.rb +14 -12
- data/spec/punchblock/command_node_spec.rb +2 -2
- data/spec/punchblock/component/component_node_spec.rb +10 -3
- data/spec/punchblock/component/input_spec.rb +1 -1
- data/spec/punchblock/component/output_spec.rb +32 -27
- data/spec/punchblock/component/record_spec.rb +5 -5
- data/spec/punchblock/connection/asterisk_spec.rb +7 -7
- data/spec/punchblock/connection/freeswitch_spec.rb +8 -8
- data/spec/punchblock/connection/xmpp_spec.rb +9 -9
- data/spec/punchblock/translator/asterisk/call_spec.rb +65 -65
- data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +17 -20
- data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +13 -16
- data/spec/punchblock/translator/asterisk/component/input_spec.rb +9 -12
- data/spec/punchblock/translator/asterisk/component/output_spec.rb +62 -29
- data/spec/punchblock/translator/asterisk/component/record_spec.rb +38 -42
- data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +2 -2
- data/spec/punchblock/translator/asterisk/component_spec.rb +5 -5
- data/spec/punchblock/translator/asterisk_spec.rb +55 -55
- data/spec/punchblock/translator/freeswitch/call_spec.rb +80 -54
- data/spec/punchblock/translator/freeswitch/component/flite_output_spec.rb +7 -10
- data/spec/punchblock/translator/freeswitch/component/input_spec.rb +8 -10
- data/spec/punchblock/translator/freeswitch/component/output_spec.rb +9 -12
- data/spec/punchblock/translator/freeswitch/component/record_spec.rb +31 -34
- data/spec/punchblock/translator/freeswitch/component/tts_output_spec.rb +7 -10
- data/spec/punchblock/translator/freeswitch/component_spec.rb +6 -6
- data/spec/punchblock/translator/freeswitch_spec.rb +27 -27
- data/spec/punchblock_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -3
- data/spec/support/mock_connection_with_event_handler.rb +8 -19
- metadata +5 -21
|
@@ -7,10 +7,10 @@ module Punchblock
|
|
|
7
7
|
class Freeswitch
|
|
8
8
|
describe Call do
|
|
9
9
|
let(:id) { Punchblock.new_uuid }
|
|
10
|
-
let(:stream) {
|
|
11
|
-
let(:media_engine) {
|
|
10
|
+
let(:stream) { stub('RubyFS::Stream').as_null_object }
|
|
11
|
+
let(:media_engine) { 'freeswitch' }
|
|
12
12
|
let(:default_voice) { :hal }
|
|
13
|
-
let(:translator) { Freeswitch.new
|
|
13
|
+
let(:translator) { Freeswitch.new stub('Connection::Freeswitch').as_null_object }
|
|
14
14
|
let(:es_env) do
|
|
15
15
|
{
|
|
16
16
|
:variable_direction => "inbound",
|
|
@@ -188,7 +188,7 @@ module Punchblock
|
|
|
188
188
|
:to => "10@127.0.0.1",
|
|
189
189
|
:from => "Extension 1000 <1000@127.0.0.1>",
|
|
190
190
|
:headers => headers
|
|
191
|
-
translator.
|
|
191
|
+
translator.should_receive(:handle_pb_event).with expected_offer
|
|
192
192
|
subject.send_offer
|
|
193
193
|
end
|
|
194
194
|
|
|
@@ -202,21 +202,21 @@ module Punchblock
|
|
|
202
202
|
|
|
203
203
|
describe "#application" do
|
|
204
204
|
it "should execute a FS application on the current call" do
|
|
205
|
-
stream.
|
|
205
|
+
stream.should_receive(:application).once.with(id, 'appname', 'options')
|
|
206
206
|
subject.application 'appname', 'options'
|
|
207
207
|
end
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
describe "#sendmsg" do
|
|
211
211
|
it "should execute a FS sendmsg on the current call" do
|
|
212
|
-
stream.
|
|
212
|
+
stream.should_receive(:sendmsg).once.with(id, 'msg', :foo => 'bar')
|
|
213
213
|
subject.sendmsg 'msg', :foo => 'bar'
|
|
214
214
|
end
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
describe "#uuid_foo" do
|
|
218
218
|
it "should execute a FS uuid_* on the current call using bgapi" do
|
|
219
|
-
stream.
|
|
219
|
+
stream.should_receive(:bgapi).once.with("uuid_record #{id} blah.mp3")
|
|
220
220
|
subject.uuid_foo 'record', 'blah.mp3'
|
|
221
221
|
end
|
|
222
222
|
end
|
|
@@ -234,7 +234,7 @@ module Punchblock
|
|
|
234
234
|
before { dial_command.request! }
|
|
235
235
|
|
|
236
236
|
it 'sends an originate bgapi command' do
|
|
237
|
-
stream.
|
|
237
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_number='#{from}'}#{to} &park()"
|
|
238
238
|
subject.dial dial_command
|
|
239
239
|
end
|
|
240
240
|
|
|
@@ -244,7 +244,7 @@ module Punchblock
|
|
|
244
244
|
let(:from) { "#{from_name} <#{from_number}>" }
|
|
245
245
|
|
|
246
246
|
it 'sends an originate bgapi command with the cid fields set correctly' do
|
|
247
|
-
stream.
|
|
247
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_number='#{from_number}',origination_caller_id_name='#{from_name}'}#{to} &park()"
|
|
248
248
|
subject.dial dial_command
|
|
249
249
|
end
|
|
250
250
|
end
|
|
@@ -255,7 +255,7 @@ module Punchblock
|
|
|
255
255
|
let(:from) { "#{from_name} <#{from_number}>" }
|
|
256
256
|
|
|
257
257
|
it 'sends an originate bgapi command with the cid fields set correctly' do
|
|
258
|
-
stream.
|
|
258
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_name='#{from_name}'}#{to} &park()"
|
|
259
259
|
subject.dial dial_command
|
|
260
260
|
end
|
|
261
261
|
end
|
|
@@ -265,7 +265,7 @@ module Punchblock
|
|
|
265
265
|
let(:from) { "<#{from_number}>" }
|
|
266
266
|
|
|
267
267
|
it 'sends an originate bgapi command with the cid fields set correctly' do
|
|
268
|
-
stream.
|
|
268
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_number='#{from_number}'}#{to} &park()"
|
|
269
269
|
subject.dial dial_command
|
|
270
270
|
end
|
|
271
271
|
end
|
|
@@ -274,7 +274,7 @@ module Punchblock
|
|
|
274
274
|
let(:from) { '' }
|
|
275
275
|
|
|
276
276
|
it 'sends an originate bgapi command with the cid fields set correctly' do
|
|
277
|
-
stream.
|
|
277
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id}}#{to} &park()"
|
|
278
278
|
subject.dial dial_command
|
|
279
279
|
end
|
|
280
280
|
end
|
|
@@ -285,7 +285,7 @@ module Punchblock
|
|
|
285
285
|
end
|
|
286
286
|
|
|
287
287
|
it 'includes the timeout in the originate command' do
|
|
288
|
-
stream.
|
|
288
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_number='#{from}',originate_timeout=10}#{to} &park()"
|
|
289
289
|
subject.dial dial_command
|
|
290
290
|
end
|
|
291
291
|
end
|
|
@@ -296,7 +296,7 @@ module Punchblock
|
|
|
296
296
|
end
|
|
297
297
|
|
|
298
298
|
it 'includes the headers in the originate command' do
|
|
299
|
-
stream.
|
|
299
|
+
stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id},origination_caller_id_number='#{from}',sip_h_X-foo='bar',sip_h_X-doo='dah'}#{to} &park()"
|
|
300
300
|
subject.dial dial_command
|
|
301
301
|
end
|
|
302
302
|
end
|
|
@@ -333,15 +333,15 @@ module Punchblock
|
|
|
333
333
|
let(:cause) { 'ORIGINATOR_CANCEL' }
|
|
334
334
|
|
|
335
335
|
it "should cause the actor to be terminated" do
|
|
336
|
-
translator.
|
|
336
|
+
translator.should_receive(:handle_pb_event).once
|
|
337
337
|
subject.handle_es_event es_event
|
|
338
338
|
sleep 5.5
|
|
339
339
|
subject.should_not be_alive
|
|
340
340
|
end
|
|
341
341
|
|
|
342
342
|
it "de-registers the call from the translator" do
|
|
343
|
-
translator.
|
|
344
|
-
translator.
|
|
343
|
+
translator.stub :handle_pb_event
|
|
344
|
+
translator.should_receive(:deregister_call).once.with(subject)
|
|
345
345
|
subject.handle_es_event es_event
|
|
346
346
|
end
|
|
347
347
|
|
|
@@ -356,9 +356,8 @@ module Punchblock
|
|
|
356
356
|
expected_complete_event.reason = Punchblock::Event::Complete::Hangup.new
|
|
357
357
|
expected_end_event = Punchblock::Event::End.new :reason => :hangup, :target_call_id => subject.id
|
|
358
358
|
|
|
359
|
-
|
|
360
|
-
translator.
|
|
361
|
-
translator.expects(:handle_pb_event).with(expected_end_event).once.in_sequence(end_sequence)
|
|
359
|
+
translator.should_receive(:handle_pb_event).with(expected_complete_event).once.ordered
|
|
360
|
+
translator.should_receive(:handle_pb_event).with(expected_end_event).once.ordered
|
|
362
361
|
subject.handle_es_event es_event
|
|
363
362
|
end
|
|
364
363
|
|
|
@@ -378,7 +377,7 @@ module Punchblock
|
|
|
378
377
|
it 'should send an end (hangup) event to the translator' do
|
|
379
378
|
expected_end_event = Punchblock::Event::End.new :reason => :hangup,
|
|
380
379
|
:target_call_id => subject.id
|
|
381
|
-
translator.
|
|
380
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
382
381
|
subject.handle_es_event es_event
|
|
383
382
|
end
|
|
384
383
|
end
|
|
@@ -390,7 +389,7 @@ module Punchblock
|
|
|
390
389
|
it 'should send an end (busy) event to the translator' do
|
|
391
390
|
expected_end_event = Punchblock::Event::End.new :reason => :busy,
|
|
392
391
|
:target_call_id => subject.id
|
|
393
|
-
translator.
|
|
392
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
394
393
|
subject.handle_es_event es_event
|
|
395
394
|
end
|
|
396
395
|
end
|
|
@@ -409,7 +408,7 @@ module Punchblock
|
|
|
409
408
|
it 'should send an end (timeout) event to the translator' do
|
|
410
409
|
expected_end_event = Punchblock::Event::End.new :reason => :timeout,
|
|
411
410
|
:target_call_id => subject.id
|
|
412
|
-
translator.
|
|
411
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
413
412
|
subject.handle_es_event es_event
|
|
414
413
|
end
|
|
415
414
|
end
|
|
@@ -440,7 +439,7 @@ module Punchblock
|
|
|
440
439
|
it 'should send an end (reject) event to the translator' do
|
|
441
440
|
expected_end_event = Punchblock::Event::End.new :reason => :reject,
|
|
442
441
|
:target_call_id => subject.id
|
|
443
|
-
translator.
|
|
442
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
444
443
|
subject.handle_es_event es_event
|
|
445
444
|
end
|
|
446
445
|
end
|
|
@@ -484,7 +483,7 @@ module Punchblock
|
|
|
484
483
|
it 'should send an end (error) event to the translator' do
|
|
485
484
|
expected_end_event = Punchblock::Event::End.new :reason => :error,
|
|
486
485
|
:target_call_id => subject.id
|
|
487
|
-
translator.
|
|
486
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
488
487
|
subject.handle_es_event es_event
|
|
489
488
|
end
|
|
490
489
|
end
|
|
@@ -506,7 +505,7 @@ module Punchblock
|
|
|
506
505
|
end
|
|
507
506
|
|
|
508
507
|
it 'should send the event to the component' do
|
|
509
|
-
component.
|
|
508
|
+
component.should_receive(:handle_es_event).once.with es_event
|
|
510
509
|
subject.handle_es_event es_event
|
|
511
510
|
end
|
|
512
511
|
end
|
|
@@ -525,7 +524,7 @@ module Punchblock
|
|
|
525
524
|
it 'should send a ringing event' do
|
|
526
525
|
expected_ringing = Punchblock::Event::Ringing.new
|
|
527
526
|
expected_ringing.target_call_id = subject.id
|
|
528
|
-
translator.
|
|
527
|
+
translator.should_receive(:handle_pb_event).with expected_ringing
|
|
529
528
|
subject.handle_es_event es_event
|
|
530
529
|
end
|
|
531
530
|
|
|
@@ -539,7 +538,7 @@ module Punchblock
|
|
|
539
538
|
let(:channel_call_state) { 'FOO' }
|
|
540
539
|
|
|
541
540
|
it 'should not send a ringing event' do
|
|
542
|
-
translator.
|
|
541
|
+
translator.should_receive(:handle_pb_event).never
|
|
543
542
|
subject.handle_es_event es_event
|
|
544
543
|
end
|
|
545
544
|
|
|
@@ -558,7 +557,7 @@ module Punchblock
|
|
|
558
557
|
it 'should send an answered event' do
|
|
559
558
|
expected_answered = Punchblock::Event::Answered.new
|
|
560
559
|
expected_answered.target_call_id = subject.id
|
|
561
|
-
translator.
|
|
560
|
+
translator.should_receive(:handle_pb_event).with expected_answered
|
|
562
561
|
subject.handle_es_event es_event
|
|
563
562
|
end
|
|
564
563
|
|
|
@@ -576,7 +575,7 @@ module Punchblock
|
|
|
576
575
|
let(:response) { mock 'Response' }
|
|
577
576
|
|
|
578
577
|
it 'should execute the handler' do
|
|
579
|
-
response.
|
|
578
|
+
response.should_receive(:call).once.with es_event
|
|
580
579
|
subject.register_handler :es, :event_name => 'DTMF' do |event|
|
|
581
580
|
response.call event
|
|
582
581
|
end
|
|
@@ -604,7 +603,7 @@ module Punchblock
|
|
|
604
603
|
end
|
|
605
604
|
|
|
606
605
|
it "should send a joined event with the correct call ID" do
|
|
607
|
-
translator.
|
|
606
|
+
translator.should_receive(:handle_pb_event).with expected_joined
|
|
608
607
|
subject.handle_es_event bridge_event
|
|
609
608
|
end
|
|
610
609
|
end
|
|
@@ -619,7 +618,7 @@ module Punchblock
|
|
|
619
618
|
end
|
|
620
619
|
|
|
621
620
|
it "should send a joined event with the correct call ID" do
|
|
622
|
-
translator.
|
|
621
|
+
translator.should_receive(:handle_pb_event).with expected_joined
|
|
623
622
|
subject.handle_es_event bridge_event
|
|
624
623
|
end
|
|
625
624
|
end
|
|
@@ -645,7 +644,7 @@ module Punchblock
|
|
|
645
644
|
end
|
|
646
645
|
|
|
647
646
|
it "should send a unjoined event with the correct call ID" do
|
|
648
|
-
translator.
|
|
647
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
649
648
|
subject.handle_es_event unbridge_event
|
|
650
649
|
end
|
|
651
650
|
end
|
|
@@ -660,7 +659,7 @@ module Punchblock
|
|
|
660
659
|
end
|
|
661
660
|
|
|
662
661
|
it "should send a unjoined event with the correct call ID" do
|
|
663
|
-
translator.
|
|
662
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
664
663
|
subject.handle_es_event unbridge_event
|
|
665
664
|
end
|
|
666
665
|
end
|
|
@@ -676,7 +675,7 @@ module Punchblock
|
|
|
676
675
|
let(:command) { Command::Accept.new }
|
|
677
676
|
|
|
678
677
|
it "should send a respond 180 command and set the command's response" do
|
|
679
|
-
subject.wrapped_object.
|
|
678
|
+
subject.wrapped_object.should_receive(:application).once.with('respond', '180 Ringing')
|
|
680
679
|
subject.execute_command command
|
|
681
680
|
command.response(0.5).should be true
|
|
682
681
|
end
|
|
@@ -687,18 +686,30 @@ module Punchblock
|
|
|
687
686
|
|
|
688
687
|
it "should execute the answer application and set the command's response" do
|
|
689
688
|
subject
|
|
690
|
-
Punchblock.
|
|
691
|
-
subject.wrapped_object.
|
|
689
|
+
Punchblock.should_receive(:new_uuid).once.and_return 'abc123'
|
|
690
|
+
subject.wrapped_object.should_receive(:application).once.with('answer', "%[punchblock_command_id=abc123]")
|
|
692
691
|
subject.should_not be_answered
|
|
693
692
|
subject.execute_command command
|
|
694
693
|
subject.handle_es_event RubyFS::Event.new(nil, :event_name => 'CHANNEL_ANSWER', :scope_variable_punchblock_command_id => 'abc123')
|
|
695
694
|
command.response(0.5).should be true
|
|
696
695
|
subject.should be_answered
|
|
697
696
|
end
|
|
697
|
+
|
|
698
|
+
it "should not execute the answer application twice if already answered" do
|
|
699
|
+
subject
|
|
700
|
+
Punchblock.should_receive(:new_uuid).once.and_return 'abc123'
|
|
701
|
+
subject.wrapped_object.should_receive(:application).once.with('answer', "%[punchblock_command_id=abc123]")
|
|
702
|
+
subject.should_not be_answered
|
|
703
|
+
subject.execute_command command
|
|
704
|
+
subject.handle_es_event RubyFS::Event.new(nil, :event_name => 'CHANNEL_ANSWER', :scope_variable_punchblock_command_id => 'abc123')
|
|
705
|
+
command.response(0.5).should be true
|
|
706
|
+
subject.should be_answered
|
|
707
|
+
subject.execute_command command
|
|
708
|
+
end
|
|
698
709
|
end
|
|
699
710
|
|
|
700
711
|
def expect_hangup_with_reason(reason)
|
|
701
|
-
subject.wrapped_object.
|
|
712
|
+
subject.wrapped_object.should_receive(:sendmsg).once.with(:call_command => 'hangup', :hangup_cause => reason)
|
|
702
713
|
end
|
|
703
714
|
|
|
704
715
|
context 'with a hangup command' do
|
|
@@ -744,8 +755,8 @@ module Punchblock
|
|
|
744
755
|
let(:mock_component) { mock 'Freeswitch::Component::Output', :id => 'foo' }
|
|
745
756
|
|
|
746
757
|
it 'should create an Output component and execute it asynchronously' do
|
|
747
|
-
Component::Output.
|
|
748
|
-
mock_component.
|
|
758
|
+
Component::Output.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
759
|
+
mock_component.should_receive(:execute!).once
|
|
749
760
|
subject.execute_command command
|
|
750
761
|
subject.component_with_id('foo').should be mock_component
|
|
751
762
|
end
|
|
@@ -754,8 +765,8 @@ module Punchblock
|
|
|
754
765
|
let(:media_engine) { :flite }
|
|
755
766
|
|
|
756
767
|
it 'should create a FliteOutput component and execute it asynchronously using flite and the calls default voice' do
|
|
757
|
-
Component::FliteOutput.
|
|
758
|
-
mock_component.
|
|
768
|
+
Component::FliteOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
769
|
+
mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
|
|
759
770
|
subject.execute_command command
|
|
760
771
|
subject.component_with_id('foo').should be mock_component
|
|
761
772
|
end
|
|
@@ -765,8 +776,8 @@ module Punchblock
|
|
|
765
776
|
let(:media_engine) { :cepstral }
|
|
766
777
|
|
|
767
778
|
it 'should create a TTSOutput component and execute it asynchronously using cepstral and the calls default voice' do
|
|
768
|
-
Component::TTSOutput.
|
|
769
|
-
mock_component.
|
|
779
|
+
Component::TTSOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
780
|
+
mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
|
|
770
781
|
subject.execute_command command
|
|
771
782
|
subject.component_with_id('foo').should be mock_component
|
|
772
783
|
end
|
|
@@ -776,12 +787,27 @@ module Punchblock
|
|
|
776
787
|
let(:media_engine) { :unimrcp }
|
|
777
788
|
|
|
778
789
|
it 'should create a TTSOutput component and execute it asynchronously using unimrcp and the calls default voice' do
|
|
779
|
-
Component::TTSOutput.
|
|
780
|
-
mock_component.
|
|
790
|
+
Component::TTSOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
791
|
+
mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
|
|
781
792
|
subject.execute_command command
|
|
782
793
|
subject.component_with_id('foo').should be mock_component
|
|
783
794
|
end
|
|
784
795
|
end
|
|
796
|
+
|
|
797
|
+
context "with a media renderer set on the component" do
|
|
798
|
+
let(:media_engine) { :cepstral }
|
|
799
|
+
let(:media_renderer) { :native }
|
|
800
|
+
let :command_with_renderer do
|
|
801
|
+
Punchblock::Component::Output.new :renderer => media_renderer
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
it "should use the component media engine and not the platform one if it is set" do
|
|
805
|
+
Component::Output.should_receive(:new_link).once.with(command_with_renderer, subject).and_return mock_component
|
|
806
|
+
mock_component.should_receive(:execute!).once
|
|
807
|
+
subject.execute_command command_with_renderer
|
|
808
|
+
subject.component_with_id('foo').should be mock_component
|
|
809
|
+
end
|
|
810
|
+
end
|
|
785
811
|
end
|
|
786
812
|
|
|
787
813
|
context 'with an Input component' do
|
|
@@ -792,8 +818,8 @@ module Punchblock
|
|
|
792
818
|
let(:mock_component) { mock 'Freeswitch::Component::Input', :id => 'foo' }
|
|
793
819
|
|
|
794
820
|
it 'should create an Input component and execute it asynchronously' do
|
|
795
|
-
Component::Input.
|
|
796
|
-
mock_component.
|
|
821
|
+
Component::Input.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
822
|
+
mock_component.should_receive(:execute!).once
|
|
797
823
|
subject.execute_command command
|
|
798
824
|
end
|
|
799
825
|
end
|
|
@@ -806,8 +832,8 @@ module Punchblock
|
|
|
806
832
|
let(:mock_component) { mock 'Freeswitch::Component::Record', :id => 'foo' }
|
|
807
833
|
|
|
808
834
|
it 'should create a Record component and execute it asynchronously' do
|
|
809
|
-
Component::Record.
|
|
810
|
-
mock_component.
|
|
835
|
+
Component::Record.should_receive(:new_link).once.with(command, subject).and_return mock_component
|
|
836
|
+
mock_component.should_receive(:execute!).once
|
|
811
837
|
subject.execute_command command
|
|
812
838
|
end
|
|
813
839
|
end
|
|
@@ -827,7 +853,7 @@ module Punchblock
|
|
|
827
853
|
before { subject.register_component mock_component }
|
|
828
854
|
|
|
829
855
|
it 'should send the command to the component for execution' do
|
|
830
|
-
mock_component.
|
|
856
|
+
mock_component.should_receive(:execute_command).once
|
|
831
857
|
subject.execute_command command
|
|
832
858
|
end
|
|
833
859
|
end
|
|
@@ -861,7 +887,7 @@ module Punchblock
|
|
|
861
887
|
raise 'Woops, I died'
|
|
862
888
|
end
|
|
863
889
|
|
|
864
|
-
translator.
|
|
890
|
+
translator.should_receive(:handle_pb_event).once.with expected_event
|
|
865
891
|
|
|
866
892
|
lambda { component.oops }.should raise_error(/Woops, I died/)
|
|
867
893
|
sleep 0.1
|
|
@@ -901,7 +927,7 @@ module Punchblock
|
|
|
901
927
|
end
|
|
902
928
|
|
|
903
929
|
it "executes the proper uuid_bridge command" do
|
|
904
|
-
subject.wrapped_object.
|
|
930
|
+
subject.wrapped_object.should_receive(:uuid_foo).once.with :bridge, other_call_id
|
|
905
931
|
subject.execute_command command
|
|
906
932
|
expect { command.response 1 }.to raise_exception(Timeout::Error)
|
|
907
933
|
end
|
|
@@ -933,7 +959,7 @@ module Punchblock
|
|
|
933
959
|
end
|
|
934
960
|
|
|
935
961
|
it "executes the unjoin via transfer to park" do
|
|
936
|
-
subject.wrapped_object.
|
|
962
|
+
subject.wrapped_object.should_receive(:uuid_foo).once.with :transfer, '-both park inline'
|
|
937
963
|
subject.execute_command command
|
|
938
964
|
expect { command.response 1 }.to raise_exception(Timeout::Error)
|
|
939
965
|
end
|
|
@@ -7,11 +7,8 @@ module Punchblock
|
|
|
7
7
|
class Freeswitch
|
|
8
8
|
module Component
|
|
9
9
|
describe FliteOutput do
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
original_command.add_event event
|
|
13
|
-
end
|
|
14
|
-
end
|
|
10
|
+
include HasMockCallbackConnection
|
|
11
|
+
|
|
15
12
|
let(:media_engine) { :flite }
|
|
16
13
|
let(:default_voice) { nil }
|
|
17
14
|
let(:translator) { Punchblock::Translator::Freeswitch.new connection }
|
|
@@ -40,7 +37,7 @@ module Punchblock
|
|
|
40
37
|
describe '#execute' do
|
|
41
38
|
before { original_command.request! }
|
|
42
39
|
def expect_playback(voice = :kal)
|
|
43
|
-
subject.wrapped_object.
|
|
40
|
+
subject.wrapped_object.should_receive(:application).once.with :speak, "#{media_engine}|#{voice}|FOO"
|
|
44
41
|
end
|
|
45
42
|
|
|
46
43
|
let(:command_opts) { {} }
|
|
@@ -70,7 +67,7 @@ module Punchblock
|
|
|
70
67
|
end
|
|
71
68
|
|
|
72
69
|
it 'should send a complete event when the speak finishes' do
|
|
73
|
-
expect_playback
|
|
70
|
+
expect_playback
|
|
74
71
|
execute
|
|
75
72
|
subject.handle_es_event RubyFS::Event.new(nil, :event_name => "CHANNEL_EXECUTE_COMPLETE")
|
|
76
73
|
original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Success
|
|
@@ -252,13 +249,13 @@ module Punchblock
|
|
|
252
249
|
end
|
|
253
250
|
|
|
254
251
|
it "sets the command response to true" do
|
|
255
|
-
subject.wrapped_object.
|
|
252
|
+
subject.wrapped_object.should_receive(:application)
|
|
256
253
|
subject.execute_command command
|
|
257
254
|
command.response(0.1).should be == true
|
|
258
255
|
end
|
|
259
256
|
|
|
260
257
|
it "sends the correct complete event" do
|
|
261
|
-
subject.wrapped_object.
|
|
258
|
+
subject.wrapped_object.should_receive(:application)
|
|
262
259
|
original_command.should_not be_complete
|
|
263
260
|
subject.execute_command command
|
|
264
261
|
reason.should be_a Punchblock::Event::Complete::Stop
|
|
@@ -266,7 +263,7 @@ module Punchblock
|
|
|
266
263
|
end
|
|
267
264
|
|
|
268
265
|
it "breaks the current dialplan application" do
|
|
269
|
-
subject.wrapped_object.
|
|
266
|
+
subject.wrapped_object.should_receive(:application).once.with 'break'
|
|
270
267
|
subject.execute_command command
|
|
271
268
|
end
|
|
272
269
|
end
|