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
|
@@ -17,6 +17,7 @@ module Punchblock
|
|
|
17
17
|
its(:repeat_times) { should be nil }
|
|
18
18
|
its(:max_time) { should be nil }
|
|
19
19
|
its(:voice) { should be nil }
|
|
20
|
+
its(:renderer) { should be nil }
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
describe "when setting options in initializer" do
|
|
@@ -27,7 +28,8 @@ module Punchblock
|
|
|
27
28
|
:repeat_interval => 2000,
|
|
28
29
|
:repeat_times => 10,
|
|
29
30
|
:max_time => 30000,
|
|
30
|
-
:voice => 'allison'
|
|
31
|
+
:voice => 'allison',
|
|
32
|
+
:renderer => 'swift'
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
its(:interrupt_on) { should be == :speech }
|
|
@@ -37,6 +39,7 @@ module Punchblock
|
|
|
37
39
|
its(:repeat_times) { should be == 10 }
|
|
38
40
|
its(:max_time) { should be == 30000 }
|
|
39
41
|
its(:voice) { should be == 'allison' }
|
|
42
|
+
its(:renderer) { should be == 'swift' }
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
describe "from a stanza" do
|
|
@@ -49,7 +52,8 @@ module Punchblock
|
|
|
49
52
|
repeat-interval='2000'
|
|
50
53
|
repeat-times='10'
|
|
51
54
|
max-time='30000'
|
|
52
|
-
voice='allison'
|
|
55
|
+
voice='allison'
|
|
56
|
+
renderer='swift'>Hello world</output>
|
|
53
57
|
MESSAGE
|
|
54
58
|
end
|
|
55
59
|
|
|
@@ -64,6 +68,7 @@ module Punchblock
|
|
|
64
68
|
its(:repeat_times) { should be == 10 }
|
|
65
69
|
its(:max_time) { should be == 30000 }
|
|
66
70
|
its(:voice) { should be == 'allison' }
|
|
71
|
+
its(:renderer) { should be == 'swift' }
|
|
67
72
|
its(:text) { should be == 'Hello world' }
|
|
68
73
|
end
|
|
69
74
|
|
|
@@ -124,8 +129,8 @@ module Punchblock
|
|
|
124
129
|
end
|
|
125
130
|
|
|
126
131
|
it "should send its command properly" do
|
|
127
|
-
mock_client.
|
|
128
|
-
command.
|
|
132
|
+
mock_client.should_receive(:execute_command).with(command.pause_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
133
|
+
command.should_receive :paused!
|
|
129
134
|
command.pause!
|
|
130
135
|
end
|
|
131
136
|
end
|
|
@@ -168,8 +173,8 @@ module Punchblock
|
|
|
168
173
|
end
|
|
169
174
|
|
|
170
175
|
it "should send its command properly" do
|
|
171
|
-
mock_client.
|
|
172
|
-
command.
|
|
176
|
+
mock_client.should_receive(:execute_command).with(command.resume_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
177
|
+
command.should_receive :resumed!
|
|
173
178
|
command.resume!
|
|
174
179
|
end
|
|
175
180
|
end
|
|
@@ -212,7 +217,7 @@ module Punchblock
|
|
|
212
217
|
end
|
|
213
218
|
|
|
214
219
|
it "should send its command properly" do
|
|
215
|
-
mock_client.
|
|
220
|
+
mock_client.should_receive(:execute_command).with(command.stop_action, :target_call_id => '123abc', :component_id => 'abc123')
|
|
216
221
|
command.stop!
|
|
217
222
|
end
|
|
218
223
|
end
|
|
@@ -244,10 +249,10 @@ module Punchblock
|
|
|
244
249
|
|
|
245
250
|
it "should send its command properly" do
|
|
246
251
|
seek_action = command.seek_action seek_options
|
|
247
|
-
command.
|
|
248
|
-
mock_client.
|
|
249
|
-
command.
|
|
250
|
-
command.
|
|
252
|
+
command.stub(:seek_action).and_return seek_action
|
|
253
|
+
mock_client.should_receive(:execute_command).with(seek_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
254
|
+
command.should_receive :seeking!
|
|
255
|
+
command.should_receive :stopped_seeking!
|
|
251
256
|
command.seek! seek_options
|
|
252
257
|
seek_action.request!
|
|
253
258
|
seek_action.execute!
|
|
@@ -311,10 +316,10 @@ module Punchblock
|
|
|
311
316
|
|
|
312
317
|
it "should send its command properly" do
|
|
313
318
|
speed_up_action = command.speed_up_action
|
|
314
|
-
command.
|
|
315
|
-
mock_client.
|
|
316
|
-
command.
|
|
317
|
-
command.
|
|
319
|
+
command.stub(:speed_up_action).and_return speed_up_action
|
|
320
|
+
mock_client.should_receive(:execute_command).with(speed_up_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
321
|
+
command.should_receive :speeding_up!
|
|
322
|
+
command.should_receive :stopped_speeding!
|
|
318
323
|
command.speed_up!
|
|
319
324
|
speed_up_action.request!
|
|
320
325
|
speed_up_action.execute!
|
|
@@ -369,10 +374,10 @@ module Punchblock
|
|
|
369
374
|
|
|
370
375
|
it "should send its command properly" do
|
|
371
376
|
slow_down_action = command.slow_down_action
|
|
372
|
-
command.
|
|
373
|
-
mock_client.
|
|
374
|
-
command.
|
|
375
|
-
command.
|
|
377
|
+
command.stub(:slow_down_action).and_return slow_down_action
|
|
378
|
+
mock_client.should_receive(:execute_command).with(slow_down_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
379
|
+
command.should_receive :slowing_down!
|
|
380
|
+
command.should_receive :stopped_speeding!
|
|
376
381
|
command.slow_down!
|
|
377
382
|
slow_down_action.request!
|
|
378
383
|
slow_down_action.execute!
|
|
@@ -444,10 +449,10 @@ module Punchblock
|
|
|
444
449
|
|
|
445
450
|
it "should send its command properly" do
|
|
446
451
|
volume_up_action = command.volume_up_action
|
|
447
|
-
command.
|
|
448
|
-
mock_client.
|
|
449
|
-
command.
|
|
450
|
-
command.
|
|
452
|
+
command.stub(:volume_up_action).and_return volume_up_action
|
|
453
|
+
mock_client.should_receive(:execute_command).with(volume_up_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
454
|
+
command.should_receive :voluming_up!
|
|
455
|
+
command.should_receive :stopped_voluming!
|
|
451
456
|
command.volume_up!
|
|
452
457
|
volume_up_action.request!
|
|
453
458
|
volume_up_action.execute!
|
|
@@ -502,10 +507,10 @@ module Punchblock
|
|
|
502
507
|
|
|
503
508
|
it "should send its command properly" do
|
|
504
509
|
volume_down_action = command.volume_down_action
|
|
505
|
-
command.
|
|
506
|
-
mock_client.
|
|
507
|
-
command.
|
|
508
|
-
command.
|
|
510
|
+
command.stub(:volume_down_action).and_return volume_down_action
|
|
511
|
+
mock_client.should_receive(:execute_command).with(volume_down_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
512
|
+
command.should_receive :voluming_down!
|
|
513
|
+
command.should_receive :stopped_voluming!
|
|
509
514
|
command.volume_down!
|
|
510
515
|
volume_down_action.request!
|
|
511
516
|
volume_down_action.execute!
|
|
@@ -78,8 +78,8 @@ module Punchblock
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "should send its command properly" do
|
|
81
|
-
mock_client.
|
|
82
|
-
command.
|
|
81
|
+
mock_client.should_receive(:execute_command).with(command.pause_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
82
|
+
command.should_receive :paused!
|
|
83
83
|
command.pause!
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -122,8 +122,8 @@ module Punchblock
|
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "should send its command properly" do
|
|
125
|
-
mock_client.
|
|
126
|
-
command.
|
|
125
|
+
mock_client.should_receive(:execute_command).with(command.resume_action, :target_call_id => '123abc', :component_id => 'abc123').and_return true
|
|
126
|
+
command.should_receive :resumed!
|
|
127
127
|
command.resume!
|
|
128
128
|
end
|
|
129
129
|
end
|
|
@@ -196,7 +196,7 @@ module Punchblock
|
|
|
196
196
|
end
|
|
197
197
|
|
|
198
198
|
it "should send its command properly" do
|
|
199
|
-
mock_client.
|
|
199
|
+
mock_client.should_receive(:execute_command).with(command.stop_action, :target_call_id => '123abc', :component_id => 'abc123')
|
|
200
200
|
command.stop!
|
|
201
201
|
end
|
|
202
202
|
end
|
|
@@ -15,7 +15,7 @@ module Punchblock
|
|
|
15
15
|
}
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
let(:mock_event_handler) {
|
|
18
|
+
let(:mock_event_handler) { stub('Event Handler').as_null_object }
|
|
19
19
|
|
|
20
20
|
let(:connection) { Asterisk.new options }
|
|
21
21
|
|
|
@@ -37,26 +37,26 @@ module Punchblock
|
|
|
37
37
|
|
|
38
38
|
describe '#run' do
|
|
39
39
|
it 'starts the RubyAMI::Client' do
|
|
40
|
-
subject.ami_client.
|
|
40
|
+
subject.ami_client.should_receive(:start).once
|
|
41
41
|
lambda { subject.run }.should raise_error DisconnectedError
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
describe '#stop' do
|
|
46
46
|
it 'stops the RubyAMI::Client' do
|
|
47
|
-
subject.ami_client.
|
|
47
|
+
subject.ami_client.should_receive(:stop).once
|
|
48
48
|
subject.stop
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it 'shuts down the translator' do
|
|
52
|
-
subject.translator.
|
|
52
|
+
subject.translator.should_receive(:shutdown!).once
|
|
53
53
|
subject.stop
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it 'sends events from RubyAMI to the translator' do
|
|
58
58
|
event = mock 'RubyAMI::Event'
|
|
59
|
-
subject.translator.
|
|
59
|
+
subject.translator.should_receive(:handle_ami_event!).once.with event
|
|
60
60
|
subject.ami_client.handle_event event
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ module Punchblock
|
|
|
64
64
|
it 'sends a command to the translator' do
|
|
65
65
|
command = mock 'Command'
|
|
66
66
|
options = {:foo => :bar}
|
|
67
|
-
subject.translator.
|
|
67
|
+
subject.translator.should_receive(:execute_command!).once.with command, options
|
|
68
68
|
subject.write command, options
|
|
69
69
|
end
|
|
70
70
|
end
|
|
@@ -74,7 +74,7 @@ module Punchblock
|
|
|
74
74
|
offer = Event::Offer.new
|
|
75
75
|
offer.target_call_id = '9f00061'
|
|
76
76
|
|
|
77
|
-
mock_event_handler.
|
|
77
|
+
mock_event_handler.should_receive(:call).once.with offer
|
|
78
78
|
subject.handle_event offer
|
|
79
79
|
end
|
|
80
80
|
end
|
|
@@ -17,7 +17,7 @@ module Punchblock
|
|
|
17
17
|
}
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
let(:mock_event_handler) {
|
|
20
|
+
let(:mock_event_handler) { stub('Event Handler').as_null_object }
|
|
21
21
|
|
|
22
22
|
let(:connection) { described_class.new options }
|
|
23
23
|
|
|
@@ -43,27 +43,27 @@ module Punchblock
|
|
|
43
43
|
|
|
44
44
|
describe '#run' do
|
|
45
45
|
it 'starts a RubyFS stream' do
|
|
46
|
-
# subject.
|
|
47
|
-
subject.stream.
|
|
46
|
+
# subject.should_receive(:new_fs_stream).once.with('127.0.0.1', 8021, 'test').and_return mock_stream
|
|
47
|
+
subject.stream.should_receive(:run).once
|
|
48
48
|
lambda { subject.run }.should raise_error(DisconnectedError)
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
describe '#stop' do
|
|
53
53
|
it 'stops the RubyFS::Stream' do
|
|
54
|
-
subject.stream.
|
|
54
|
+
subject.stream.should_receive(:shutdown).once
|
|
55
55
|
subject.stop
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it 'shuts down the translator' do
|
|
59
|
-
subject.translator.
|
|
59
|
+
subject.translator.should_receive(:terminate).once
|
|
60
60
|
subject.stop
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it 'sends events from RubyFS to the translator' do
|
|
65
65
|
event = mock 'RubyFS::Event'
|
|
66
|
-
subject.translator.
|
|
66
|
+
subject.translator.should_receive(:handle_es_event!).once.with event
|
|
67
67
|
subject.stream.fire_event event
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -71,7 +71,7 @@ module Punchblock
|
|
|
71
71
|
it 'sends a command to the translator' do
|
|
72
72
|
command = mock 'Command'
|
|
73
73
|
options = {:foo => :bar}
|
|
74
|
-
subject.translator.
|
|
74
|
+
subject.translator.should_receive(:execute_command!).once.with command, options
|
|
75
75
|
subject.write command, options
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -81,7 +81,7 @@ module Punchblock
|
|
|
81
81
|
offer = Event::Offer.new
|
|
82
82
|
offer.target_call_id = '9f00061'
|
|
83
83
|
|
|
84
|
-
mock_event_handler.
|
|
84
|
+
mock_event_handler.should_receive(:call).once.with offer
|
|
85
85
|
subject.handle_event offer
|
|
86
86
|
end
|
|
87
87
|
end
|
|
@@ -8,7 +8,7 @@ module Punchblock
|
|
|
8
8
|
let(:options) { { :root_domain => 'rayo.net' } }
|
|
9
9
|
let(:connection) { XMPP.new({:username => '1@app.rayo.net', :password => 1}.merge(options)) }
|
|
10
10
|
|
|
11
|
-
let(:mock_event_handler) {
|
|
11
|
+
let(:mock_event_handler) { stub('Event Handler').as_null_object }
|
|
12
12
|
|
|
13
13
|
before do
|
|
14
14
|
connection.event_handler = mock_event_handler
|
|
@@ -87,9 +87,9 @@ module Punchblock
|
|
|
87
87
|
</output>
|
|
88
88
|
MSG
|
|
89
89
|
output = RayoNode.import parse_stanza(output).root
|
|
90
|
-
connection.
|
|
90
|
+
connection.should_receive(:write_to_stream).once.and_return true
|
|
91
91
|
iq = Blather::Stanza::Iq.new :set, '9f00061@call.rayo.net'
|
|
92
|
-
connection.
|
|
92
|
+
connection.should_receive(:create_iq).and_return iq
|
|
93
93
|
|
|
94
94
|
write_thread = Thread.new do
|
|
95
95
|
connection.write offer.call_id, output
|
|
@@ -127,7 +127,7 @@ module Punchblock
|
|
|
127
127
|
|
|
128
128
|
it 'should send a "Chat" presence when ready' do
|
|
129
129
|
client = connection.send :client
|
|
130
|
-
client.
|
|
130
|
+
client.should_receive(:write).once.with do |stanza|
|
|
131
131
|
stanza.to.should be == 'rayo.net'
|
|
132
132
|
stanza.should be_a Blather::Stanza::Presence::Status
|
|
133
133
|
stanza.chat?.should be true
|
|
@@ -137,7 +137,7 @@ module Punchblock
|
|
|
137
137
|
|
|
138
138
|
it 'should send a "Do Not Disturb" presence when not_ready' do
|
|
139
139
|
client = connection.send :client
|
|
140
|
-
client.
|
|
140
|
+
client.should_receive(:write).once.with do |stanza|
|
|
141
141
|
stanza.to.should be == 'rayo.net'
|
|
142
142
|
stanza.should be_a Blather::Stanza::Presence::Status
|
|
143
143
|
stanza.dnd?.should be true
|
|
@@ -180,7 +180,7 @@ module Punchblock
|
|
|
180
180
|
let(:handle_presence) { connection.__send__ :handle_presence, example_offer }
|
|
181
181
|
|
|
182
182
|
it 'should call the event handler with the event' do
|
|
183
|
-
mock_event_handler.
|
|
183
|
+
mock_event_handler.should_receive(:call).once.with do |event|
|
|
184
184
|
event.should be_instance_of Event::Offer
|
|
185
185
|
event.target_call_id.should be == '9f00061'
|
|
186
186
|
event.domain.should be == 'call.rayo.net'
|
|
@@ -207,7 +207,7 @@ module Punchblock
|
|
|
207
207
|
let(:example_irrelevant_event) { import_stanza irrelevant_xml }
|
|
208
208
|
|
|
209
209
|
it 'should not handle the event' do
|
|
210
|
-
mock_event_handler.
|
|
210
|
+
mock_event_handler.should_receive(:call).never
|
|
211
211
|
lambda { connection.__send__ :handle_presence, example_irrelevant_event }.should throw_symbol(:pass)
|
|
212
212
|
end
|
|
213
213
|
end
|
|
@@ -307,7 +307,7 @@ module Punchblock
|
|
|
307
307
|
describe "receiving events from a mixer" do
|
|
308
308
|
context "after joining the mixer" do
|
|
309
309
|
before do
|
|
310
|
-
subject.send(:client).
|
|
310
|
+
subject.send(:client).should_receive :write_with_handler
|
|
311
311
|
subject.write Command::Join.new(:mixer_name => 'foomixer')
|
|
312
312
|
end
|
|
313
313
|
|
|
@@ -322,7 +322,7 @@ module Punchblock
|
|
|
322
322
|
let(:active_speaker_event) { import_stanza active_speaker_xml }
|
|
323
323
|
|
|
324
324
|
it "should tag those events with a mixer name, rather than a call ID" do
|
|
325
|
-
mock_event_handler.
|
|
325
|
+
mock_event_handler.should_receive(:call).once.with do |event|
|
|
326
326
|
event.should be_instance_of Event::StartedSpeaking
|
|
327
327
|
event.target_mixer_name.should be == 'foomixer'
|
|
328
328
|
event.target_call_id.should be nil
|
|
@@ -7,7 +7,7 @@ module Punchblock
|
|
|
7
7
|
class Asterisk
|
|
8
8
|
describe Call do
|
|
9
9
|
let(:channel) { 'SIP/foo' }
|
|
10
|
-
let(:translator) {
|
|
10
|
+
let(:translator) { stub('Translator::Asterisk').as_null_object }
|
|
11
11
|
let(:agi_env) do
|
|
12
12
|
{
|
|
13
13
|
:agi_request => 'async',
|
|
@@ -88,7 +88,7 @@ module Punchblock
|
|
|
88
88
|
:to => '1000',
|
|
89
89
|
:from => 'Jane Smith <SIP/5678>',
|
|
90
90
|
:headers => sip_headers
|
|
91
|
-
translator.
|
|
91
|
+
translator.should_receive(:handle_pb_event).with expected_offer
|
|
92
92
|
subject.send_offer
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -104,15 +104,15 @@ module Punchblock
|
|
|
104
104
|
|
|
105
105
|
context "with a call that is already answered" do
|
|
106
106
|
it 'should not send the EXEC Progress command' do
|
|
107
|
-
subject.wrapped_object.
|
|
108
|
-
subject.wrapped_object.
|
|
107
|
+
subject.wrapped_object.should_receive(:'answered?').and_return true
|
|
108
|
+
subject.wrapped_object.should_receive(:send_agi_action).with("EXEC Progress").never
|
|
109
109
|
subject.send_progress
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
context "with an unanswered call" do
|
|
114
114
|
before do
|
|
115
|
-
subject.wrapped_object.
|
|
115
|
+
subject.wrapped_object.should_receive(:'answered?').at_least(:once).and_return(false)
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
context "with a call that is outbound" do
|
|
@@ -124,7 +124,7 @@ module Punchblock
|
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
it 'should not send the EXEC Progress command' do
|
|
127
|
-
subject.wrapped_object.
|
|
127
|
+
subject.wrapped_object.should_receive(:send_agi_action).with("EXEC Progress").never
|
|
128
128
|
subject.send_progress
|
|
129
129
|
end
|
|
130
130
|
end
|
|
@@ -135,12 +135,12 @@ module Punchblock
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
it 'should send the EXEC Progress command to a call that is inbound and not answered' do
|
|
138
|
-
subject.wrapped_object.
|
|
138
|
+
subject.wrapped_object.should_receive(:send_agi_action).with("EXEC Progress")
|
|
139
139
|
subject.send_progress
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
it 'should send the EXEC Progress command only once if called twice' do
|
|
143
|
-
subject.wrapped_object.
|
|
143
|
+
subject.wrapped_object.should_receive(:send_agi_action).with("EXEC Progress").once
|
|
144
144
|
subject.send_progress
|
|
145
145
|
subject.send_progress
|
|
146
146
|
end
|
|
@@ -170,7 +170,7 @@ module Punchblock
|
|
|
170
170
|
:variable => "punchblock_call_id=#{subject.id}"
|
|
171
171
|
}).tap { |a| a.request! }
|
|
172
172
|
|
|
173
|
-
translator.
|
|
173
|
+
translator.should_receive(:execute_global_command!).once.with expected_action
|
|
174
174
|
subject.dial dial_command
|
|
175
175
|
end
|
|
176
176
|
|
|
@@ -188,7 +188,7 @@ module Punchblock
|
|
|
188
188
|
:variable => "punchblock_call_id=#{subject.id}"
|
|
189
189
|
}).tap { |a| a.request! }
|
|
190
190
|
|
|
191
|
-
translator.
|
|
191
|
+
translator.should_receive(:execute_global_command!).once.with expected_action
|
|
192
192
|
subject.dial dial_command
|
|
193
193
|
end
|
|
194
194
|
end
|
|
@@ -210,7 +210,7 @@ module Punchblock
|
|
|
210
210
|
:timeout => 10000
|
|
211
211
|
}).tap { |a| a.request! }
|
|
212
212
|
|
|
213
|
-
translator.
|
|
213
|
+
translator.should_receive(:execute_global_command!).once.with expected_action
|
|
214
214
|
subject.dial dial_command
|
|
215
215
|
end
|
|
216
216
|
end
|
|
@@ -231,7 +231,7 @@ module Punchblock
|
|
|
231
231
|
:variable => "punchblock_call_id=#{subject.id},SIPADDHEADER51=\"X-foo: bar\",SIPADDHEADER52=\"X-doo: dah\""
|
|
232
232
|
}).tap { |a| a.request! }
|
|
233
233
|
|
|
234
|
-
translator.
|
|
234
|
+
translator.should_receive(:execute_global_command!).once.with expected_action
|
|
235
235
|
subject.dial dial_command
|
|
236
236
|
end
|
|
237
237
|
end
|
|
@@ -253,7 +253,7 @@ module Punchblock
|
|
|
253
253
|
subject.dial dial_command
|
|
254
254
|
accept_command = Command::Accept.new
|
|
255
255
|
accept_command.request!
|
|
256
|
-
subject.wrapped_object.
|
|
256
|
+
subject.wrapped_object.should_receive(:send_agi_action).never
|
|
257
257
|
subject.execute_command accept_command
|
|
258
258
|
accept_command.response(0.5).should be true
|
|
259
259
|
end
|
|
@@ -276,15 +276,15 @@ module Punchblock
|
|
|
276
276
|
let(:cause_txt) { 'Normal Clearing' }
|
|
277
277
|
|
|
278
278
|
it "should cause the actor to be terminated" do
|
|
279
|
-
translator.
|
|
279
|
+
translator.should_receive(:handle_pb_event).twice
|
|
280
280
|
subject.process_ami_event ami_event
|
|
281
281
|
sleep 5.5
|
|
282
282
|
subject.should_not be_alive
|
|
283
283
|
end
|
|
284
284
|
|
|
285
285
|
it "de-registers the call from the translator" do
|
|
286
|
-
translator.
|
|
287
|
-
translator.
|
|
286
|
+
translator.stub :handle_pb_event
|
|
287
|
+
translator.should_receive(:deregister_call).once.with(subject)
|
|
288
288
|
subject.process_ami_event ami_event
|
|
289
289
|
end
|
|
290
290
|
|
|
@@ -296,9 +296,9 @@ module Punchblock
|
|
|
296
296
|
expected_complete_event = Punchblock::Event::Complete.new :target_call_id => subject.id, :component_id => component.id
|
|
297
297
|
expected_complete_event.reason = Punchblock::Event::Complete::Hangup.new
|
|
298
298
|
expected_end_event = Punchblock::Event::End.new :reason => :hangup, :target_call_id => subject.id
|
|
299
|
-
|
|
300
|
-
translator.
|
|
301
|
-
translator.
|
|
299
|
+
|
|
300
|
+
translator.should_receive(:handle_pb_event).with(expected_complete_event).once.ordered
|
|
301
|
+
translator.should_receive(:handle_pb_event).with(expected_end_event).once.ordered
|
|
302
302
|
subject.process_ami_event ami_event
|
|
303
303
|
end
|
|
304
304
|
|
|
@@ -309,7 +309,7 @@ module Punchblock
|
|
|
309
309
|
it 'should send an end (hangup) event to the translator' do
|
|
310
310
|
expected_end_event = Punchblock::Event::End.new :reason => :hangup,
|
|
311
311
|
:target_call_id => subject.id
|
|
312
|
-
translator.
|
|
312
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
313
313
|
subject.process_ami_event ami_event
|
|
314
314
|
end
|
|
315
315
|
end
|
|
@@ -321,7 +321,7 @@ module Punchblock
|
|
|
321
321
|
it 'should send an end (hangup) event to the translator' do
|
|
322
322
|
expected_end_event = Punchblock::Event::End.new :reason => :hangup,
|
|
323
323
|
:target_call_id => subject.id
|
|
324
|
-
translator.
|
|
324
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
325
325
|
subject.process_ami_event ami_event
|
|
326
326
|
end
|
|
327
327
|
end
|
|
@@ -333,7 +333,7 @@ module Punchblock
|
|
|
333
333
|
it 'should send an end (busy) event to the translator' do
|
|
334
334
|
expected_end_event = Punchblock::Event::End.new :reason => :busy,
|
|
335
335
|
:target_call_id => subject.id
|
|
336
|
-
translator.
|
|
336
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
337
337
|
subject.process_ami_event ami_event
|
|
338
338
|
end
|
|
339
339
|
end
|
|
@@ -349,7 +349,7 @@ module Punchblock
|
|
|
349
349
|
it 'should send an end (timeout) event to the translator' do
|
|
350
350
|
expected_end_event = Punchblock::Event::End.new :reason => :timeout,
|
|
351
351
|
:target_call_id => subject.id
|
|
352
|
-
translator.
|
|
352
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
353
353
|
subject.process_ami_event ami_event
|
|
354
354
|
end
|
|
355
355
|
end
|
|
@@ -367,7 +367,7 @@ module Punchblock
|
|
|
367
367
|
it 'should send an end (reject) event to the translator' do
|
|
368
368
|
expected_end_event = Punchblock::Event::End.new :reason => :reject,
|
|
369
369
|
:target_call_id => subject.id
|
|
370
|
-
translator.
|
|
370
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
371
371
|
subject.process_ami_event ami_event
|
|
372
372
|
end
|
|
373
373
|
end
|
|
@@ -419,7 +419,7 @@ module Punchblock
|
|
|
419
419
|
it 'should send an end (error) event to the translator' do
|
|
420
420
|
expected_end_event = Punchblock::Event::End.new :reason => :error,
|
|
421
421
|
:target_call_id => subject.id
|
|
422
|
-
translator.
|
|
422
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
423
423
|
subject.process_ami_event ami_event
|
|
424
424
|
end
|
|
425
425
|
end
|
|
@@ -447,7 +447,7 @@ module Punchblock
|
|
|
447
447
|
end
|
|
448
448
|
|
|
449
449
|
it 'should send the event to the component' do
|
|
450
|
-
component.
|
|
450
|
+
component.should_receive(:handle_ami_event).once.with ami_event
|
|
451
451
|
subject.process_ami_event ami_event
|
|
452
452
|
end
|
|
453
453
|
end
|
|
@@ -474,7 +474,7 @@ module Punchblock
|
|
|
474
474
|
it 'should send a ringing event' do
|
|
475
475
|
expected_ringing = Punchblock::Event::Ringing.new
|
|
476
476
|
expected_ringing.target_call_id = subject.id
|
|
477
|
-
translator.
|
|
477
|
+
translator.should_receive(:handle_pb_event).with expected_ringing
|
|
478
478
|
subject.process_ami_event ami_event
|
|
479
479
|
end
|
|
480
480
|
|
|
@@ -491,7 +491,7 @@ module Punchblock
|
|
|
491
491
|
it 'should send a ringing event' do
|
|
492
492
|
expected_answered = Punchblock::Event::Answered.new
|
|
493
493
|
expected_answered.target_call_id = subject.id
|
|
494
|
-
translator.
|
|
494
|
+
translator.should_receive(:handle_pb_event).with expected_answered
|
|
495
495
|
subject.process_ami_event ami_event
|
|
496
496
|
end
|
|
497
497
|
|
|
@@ -523,7 +523,7 @@ module Punchblock
|
|
|
523
523
|
let(:uniqueid) { '<null>' }
|
|
524
524
|
|
|
525
525
|
it 'should not send an end event' do
|
|
526
|
-
translator.
|
|
526
|
+
translator.should_receive(:handle_pb_event).once.with an_instance_of(Punchblock::Event::Asterisk::AMI::Event)
|
|
527
527
|
subject.process_ami_event ami_event
|
|
528
528
|
end
|
|
529
529
|
end
|
|
@@ -533,7 +533,7 @@ module Punchblock
|
|
|
533
533
|
let(:uniqueid) { '1235' }
|
|
534
534
|
|
|
535
535
|
it 'should not send an end event' do
|
|
536
|
-
translator.
|
|
536
|
+
translator.should_receive(:handle_pb_event).once.with an_instance_of(Punchblock::Event::Asterisk::AMI::Event)
|
|
537
537
|
subject.process_ami_event ami_event
|
|
538
538
|
end
|
|
539
539
|
end
|
|
@@ -545,7 +545,7 @@ module Punchblock
|
|
|
545
545
|
it 'should send an error end event' do
|
|
546
546
|
expected_end_event = Punchblock::Event::End.new :reason => :error,
|
|
547
547
|
:target_call_id => subject.id
|
|
548
|
-
translator.
|
|
548
|
+
translator.should_receive(:handle_pb_event).with expected_end_event
|
|
549
549
|
subject.process_ami_event ami_event
|
|
550
550
|
end
|
|
551
551
|
end
|
|
@@ -565,7 +565,7 @@ module Punchblock
|
|
|
565
565
|
let(:response) { mock 'Response' }
|
|
566
566
|
|
|
567
567
|
it 'should execute the handler' do
|
|
568
|
-
response.
|
|
568
|
+
response.should_receive(:call).once.with ami_event
|
|
569
569
|
subject.register_handler :ami, :name => 'DTMF' do |event|
|
|
570
570
|
response.call event
|
|
571
571
|
end
|
|
@@ -637,8 +637,8 @@ module Punchblock
|
|
|
637
637
|
|
|
638
638
|
before do
|
|
639
639
|
translator.register_call other_call
|
|
640
|
-
translator.
|
|
641
|
-
other_call.
|
|
640
|
+
translator.should_receive(:call_for_channel).with(other_channel).and_return(other_call)
|
|
641
|
+
other_call.should_receive(:id).and_return other_call_id
|
|
642
642
|
end
|
|
643
643
|
|
|
644
644
|
context "of state 'Link'" do
|
|
@@ -652,12 +652,12 @@ module Punchblock
|
|
|
652
652
|
end
|
|
653
653
|
|
|
654
654
|
it 'sends the Joined event when the call is the first channel' do
|
|
655
|
-
translator.
|
|
655
|
+
translator.should_receive(:handle_pb_event).with expected_joined
|
|
656
656
|
subject.process_ami_event ami_event
|
|
657
657
|
end
|
|
658
658
|
|
|
659
659
|
it 'sends the Joined event when the call is the second channel' do
|
|
660
|
-
translator.
|
|
660
|
+
translator.should_receive(:handle_pb_event).with expected_joined
|
|
661
661
|
subject.process_ami_event switched_ami_event
|
|
662
662
|
end
|
|
663
663
|
end
|
|
@@ -673,12 +673,12 @@ module Punchblock
|
|
|
673
673
|
end
|
|
674
674
|
|
|
675
675
|
it 'sends the Unjoined event when the call is the first channel' do
|
|
676
|
-
translator.
|
|
676
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
677
677
|
subject.process_ami_event ami_event
|
|
678
678
|
end
|
|
679
679
|
|
|
680
680
|
it 'sends the Unjoined event when the call is the second channel' do
|
|
681
|
-
translator.
|
|
681
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
682
682
|
subject.process_ami_event switched_ami_event
|
|
683
683
|
end
|
|
684
684
|
end
|
|
@@ -717,8 +717,8 @@ module Punchblock
|
|
|
717
717
|
|
|
718
718
|
before do
|
|
719
719
|
translator.register_call other_call
|
|
720
|
-
translator.
|
|
721
|
-
other_call.
|
|
720
|
+
translator.should_receive(:call_for_channel).with(other_channel).and_return(other_call)
|
|
721
|
+
other_call.should_receive(:id).and_return other_call_id
|
|
722
722
|
end
|
|
723
723
|
|
|
724
724
|
let :expected_unjoined do
|
|
@@ -729,12 +729,12 @@ module Punchblock
|
|
|
729
729
|
end
|
|
730
730
|
|
|
731
731
|
it 'sends the Unjoined event when the call is the first channel' do
|
|
732
|
-
translator.
|
|
732
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
733
733
|
subject.process_ami_event ami_event
|
|
734
734
|
end
|
|
735
735
|
|
|
736
736
|
it 'sends the Unjoined event when the call is the second channel' do
|
|
737
|
-
translator.
|
|
737
|
+
translator.should_receive(:handle_pb_event).with expected_unjoined
|
|
738
738
|
subject.process_ami_event switched_ami_event
|
|
739
739
|
end
|
|
740
740
|
end
|
|
@@ -762,7 +762,7 @@ module Punchblock
|
|
|
762
762
|
end
|
|
763
763
|
|
|
764
764
|
it 'sends the AMI event to the connection as a PB event' do
|
|
765
|
-
translator.
|
|
765
|
+
translator.should_receive(:handle_pb_event).with expected_pb_event
|
|
766
766
|
subject.process_ami_event ami_event
|
|
767
767
|
end
|
|
768
768
|
|
|
@@ -862,9 +862,9 @@ module Punchblock
|
|
|
862
862
|
let(:mock_action) { mock 'Component::Asterisk::AGI::Command', :id => 'foo' }
|
|
863
863
|
|
|
864
864
|
it 'should create an AGI command component actor and execute it asynchronously' do
|
|
865
|
-
mock_action.
|
|
866
|
-
Component::Asterisk::AGICommand.
|
|
867
|
-
mock_action.
|
|
865
|
+
mock_action.should_receive(:internal=).never
|
|
866
|
+
Component::Asterisk::AGICommand.should_receive(:new_link).once.with(command, subject).and_return mock_action
|
|
867
|
+
mock_action.should_receive(:execute!).once
|
|
868
868
|
subject.execute_command command
|
|
869
869
|
end
|
|
870
870
|
end
|
|
@@ -877,9 +877,9 @@ module Punchblock
|
|
|
877
877
|
let(:mock_action) { mock 'Component::Asterisk::Output', :id => 'foo' }
|
|
878
878
|
|
|
879
879
|
it 'should create an Output component and execute it asynchronously' do
|
|
880
|
-
Component::Output.
|
|
881
|
-
mock_action.
|
|
882
|
-
mock_action.
|
|
880
|
+
Component::Output.should_receive(:new_link).once.with(command, subject).and_return mock_action
|
|
881
|
+
mock_action.should_receive(:internal=).never
|
|
882
|
+
mock_action.should_receive(:execute!).once
|
|
883
883
|
subject.execute_command command
|
|
884
884
|
end
|
|
885
885
|
end
|
|
@@ -892,9 +892,9 @@ module Punchblock
|
|
|
892
892
|
let(:mock_action) { mock 'Component::Asterisk::Input', :id => 'foo' }
|
|
893
893
|
|
|
894
894
|
it 'should create an Input component and execute it asynchronously' do
|
|
895
|
-
Component::Input.
|
|
896
|
-
mock_action.
|
|
897
|
-
mock_action.
|
|
895
|
+
Component::Input.should_receive(:new_link).once.with(command, subject).and_return mock_action
|
|
896
|
+
mock_action.should_receive(:internal=).never
|
|
897
|
+
mock_action.should_receive(:execute!).once
|
|
898
898
|
subject.execute_command command
|
|
899
899
|
end
|
|
900
900
|
end
|
|
@@ -907,9 +907,9 @@ module Punchblock
|
|
|
907
907
|
let(:mock_action) { mock 'Component::Asterisk::Record', :id => 'foo' }
|
|
908
908
|
|
|
909
909
|
it 'should create a Record component and execute it asynchronously' do
|
|
910
|
-
Component::Record.
|
|
911
|
-
mock_action.
|
|
912
|
-
mock_action.
|
|
910
|
+
Component::Record.should_receive(:new_link).once.with(command, subject).and_return mock_action
|
|
911
|
+
mock_action.should_receive(:internal=).never
|
|
912
|
+
mock_action.should_receive(:execute!).once
|
|
913
913
|
subject.execute_command command
|
|
914
914
|
end
|
|
915
915
|
end
|
|
@@ -929,7 +929,7 @@ module Punchblock
|
|
|
929
929
|
before { subject.register_component mock_component }
|
|
930
930
|
|
|
931
931
|
it 'should send the command to the component for execution' do
|
|
932
|
-
mock_component.
|
|
932
|
+
mock_component.should_receive(:execute_command).once
|
|
933
933
|
subject.execute_command command
|
|
934
934
|
end
|
|
935
935
|
end
|
|
@@ -963,7 +963,7 @@ module Punchblock
|
|
|
963
963
|
raise 'Woops, I died'
|
|
964
964
|
end
|
|
965
965
|
|
|
966
|
-
translator.
|
|
966
|
+
translator.should_receive(:handle_pb_event).once.with expected_event
|
|
967
967
|
|
|
968
968
|
lambda { component.oops }.should raise_error(/Woops, I died/)
|
|
969
969
|
sleep 0.1
|
|
@@ -998,7 +998,7 @@ module Punchblock
|
|
|
998
998
|
context "with a join command" do
|
|
999
999
|
let(:other_call_id) { "abc123" }
|
|
1000
1000
|
let(:other_channel) { 'SIP/bar' }
|
|
1001
|
-
let(:other_translator) {
|
|
1001
|
+
let(:other_translator) { stub('Translator::Asterisk').as_null_object }
|
|
1002
1002
|
|
|
1003
1003
|
let :other_call do
|
|
1004
1004
|
Call.new other_channel, other_translator
|
|
@@ -1009,7 +1009,7 @@ module Punchblock
|
|
|
1009
1009
|
end
|
|
1010
1010
|
|
|
1011
1011
|
it "executes the proper dialplan Bridge application" do
|
|
1012
|
-
translator.
|
|
1012
|
+
translator.should_receive(:call_with_id).with(other_call_id).and_return(other_call)
|
|
1013
1013
|
subject.execute_command command
|
|
1014
1014
|
agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command')
|
|
1015
1015
|
agi_command.name.should be == "EXEC Bridge"
|
|
@@ -1017,7 +1017,7 @@ module Punchblock
|
|
|
1017
1017
|
end
|
|
1018
1018
|
|
|
1019
1019
|
it "adds the join to the @pending_joins hash" do
|
|
1020
|
-
translator.
|
|
1020
|
+
translator.should_receive(:call_with_id).with(other_call_id).and_return(other_call)
|
|
1021
1021
|
subject.execute_command command
|
|
1022
1022
|
subject.pending_joins[other_channel].should be command
|
|
1023
1023
|
end
|
|
@@ -1036,7 +1036,7 @@ module Punchblock
|
|
|
1036
1036
|
end
|
|
1037
1037
|
|
|
1038
1038
|
it "executes the unjoin through redirection" do
|
|
1039
|
-
translator.
|
|
1039
|
+
translator.should_receive(:call_with_id).with(other_call_id).and_return(nil)
|
|
1040
1040
|
subject.execute_command command
|
|
1041
1041
|
ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
|
|
1042
1042
|
ami_action.name.should be == "redirect"
|
|
@@ -1050,7 +1050,7 @@ module Punchblock
|
|
|
1050
1050
|
end
|
|
1051
1051
|
|
|
1052
1052
|
it "executes the unjoin through redirection, on the subject call and the other call" do
|
|
1053
|
-
translator.
|
|
1053
|
+
translator.should_receive(:call_with_id).with(other_call_id).and_return(other_call)
|
|
1054
1054
|
subject.execute_command command
|
|
1055
1055
|
ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
|
|
1056
1056
|
ami_action.name.should be == "redirect"
|
|
@@ -1066,7 +1066,7 @@ module Punchblock
|
|
|
1066
1066
|
end
|
|
1067
1067
|
|
|
1068
1068
|
it "handles redirect errors" do
|
|
1069
|
-
translator.
|
|
1069
|
+
translator.should_receive(:call_with_id).with(other_call_id).and_return(nil)
|
|
1070
1070
|
subject.execute_command command
|
|
1071
1071
|
ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
|
|
1072
1072
|
ami_action.name.should be == "redirect"
|
|
@@ -1086,7 +1086,7 @@ module Punchblock
|
|
|
1086
1086
|
describe '#send_agi_action' do
|
|
1087
1087
|
it 'should send an appropriate AsyncAGI AMI action' do
|
|
1088
1088
|
pending
|
|
1089
|
-
subject.wrapped_object.
|
|
1089
|
+
subject.wrapped_object.should_receive(:send_ami_action).once.with('AGI', 'Command' => 'FOO', 'Channel' => subject.channel)
|
|
1090
1090
|
subject.send_agi_action 'FOO'
|
|
1091
1091
|
end
|
|
1092
1092
|
end
|
|
@@ -1097,7 +1097,7 @@ module Punchblock
|
|
|
1097
1097
|
|
|
1098
1098
|
it 'should send the action to the AMI client' do
|
|
1099
1099
|
action = RubyAMI::Action.new 'foo', :foo => :bar
|
|
1100
|
-
translator.
|
|
1100
|
+
translator.should_receive(:send_ami_action).once.with action
|
|
1101
1101
|
subject.send_ami_action 'foo', :foo => :bar
|
|
1102
1102
|
end
|
|
1103
1103
|
end
|