punchblock 2.5.2 → 2.5.3

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -0
  3. data/CHANGELOG.md +6 -0
  4. data/README.markdown +2 -1
  5. data/lib/punchblock/translator/asterisk/call.rb +3 -3
  6. data/lib/punchblock/translator/asterisk/component/mrcp_recog_prompt.rb +15 -9
  7. data/lib/punchblock/translator/asterisk/component/output.rb +8 -1
  8. data/lib/punchblock/translator/input_component.rb +2 -0
  9. data/lib/punchblock/version.rb +1 -1
  10. data/punchblock.gemspec +1 -1
  11. data/spec/punchblock/client/component_registry_spec.rb +3 -3
  12. data/spec/punchblock/client_spec.rb +22 -15
  13. data/spec/punchblock/command/accept_spec.rb +17 -7
  14. data/spec/punchblock/command/answer_spec.rb +19 -9
  15. data/spec/punchblock/command/dial_spec.rb +76 -27
  16. data/spec/punchblock/command/hangup_spec.rb +17 -7
  17. data/spec/punchblock/command/join_spec.rb +78 -24
  18. data/spec/punchblock/command/mute_spec.rb +3 -3
  19. data/spec/punchblock/command/redirect_spec.rb +33 -12
  20. data/spec/punchblock/command/reject_spec.rb +41 -14
  21. data/spec/punchblock/command/unjoin_spec.rb +29 -12
  22. data/spec/punchblock/command/unmute_spec.rb +3 -3
  23. data/spec/punchblock/command_node_spec.rb +43 -20
  24. data/spec/punchblock/component/asterisk/agi/command_spec.rb +52 -12
  25. data/spec/punchblock/component/asterisk/ami/action_spec.rb +69 -21
  26. data/spec/punchblock/component/component_node_spec.rb +12 -12
  27. data/spec/punchblock/component/input_spec.rb +304 -87
  28. data/spec/punchblock/component/output_spec.rb +434 -173
  29. data/spec/punchblock/component/prompt_spec.rb +63 -20
  30. data/spec/punchblock/component/receive_fax_spec.rb +43 -14
  31. data/spec/punchblock/component/record_spec.rb +215 -71
  32. data/spec/punchblock/component/send_fax_spec.rb +54 -15
  33. data/spec/punchblock/connection/asterisk_spec.rb +34 -24
  34. data/spec/punchblock/connection/freeswitch_spec.rb +9 -9
  35. data/spec/punchblock/connection/xmpp_spec.rb +92 -83
  36. data/spec/punchblock/event/answered_spec.rb +14 -4
  37. data/spec/punchblock/event/asterisk/ami/event_spec.rb +34 -12
  38. data/spec/punchblock/event/complete_spec.rb +36 -16
  39. data/spec/punchblock/event/dtmf_spec.rb +9 -3
  40. data/spec/punchblock/event/end_spec.rb +43 -10
  41. data/spec/punchblock/event/input_timers_started_spec.rb +1 -1
  42. data/spec/punchblock/event/joined_spec.rb +29 -7
  43. data/spec/punchblock/event/offer_spec.rb +41 -10
  44. data/spec/punchblock/event/ringing_spec.rb +14 -4
  45. data/spec/punchblock/event/started_speaking_spec.rb +9 -3
  46. data/spec/punchblock/event/stopped_speaking_spec.rb +9 -3
  47. data/spec/punchblock/event/unjoined_spec.rb +24 -6
  48. data/spec/punchblock/protocol_error_spec.rb +16 -13
  49. data/spec/punchblock/ref_spec.rb +90 -26
  50. data/spec/punchblock/translator/asterisk/call_spec.rb +176 -161
  51. data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +18 -18
  52. data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +9 -9
  53. data/spec/punchblock/translator/asterisk/component/composed_prompt_spec.rb +14 -14
  54. data/spec/punchblock/translator/asterisk/component/input_spec.rb +57 -36
  55. data/spec/punchblock/translator/asterisk/component/mrcp_native_prompt_spec.rb +50 -50
  56. data/spec/punchblock/translator/asterisk/component/mrcp_prompt_spec.rb +59 -48
  57. data/spec/punchblock/translator/asterisk/component/output_spec.rb +231 -221
  58. data/spec/punchblock/translator/asterisk/component/record_spec.rb +82 -82
  59. data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +10 -10
  60. data/spec/punchblock/translator/asterisk/component_spec.rb +4 -4
  61. data/spec/punchblock/translator/asterisk_spec.rb +89 -82
  62. data/spec/punchblock/translator/freeswitch/call_spec.rb +114 -99
  63. data/spec/punchblock/translator/freeswitch/component/flite_output_spec.rb +19 -19
  64. data/spec/punchblock/translator/freeswitch/component/input_spec.rb +24 -24
  65. data/spec/punchblock/translator/freeswitch/component/output_spec.rb +23 -23
  66. data/spec/punchblock/translator/freeswitch/component/record_spec.rb +78 -78
  67. data/spec/punchblock/translator/freeswitch/component/tts_output_spec.rb +19 -19
  68. data/spec/punchblock/translator/freeswitch/component_spec.rb +8 -8
  69. data/spec/punchblock/translator/freeswitch_spec.rb +66 -59
  70. data/spec/punchblock/uri_list_spec.rb +45 -10
  71. data/spec/punchblock_spec.rb +13 -13
  72. data/spec/spec_helper.rb +18 -11
  73. data/spec/support/mock_connection_with_event_handler.rb +1 -1
  74. metadata +5 -4
@@ -34,7 +34,7 @@ module Punchblock
34
34
  end
35
35
 
36
36
  it "should send the event to the connection" do
37
- connection.should_receive(:handle_event).once.with expected_event
37
+ expect(connection).to receive(:handle_event).once.with expected_event
38
38
  subject.send_event event
39
39
  end
40
40
  end
@@ -48,14 +48,14 @@ module Punchblock
48
48
  end
49
49
 
50
50
  it "should send a complete event with the specified reason" do
51
- subject.should_receive(:send_event).once.with expected_event
51
+ expect(subject).to receive(:send_event).once.with expected_event
52
52
  subject.send_complete_event reason
53
53
  end
54
54
  end
55
55
 
56
56
  describe "#call_ended" do
57
57
  it "should send a complete event with the call hangup reason" do
58
- subject.should_receive(:send_complete_event).once.with Punchblock::Event::Complete::Hangup.new
58
+ expect(subject).to receive(:send_complete_event).once.with Punchblock::Event::Complete::Hangup.new
59
59
  subject.call_ended
60
60
  end
61
61
  end
@@ -72,7 +72,7 @@ module Punchblock
72
72
 
73
73
  it 'sends an error in response to the command' do
74
74
  subject.execute_command component_command
75
- component_command.response.should be == ProtocolError.new.setup('command-not-acceptable', "Did not understand command for component #{subject.id}", call.id, subject.id)
75
+ expect(component_command.response).to eq(ProtocolError.new.setup('command-not-acceptable', "Did not understand command for component #{subject.id}", call.id, subject.id))
76
76
  end
77
77
  end
78
78
  end
@@ -13,8 +13,15 @@ module Punchblock
13
13
 
14
14
  subject { translator }
15
15
 
16
- its(:ami_client) { should be ami_client }
17
- its(:connection) { should be connection }
16
+ describe '#ami_client' do
17
+ subject { super().ami_client }
18
+ it { should be ami_client }
19
+ end
20
+
21
+ describe '#connection' do
22
+ subject { super().connection }
23
+ it { should be connection }
24
+ end
18
25
 
19
26
  before do
20
27
  connection.event_handler = ->(*) {}
@@ -28,10 +35,10 @@ module Punchblock
28
35
  let(:call_id) { 'abc123' }
29
36
 
30
37
  it 'executes the call command' do
31
- subject.wrapped_object.should_receive(:execute_call_command).with do |c|
32
- c.should be command
33
- c.target_call_id.should be == call_id
34
- end
38
+ expect(subject.wrapped_object).to receive(:execute_call_command).with { |c|
39
+ expect(c).to be command
40
+ expect(c.target_call_id).to eq(call_id)
41
+ }
35
42
  subject.execute_command command, :call_id => call_id
36
43
  end
37
44
  end
@@ -41,10 +48,10 @@ module Punchblock
41
48
  let(:component_id) { '123abc' }
42
49
 
43
50
  it 'executes the component command' do
44
- subject.wrapped_object.should_receive(:execute_component_command).with do |c|
45
- c.should be command
46
- c.component_id.should be == component_id
47
- end
51
+ expect(subject.wrapped_object).to receive(:execute_component_command).with { |c|
52
+ expect(c).to be command
53
+ expect(c.component_id).to eq(component_id)
54
+ }
48
55
  subject.execute_command command, :component_id => component_id
49
56
  end
50
57
  end
@@ -53,7 +60,7 @@ module Punchblock
53
60
  let(:command) { Command::Dial.new }
54
61
 
55
62
  it 'executes the command directly' do
56
- subject.wrapped_object.should_receive(:execute_global_command).with command
63
+ expect(subject.wrapped_object).to receive(:execute_global_command).with command
57
64
  subject.execute_command command
58
65
  end
59
66
  end
@@ -65,19 +72,19 @@ module Punchblock
65
72
  let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject, ami_client, connection }
66
73
 
67
74
  before do
68
- call.stub(:id).and_return call_id
75
+ allow(call).to receive(:id).and_return call_id
69
76
  subject.register_call call
70
77
  end
71
78
 
72
79
  it 'sends the command to the call for execution' do
73
- call.should_receive(:send_message).once.with body
80
+ expect(call).to receive(:send_message).once.with body
74
81
  subject.send_message call_id, 'example.com', body, subject: 'stuff'
75
82
  end
76
83
 
77
84
  context "when the call doesn't exist" do
78
85
  it "should not crash the translator" do
79
86
  subject.send_message 'oops', 'example.com', body, subject: 'stuff'
80
- subject.should be_alive
87
+ expect(subject).to be_alive
81
88
  end
82
89
  end
83
90
  end
@@ -88,16 +95,16 @@ module Punchblock
88
95
  let(:call) { Translator::Asterisk::Call.new channel, subject, ami_client, connection }
89
96
 
90
97
  before do
91
- call.stub(:id).and_return call_id
98
+ allow(call).to receive(:id).and_return call_id
92
99
  subject.register_call call
93
100
  end
94
101
 
95
102
  it 'should make the call accessible by ID' do
96
- subject.call_with_id(call_id).should be call
103
+ expect(subject.call_with_id(call_id)).to be call
97
104
  end
98
105
 
99
106
  it 'should make the call accessible by channel' do
100
- subject.call_for_channel(channel).should be call
107
+ expect(subject.call_for_channel(channel)).to be call
101
108
  end
102
109
  end
103
110
 
@@ -107,20 +114,20 @@ module Punchblock
107
114
  let(:call) { Translator::Asterisk::Call.new channel, subject, ami_client, connection }
108
115
 
109
116
  before do
110
- call.stub(:id).and_return call_id
117
+ allow(call).to receive(:id).and_return call_id
111
118
  subject.register_call call
112
119
  end
113
120
 
114
121
  it 'should make the call inaccessible by ID' do
115
- subject.call_with_id(call_id).should be call
122
+ expect(subject.call_with_id(call_id)).to be call
116
123
  subject.deregister_call call_id, channel
117
- subject.call_with_id(call_id).should be_nil
124
+ expect(subject.call_with_id(call_id)).to be_nil
118
125
  end
119
126
 
120
127
  it 'should make the call inaccessible by channel' do
121
- subject.call_for_channel(channel).should be call
128
+ expect(subject.call_for_channel(channel)).to be call
122
129
  subject.deregister_call call_id, channel
123
- subject.call_for_channel(channel).should be_nil
130
+ expect(subject.call_for_channel(channel)).to be_nil
124
131
  end
125
132
  end
126
133
 
@@ -130,7 +137,7 @@ module Punchblock
130
137
 
131
138
  it 'should make the component accessible by ID' do
132
139
  subject.register_component component
133
- subject.component_with_id(component_id).should be component
140
+ expect(subject.component_with_id(component_id)).to be component
134
141
  end
135
142
  end
136
143
 
@@ -143,18 +150,18 @@ module Punchblock
143
150
 
144
151
  before do
145
152
  command.request!
146
- call.stub(:id).and_return call_id
153
+ allow(call).to receive(:id).and_return call_id
147
154
  subject.register_call call
148
155
  end
149
156
 
150
157
  it 'sends the command to the call for execution' do
151
- call.should_receive(:execute_command).once.with command
158
+ expect(call).to receive(:execute_command).once.with command
152
159
  subject.execute_call_command command
153
160
  end
154
161
 
155
162
  context 'when it raises' do
156
163
  before do
157
- call.should_receive(:execute_command).and_raise StandardError
164
+ expect(call).to receive(:execute_command).and_raise StandardError
158
165
  end
159
166
 
160
167
  let(:other_command) { Command::Answer.new target_call_id: call_id }
@@ -162,11 +169,11 @@ module Punchblock
162
169
  it 'sends an error in response to the command' do
163
170
  subject.execute_call_command command
164
171
 
165
- subject.call_with_id(call_id).should be_nil
172
+ expect(subject.call_with_id(call_id)).to be_nil
166
173
 
167
174
  other_command.request!
168
175
  subject.execute_call_command other_command
169
- other_command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{call_id}", call_id)
176
+ expect(other_command.response).to eq(ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{call_id}", call_id))
170
177
  end
171
178
  end
172
179
  end
@@ -179,7 +186,7 @@ module Punchblock
179
186
  it 'sends an error in response to the command' do
180
187
  command.request!
181
188
  subject.execute_call_command command
182
- command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{call_id}", call_id, nil)
189
+ expect(command.response).to eq(ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{call_id}", call_id, nil))
183
190
  end
184
191
  end
185
192
  end
@@ -201,7 +208,7 @@ module Punchblock
201
208
  end
202
209
 
203
210
  it 'sends the command to the component for execution' do
204
- component.should_receive(:execute_command).once.with command
211
+ expect(component).to receive(:execute_command).once.with command
205
212
  subject.execute_component_command command
206
213
  end
207
214
  end
@@ -209,7 +216,7 @@ module Punchblock
209
216
  context "with an unknown component ID" do
210
217
  it 'sends an error in response to the command' do
211
218
  subject.execute_component_command command
212
- command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component.id}", nil, component.id)
219
+ expect(command.response).to eq(ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component.id}", nil, component.id))
213
220
  end
214
221
  end
215
222
  end
@@ -222,19 +229,19 @@ module Punchblock
222
229
 
223
230
  before do
224
231
  command.request!
225
- ami_client.stub(:send_action).and_return RubyAMI::Response.new
232
+ allow(ami_client).to receive(:send_action).and_return RubyAMI::Response.new
226
233
  end
227
234
 
228
235
  it 'should be able to look up the call by channel ID' do
229
236
  subject.execute_global_command command
230
237
  call = subject.call_for_channel('SIP/1234')
231
- call.should be_a Asterisk::Call
238
+ expect(call).to be_a Asterisk::Call
232
239
  end
233
240
 
234
241
  it 'should instruct the call to send a dial' do
235
242
  mock_call = double('Asterisk::Call').as_null_object
236
- Asterisk::Call.should_receive(:new).once.and_return mock_call
237
- mock_call.should_receive(:dial).once.with command
243
+ expect(Asterisk::Call).to receive(:new).once.and_return mock_call
244
+ expect(mock_call).to receive(:dial).once.with command
238
245
  subject.execute_global_command command
239
246
  end
240
247
 
@@ -247,7 +254,7 @@ module Punchblock
247
254
 
248
255
  it "should assign the requested URI to the call" do
249
256
  subject.execute_global_command command
250
- subject.call_with_id(requested_uri).id.should == requested_uri
257
+ expect(subject.call_with_id(requested_uri).id).to eq(requested_uri)
251
258
  end
252
259
 
253
260
  context 'and the requested URI already represents a known call' do
@@ -263,11 +270,11 @@ module Punchblock
263
270
  end
264
271
 
265
272
  it "should set the command response to a conflict error" do
266
- command.response(0.1).should == ProtocolError.new.setup(:conflict, 'Call ID already in use')
273
+ expect(command.response(0.1)).to eq(ProtocolError.new.setup(:conflict, 'Call ID already in use'))
267
274
  end
268
275
 
269
276
  it "should not replace the original call in the registry" do
270
- subject.call_with_id(requested_uri).should be @first_call
277
+ expect(subject.call_with_id(requested_uri)).to be @first_call
271
278
  end
272
279
  end
273
280
  end
@@ -281,14 +288,14 @@ module Punchblock
281
288
  let(:mock_action) { double('Asterisk::Component::Asterisk::AMIAction').as_null_object }
282
289
 
283
290
  it 'should create a component actor and execute it asynchronously' do
284
- Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject, ami_client).and_return mock_action
285
- mock_action.should_receive(:execute).once
291
+ expect(Asterisk::Component::Asterisk::AMIAction).to receive(:new).once.with(command, subject, ami_client).and_return mock_action
292
+ expect(mock_action).to receive(:execute).once
286
293
  subject.execute_global_command command
287
294
  end
288
295
 
289
296
  it 'registers the component' do
290
- Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject, ami_client).and_return mock_action
291
- subject.wrapped_object.should_receive(:register_component).with mock_action
297
+ expect(Asterisk::Component::Asterisk::AMIAction).to receive(:new).once.with(command, subject, ami_client).and_return mock_action
298
+ expect(subject.wrapped_object).to receive(:register_component).with mock_action
292
299
  subject.execute_global_command command
293
300
  end
294
301
  end
@@ -300,7 +307,7 @@ module Punchblock
300
307
 
301
308
  it 'sends an error in response to the command' do
302
309
  subject.execute_command command
303
- command.response.should be == ProtocolError.new.setup('command-not-acceptable', "Did not understand command")
310
+ expect(command.response).to eq(ProtocolError.new.setup('command-not-acceptable', "Did not understand command"))
304
311
  end
305
312
  end
306
313
  end
@@ -308,7 +315,7 @@ module Punchblock
308
315
  describe '#handle_pb_event' do
309
316
  it 'should forward the event to the connection' do
310
317
  event = double 'Punchblock::Event'
311
- subject.connection.should_receive(:handle_event).once.with event
318
+ expect(subject.connection).to receive(:handle_event).once.with event
312
319
  subject.handle_pb_event event
313
320
  end
314
321
  end
@@ -331,7 +338,7 @@ module Punchblock
331
338
  end
332
339
 
333
340
  it 'should create a Punchblock AMI event object and pass it to the connection' do
334
- subject.connection.should_receive(:handle_event).once.with expected_pb_event
341
+ expect(subject.connection).to receive(:handle_event).once.with expected_pb_event
335
342
  subject.handle_ami_event ami_event
336
343
  end
337
344
 
@@ -340,14 +347,14 @@ module Punchblock
340
347
  after { described_class.event_filter = nil }
341
348
 
342
349
  it 'does not send the AMI event to the connection as a PB event' do
343
- subject.connection.should_receive(:handle_event).never
350
+ expect(subject.connection).to receive(:handle_event).never
344
351
  subject.handle_ami_event ami_event
345
352
  end
346
353
  end
347
354
 
348
355
  context 'with something that is not a RubyAMI::Event' do
349
356
  it 'does not send anything to the connection' do
350
- subject.connection.should_receive(:handle_event).never
357
+ expect(subject.connection).to receive(:handle_event).never
351
358
  subject.handle_ami_event :foo
352
359
  end
353
360
  end
@@ -356,8 +363,8 @@ module Punchblock
356
363
  let(:ami_event) { RubyAMI::Event.new 'FullyBooted' }
357
364
 
358
365
  it 'sends a connected event to the event handler' do
359
- subject.connection.should_receive(:handle_event).once.with Connection::Connected.new
360
- subject.wrapped_object.should_receive(:run_at_fully_booted).once
366
+ expect(subject.connection).to receive(:handle_event).once.with Connection::Connected.new
367
+ expect(subject.wrapped_object).to receive(:run_at_fully_booted).once
361
368
  subject.handle_ami_event ami_event
362
369
  end
363
370
  end
@@ -370,14 +377,14 @@ module Punchblock
370
377
  'Env' => "agi_request%3A%20async%0Aagi_channel%3A%20SIP%2F1234-00000000%0Aagi_language%3A%20en%0Aagi_type%3A%20SIP%0Aagi_uniqueid%3A%201320835995.0%0Aagi_version%3A%201.8.4.1%0Aagi_callerid%3A%205678%0Aagi_calleridname%3A%20Jane%20Smith%0Aagi_callingpres%3A%200%0Aagi_callingani2%3A%200%0Aagi_callington%3A%200%0Aagi_callingtns%3A%200%0Aagi_dnid%3A%201000%0Aagi_rdnis%3A%20unknown%0Aagi_context%3A%20default%0Aagi_extension%3A%201000%0Aagi_priority%3A%201%0Aagi_enhanced%3A%200.0%0Aagi_accountcode%3A%20%0Aagi_threadid%3A%204366221312%0A%0A"
371
378
  end
372
379
 
373
- before { subject.wrapped_object.stub :handle_pb_event }
380
+ before { allow(subject.wrapped_object).to receive :handle_pb_event }
374
381
 
375
382
  it 'should be able to look up the call by channel ID' do
376
383
  subject.handle_ami_event ami_event
377
384
  call = subject.call_for_channel('SIP/1234-00000000')
378
- call.should be_a Asterisk::Call
379
- call.agi_env.should be_a Hash
380
- call.agi_env.should be == {
385
+ expect(call).to be_a Asterisk::Call
386
+ expect(call.agi_env).to be_a Hash
387
+ expect(call.agi_env).to eq({
381
388
  :agi_request => 'async',
382
389
  :agi_channel => 'SIP/1234-00000000',
383
390
  :agi_language => 'en',
@@ -398,13 +405,13 @@ module Punchblock
398
405
  :agi_enhanced => '0.0',
399
406
  :agi_accountcode => '',
400
407
  :agi_threadid => '4366221312'
401
- }
408
+ })
402
409
  end
403
410
 
404
411
  it 'should instruct the call to send an offer' do
405
412
  mock_call = double('Asterisk::Call').as_null_object
406
- Asterisk::Call.should_receive(:new).once.and_return mock_call
407
- mock_call.should_receive(:send_offer).once
413
+ expect(Asterisk::Call).to receive(:new).once.and_return mock_call
414
+ expect(mock_call).to receive(:send_offer).once
408
415
  subject.handle_ami_event ami_event
409
416
  end
410
417
 
@@ -416,7 +423,7 @@ module Punchblock
416
423
  end
417
424
 
418
425
  it "should not create a new call" do
419
- Asterisk::Call.should_receive(:new).never
426
+ expect(Asterisk::Call).to receive(:new).never
420
427
  subject.handle_ami_event ami_event
421
428
  end
422
429
  end
@@ -430,13 +437,13 @@ module Punchblock
430
437
  end
431
438
 
432
439
  it "should not create a new call" do
433
- Asterisk::Call.should_receive(:new).never
440
+ expect(Asterisk::Call).to receive(:new).never
434
441
  subject.handle_ami_event ami_event
435
442
  end
436
443
 
437
444
  it 'should not be able to look up the call by channel ID' do
438
445
  subject.handle_ami_event ami_event
439
- subject.call_for_channel('SIP/1234-00000000').should be nil
446
+ expect(subject.call_for_channel('SIP/1234-00000000')).to be nil
440
447
  end
441
448
  end
442
449
 
@@ -449,13 +456,13 @@ module Punchblock
449
456
  end
450
457
 
451
458
  it "should not create a new call" do
452
- Asterisk::Call.should_receive(:new).never
459
+ expect(Asterisk::Call).to receive(:new).never
453
460
  subject.handle_ami_event ami_event
454
461
  end
455
462
 
456
463
  it 'should not be able to look up the call by channel ID' do
457
464
  subject.handle_ami_event ami_event
458
- subject.call_for_channel('SIP/1234-00000000').should be nil
465
+ expect(subject.call_for_channel('SIP/1234-00000000')).to be nil
459
466
  end
460
467
  end
461
468
  end
@@ -472,7 +479,7 @@ module Punchblock
472
479
 
473
480
  before do
474
481
  ami_client.as_null_object
475
- subject.wrapped_object.stub :handle_pb_event
482
+ allow(subject.wrapped_object).to receive :handle_pb_event
476
483
  end
477
484
 
478
485
  context "matching a call that was created by a Dial command" do
@@ -489,17 +496,17 @@ module Punchblock
489
496
 
490
497
  it "should set the correct channel on the call" do
491
498
  subject.handle_ami_event ami_event
492
- call.channel.should be == 'SIP/1234-00000000'
499
+ expect(call.channel).to eq('SIP/1234-00000000')
493
500
  end
494
501
 
495
502
  it "should make it possible to look up the call by the full channel name" do
496
503
  subject.handle_ami_event ami_event
497
- subject.call_for_channel("SIP/1234-00000000").should be call
504
+ expect(subject.call_for_channel("SIP/1234-00000000")).to be call
498
505
  end
499
506
 
500
507
  it "should make looking up the channel by the requested channel name impossible" do
501
508
  subject.handle_ami_event ami_event
502
- subject.call_for_channel('SIP/1234').should be_nil
509
+ expect(subject.call_for_channel('SIP/1234')).to be_nil
503
510
  end
504
511
  end
505
512
 
@@ -507,7 +514,7 @@ module Punchblock
507
514
  let(:call_id) { 'foobarbaz' }
508
515
 
509
516
  it "should not raise" do
510
- lambda { subject.handle_ami_event ami_event }.should_not raise_error
517
+ expect { subject.handle_ami_event ami_event }.not_to raise_error
511
518
  end
512
519
  end
513
520
  end
@@ -532,7 +539,7 @@ module Punchblock
532
539
  end
533
540
 
534
541
  it 'sends the AMI event to the call and to the connection as a PB event' do
535
- call.should_receive(:process_ami_event).once.with ami_event
542
+ expect(call).to receive(:process_ami_event).once.with ami_event
536
543
  subject.handle_ami_event ami_event
537
544
  end
538
545
 
@@ -553,8 +560,8 @@ module Punchblock
553
560
  before { subject.register_call call2 }
554
561
 
555
562
  it 'should send the event to both calls and to the connection once as a PB event' do
556
- call.should_receive(:process_ami_event).once.with ami_event
557
- call2.should_receive(:process_ami_event).once.with ami_event
563
+ expect(call).to receive(:process_ami_event).once.with ami_event
564
+ expect(call2).to receive(:process_ami_event).once.with ami_event
558
565
  subject.handle_ami_event ami_event
559
566
  end
560
567
  end
@@ -587,12 +594,12 @@ module Punchblock
587
594
  end
588
595
 
589
596
  it 'sends the AMI event to the call and to the connection as a PB event if it is an allowed event' do
590
- call.should_receive(:process_ami_event).once.with ami_event
597
+ expect(call).to receive(:process_ami_event).once.with ami_event
591
598
  subject.handle_ami_event ami_event
592
599
  end
593
600
 
594
601
  it 'does not send the AMI event to a bridged channel if it is not allowed' do
595
- call.should_receive(:process_ami_event).never.with ami_event2
602
+ expect(call).to receive(:process_ami_event).never.with ami_event2
596
603
  subject.handle_ami_event ami_event2
597
604
  end
598
605
 
@@ -611,29 +618,29 @@ module Punchblock
611
618
  end
612
619
 
613
620
  it 'should send the redirect extension Command to the AMI client' do
614
- ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
615
- ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
621
+ expect(ami_client).to receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
622
+ expect(ami_client).to receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
616
623
  subject.run_at_fully_booted
617
624
  end
618
625
 
619
626
  it 'should check the context for existence and do nothing if it is there' do
620
- ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
621
- ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
627
+ expect(ami_client).to receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
628
+ expect(ami_client).to receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
622
629
  subject.run_at_fully_booted
623
630
  end
624
631
 
625
632
  it 'should check the context for existence and log an error if it is not there' do
626
- ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
627
- ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(failed_show)
628
- Punchblock.logger.should_receive(:error).once.with("Punchblock failed to add the #{Asterisk::REDIRECT_EXTENSION} extension to the #{Asterisk::REDIRECT_CONTEXT} context. Please add a [#{Asterisk::REDIRECT_CONTEXT}] entry to your dialplan.")
633
+ expect(ami_client).to receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
634
+ expect(ami_client).to receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(failed_show)
635
+ expect(Punchblock.logger).to receive(:error).once.with("Punchblock failed to add the #{Asterisk::REDIRECT_EXTENSION} extension to the #{Asterisk::REDIRECT_CONTEXT} context. Please add a [#{Asterisk::REDIRECT_CONTEXT}] entry to your dialplan.")
629
636
  subject.run_at_fully_booted
630
637
  end
631
638
 
632
639
  it 'should check the recording directory for existence' do
633
640
  stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
634
- ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
635
- ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
636
- Punchblock.logger.should_receive(:warn).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
641
+ expect(ami_client).to receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
642
+ expect(ami_client).to receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_return(passed_show)
643
+ expect(Punchblock.logger).to receive(:warn).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
637
644
  subject.run_at_fully_booted
638
645
  end
639
646
  end
@@ -642,7 +649,7 @@ module Punchblock
642
649
  let(:broken_path) { "/this/is/not/a/valid/path" }
643
650
  it 'logs a warning if the recording directory does not exist' do
644
651
  stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
645
- Punchblock.logger.should_receive(:warn).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
652
+ expect(Punchblock.logger).to receive(:warn).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
646
653
  subject.check_recording_directory
647
654
  end
648
655
  end