adhearsion 2.3.0 → 2.3.1

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +3 -0
  4. data/LICENSE +1 -1
  5. data/README.markdown +2 -2
  6. data/adhearsion.gemspec +0 -1
  7. data/lib/adhearsion/punchblock_plugin/initializer.rb +1 -1
  8. data/lib/adhearsion/version.rb +1 -1
  9. data/spec/adhearsion/call_controller/dial_spec.rb +56 -57
  10. data/spec/adhearsion/call_controller/input_spec.rb +11 -16
  11. data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +6 -6
  12. data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +10 -10
  13. data/spec/adhearsion/call_controller/output/async_player_spec.rb +3 -3
  14. data/spec/adhearsion/call_controller/output/player_spec.rb +1 -1
  15. data/spec/adhearsion/call_controller/output_spec.rb +2 -7
  16. data/spec/adhearsion/call_controller/record_spec.rb +11 -18
  17. data/spec/adhearsion/call_controller_spec.rb +35 -35
  18. data/spec/adhearsion/call_spec.rb +49 -35
  19. data/spec/adhearsion/calls_spec.rb +2 -2
  20. data/spec/adhearsion/console_spec.rb +22 -23
  21. data/spec/adhearsion/events_spec.rb +3 -3
  22. data/spec/adhearsion/initializer_spec.rb +33 -35
  23. data/spec/adhearsion/logging_spec.rb +3 -3
  24. data/spec/adhearsion/outbound_call_spec.rb +21 -19
  25. data/spec/adhearsion/plugin_spec.rb +9 -11
  26. data/spec/adhearsion/process_spec.rb +15 -14
  27. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +37 -42
  28. data/spec/adhearsion/punchblock_plugin_spec.rb +2 -2
  29. data/spec/adhearsion/router/evented_route_spec.rb +1 -1
  30. data/spec/adhearsion/router/openended_route_spec.rb +5 -5
  31. data/spec/adhearsion/router/route_spec.rb +9 -9
  32. data/spec/adhearsion/router/unaccepting_route_spec.rb +6 -6
  33. data/spec/adhearsion/router_spec.rb +8 -8
  34. data/spec/adhearsion/statistics_spec.rb +1 -1
  35. data/spec/adhearsion_spec.rb +1 -1
  36. data/spec/spec_helper.rb +1 -2
  37. data/spec/support/call_controller_test_helpers.rb +11 -8
  38. data/spec/support/initializer_stubs.rb +1 -1
  39. data/spec/support/punchblock_mocks.rb +3 -2
  40. metadata +2 -16
@@ -9,7 +9,7 @@ module Adhearsion
9
9
  describe AsyncPlayer do
10
10
  include CallControllerTestHelpers
11
11
 
12
- let(:controller) { flexmock new_controller }
12
+ let(:controller) { new_controller }
13
13
 
14
14
  subject { AsyncPlayer.new controller }
15
15
 
@@ -43,9 +43,9 @@ module Adhearsion
43
43
  response = Punchblock::Event::Complete.new
44
44
  response.reason = Punchblock::Event::Complete::Error.new
45
45
  component = Punchblock::Component::Output.new(:ssml => content)
46
- flexmock subject, :new_output => component
46
+ subject.stub :new_output => component
47
47
  expect_message_waiting_for_response component
48
- flexmock(controller.logger).should_receive(:error).once
48
+ controller.logger.should_receive(:error).once
49
49
  subject.output content
50
50
  component.request!
51
51
  component.execute!
@@ -9,7 +9,7 @@ module Adhearsion
9
9
  describe Player do
10
10
  include CallControllerTestHelpers
11
11
 
12
- let(:controller) { flexmock new_controller }
12
+ let(:controller) { new_controller }
13
13
 
14
14
  subject { Player.new controller }
15
15
 
@@ -692,12 +692,7 @@ module Adhearsion
692
692
  }
693
693
 
694
694
  def expect_component_complete_event
695
- complete_event = Punchblock::Event::Complete.new
696
- flexmock(complete_event).should_receive(:reason => flexmock(:utterance => 'dtmf-5'))
697
- flexmock(Punchblock::Component::Input).new_instances do |input|
698
- input.should_receive(:complete?).and_return(false)
699
- input.should_receive(:complete_event).and_return(complete_event)
700
- end
695
+ expect_input_component_complete_event 'dtmf-5'
701
696
  end
702
697
 
703
698
  #test does pass and method works, but not sure if the empty method is a good idea
@@ -717,7 +712,7 @@ module Adhearsion
717
712
  end
718
713
 
719
714
  expect_component_complete_event
720
- flexmock(Punchblock::Component::Output).new_instances.should_receive(:stop!)
715
+ Punchblock::Component::Output.any_instance.should_receive(:stop!)
721
716
  expect_component_execution output_component
722
717
  subject.stream_file(prompt, allowed_digits).should be == '5'
723
718
  end
@@ -101,7 +101,7 @@ module Adhearsion
101
101
  end
102
102
 
103
103
  it "stops the recording" do
104
- flexmock(subject.record_component).should_receive(:stop!).once
104
+ subject.record_component.should_receive(:stop!).once
105
105
  subject.stopper_component.trigger_event_handler complete_event
106
106
  end
107
107
  end
@@ -110,7 +110,7 @@ module Adhearsion
110
110
  it "stops the input component" do
111
111
  controller.should_receive(:execute_component_and_await_completion).once.with(component)
112
112
  controller.should_receive(:write_and_await_response).once.with(input_component)
113
- flexmock(subject.stopper_component).should_receive(:stop!).once
113
+ subject.stopper_component.should_receive(:stop!).once
114
114
  subject.run
115
115
  end
116
116
  end
@@ -139,8 +139,8 @@ module Adhearsion
139
139
  let(:complete_event) { Punchblock::Event::Complete.new }
140
140
 
141
141
  it "should execute those handlers when recording completes" do
142
- foo = flexmock 'foo'
143
- foo.should_receive(:call).once.with Punchblock::Event::Complete
142
+ foo = mock 'foo'
143
+ foo.should_receive(:call).once.with kind_of(Punchblock::Event::Complete)
144
144
  subject.handle_record_completion { |e| foo.call e }
145
145
  subject.record_component.trigger_event_handler complete_event
146
146
  end
@@ -164,7 +164,7 @@ module Adhearsion
164
164
  describe "with :async => true and an :on_complete callback" do
165
165
  before do
166
166
  component
167
- flexmock(Punchblock::Component::Record).should_receive(:new).once.with(parsed_options).and_return component
167
+ Punchblock::Component::Record.should_receive(:new).once.with(parsed_options).and_return component
168
168
  expect_message_waiting_for_response component
169
169
  @rec = Queue.new
170
170
  subject.record(options.merge(async: true)) { |rec| @rec.push rec }
@@ -184,7 +184,7 @@ module Adhearsion
184
184
  before do
185
185
  TestException = Class.new StandardError
186
186
  component
187
- flexmock(Punchblock::Component::Record).should_receive(:new).once.with({}).and_return component
187
+ Punchblock::Component::Record.should_receive(:new).once.with({}).and_return component
188
188
  end
189
189
 
190
190
  it "should pass the exception to the events system" do
@@ -207,7 +207,7 @@ module Adhearsion
207
207
  describe "with :async => false" do
208
208
  before do
209
209
  component
210
- flexmock(Punchblock::Component::Record).should_receive(:new).once.with(parsed_options).and_return component
210
+ Punchblock::Component::Record.should_receive(:new).once.with(parsed_options).and_return component
211
211
  expect_component_execution component
212
212
  @rec = Queue.new
213
213
  subject.record(options.merge(:async => false)) { |rec| @rec.push rec }
@@ -233,21 +233,14 @@ module Adhearsion
233
233
  end
234
234
 
235
235
  describe "with :interruptible => true" do
236
- let(:input_component) { Punchblock::Component::Input.new }
237
236
  it "stops the recording" do
238
- flexmock(Punchblock::Event::Complete).new_instances.should_receive(:reason => flexmock(:name => :input))
239
-
240
237
  def subject.write_and_await_response(input_component)
241
238
  input_component.trigger_event_handler Punchblock::Event::Complete.new
242
239
  end
243
240
 
244
- complete_event = Punchblock::Event::Complete.new
245
- flexmock(complete_event).should_receive(:reason => flexmock(:name => :input))
246
- flexmock(Punchblock::Component::Input).new_instances do |input|
247
- input.should_receive(:complete?).and_return(true)
248
- input.should_receive(:complete_event).and_return(complete_event)
249
- end
250
- flexmock(Punchblock::Component::Record).new_instances.should_receive(:stop!)
241
+ expect_input_component_complete_event 'dtmf-5'
242
+
243
+ Punchblock::Component::Record.any_instance.should_receive(:stop!)
251
244
  subject.should_receive(:execute_component_and_await_completion).once.with(component)
252
245
  subject.record(options.merge(:async => false, :interruptible => true)) { |rec| @rec.push rec }
253
246
  end
@@ -257,7 +250,7 @@ module Adhearsion
257
250
  describe "check for the return value" do
258
251
  it "returns a Record component" do
259
252
  component
260
- flexmock(Punchblock::Component::Record).should_receive(:new).once.with(parsed_options).and_return component
253
+ Punchblock::Component::Record.should_receive(:new).once.with(parsed_options).and_return component
261
254
  expect_component_execution component
262
255
  subject.record(options.merge(:async => false)).should be == component
263
256
  component.request!
@@ -30,18 +30,18 @@ module Adhearsion
30
30
 
31
31
  describe "execution on a call" do
32
32
  before do
33
- flexmock subject, :execute_component_and_await_completion => nil
34
- flexmock call.wrapped_object, :write_and_await_response => nil
33
+ subject.stub :execute_component_and_await_completion => nil
34
+ call.wrapped_object.stub :write_and_await_response => nil
35
35
  end
36
36
 
37
37
  it "catches Hangup exceptions and logs the hangup" do
38
- subject.should_receive(:run).once.and_raise(Call::Hangup).ordered
39
- flexmock(subject.logger).should_receive(:info).once.with(/Call was hung up/).ordered
38
+ subject.should_receive(:run).once.ordered.and_raise(Call::Hangup)
39
+ subject.logger.should_receive(:info).once.with(/Call was hung up/).ordered
40
40
  subject.execute!
41
41
  end
42
42
 
43
43
  it "catches standard errors, triggering an exception event" do
44
- subject.should_receive(:run).once.and_raise(StandardError).ordered
44
+ subject.should_receive(:run).once.ordered.and_raise(StandardError)
45
45
  latch = CountDownLatch.new 1
46
46
  ex = lo = nil
47
47
  Events.exception do |e, l|
@@ -62,7 +62,7 @@ module Adhearsion
62
62
  its(:block) { should be block }
63
63
 
64
64
  it "should execute the block in the context of the controller" do
65
- flexmock subject, :value => :bar
65
+ subject.stub :value => :bar
66
66
  subject.should_receive(:foo).once.with(:bar)
67
67
  subject.run
68
68
  end
@@ -112,10 +112,10 @@ module Adhearsion
112
112
  subject { InvokeController.new call }
113
113
 
114
114
  before do
115
- flexmock subject, :execute_component_and_await_completion => nil
116
- flexmock call.wrapped_object, :write_and_await_response => nil
117
- flexmock call, :register_controller => nil
118
- flexmock(Events).should_receive(:trigger).with(:exception, Exception).never
115
+ subject.stub :execute_component_and_await_completion => nil
116
+ call.wrapped_object.stub :write_and_await_response => nil
117
+ call.stub :register_controller => nil
118
+ Events.should_receive(:trigger).with(:exception, Exception).never
119
119
  end
120
120
 
121
121
  it "should invoke another controller before returning to the current controller" do
@@ -127,13 +127,13 @@ module Adhearsion
127
127
  end
128
128
 
129
129
  it "should return the outer controller's run method return value" do
130
- flexmock(SecondController).new_instances.should_receive(:run).once.and_return(:run_result)
130
+ SecondController.any_instance.should_receive(:run).once.and_return(:run_result)
131
131
  subject.execute!
132
132
  subject.metadata[:invoke_result].should be == :run_result
133
133
  end
134
134
 
135
135
  it "should invoke the new controller with metadata" do
136
- flexmock(SecondController).new_instances.should_receive(:md_check).once.with :foo => 'bar'
136
+ SecondController.any_instance.should_receive(:md_check).once.with :foo => 'bar'
137
137
  subject.execute!
138
138
  end
139
139
 
@@ -171,11 +171,11 @@ module Adhearsion
171
171
  subject { PassController.new call }
172
172
 
173
173
  before do
174
- flexmock call.wrapped_object, :write_and_await_response => nil
175
- flexmock call, :register_controller => nil
176
- flexmock subject, :execute_component_and_await_completion => nil
177
- flexmock(SecondController).new_instances.should_receive(:md_check).once.with :foo => 'bar'
178
- flexmock(Events).should_receive(:trigger).with(:exception, Exception).never
174
+ call.wrapped_object.stub :write_and_await_response => nil
175
+ call.stub :register_controller => nil
176
+ subject.stub :execute_component_and_await_completion => nil
177
+ SecondController.any_instance.should_receive(:md_check).once.with :foo => 'bar'
178
+ Events.should_receive(:trigger).with(:exception, Exception).never
179
179
  end
180
180
 
181
181
  it "should cease execution of the current controller, and instruct the call to execute another" do
@@ -199,8 +199,8 @@ module Adhearsion
199
199
  let(:message) { Punchblock::Command::Accept.new }
200
200
 
201
201
  it "delegates to the call, blocking first until it is allowed to execute" do
202
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
203
- flexmock(subject.call).should_receive(:write_and_await_response).once.ordered.with(message)
202
+ subject.should_receive(:block_until_resumed).once.ordered
203
+ subject.call.should_receive(:write_and_await_response).once.ordered.with(message)
204
204
  subject.write_and_await_response message
205
205
  end
206
206
  end
@@ -211,8 +211,8 @@ module Adhearsion
211
211
  :unmute].each do |method_name|
212
212
  describe "##{method_name}" do
213
213
  it "delegates to the call, blocking first until it is allowed to execute" do
214
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
215
- flexmock(subject.call).should_receive(method_name).once.ordered
214
+ subject.should_receive(:block_until_resumed).once.ordered
215
+ subject.call.should_receive(method_name).once.ordered
216
216
  subject.send method_name
217
217
  end
218
218
  end
@@ -220,16 +220,16 @@ module Adhearsion
220
220
 
221
221
  describe "#hangup" do
222
222
  it "delegates to the call, blocking first until it is allowed to execute" do
223
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
224
- flexmock(subject.call).should_receive(:hangup).once.ordered
223
+ subject.should_receive(:block_until_resumed).once.ordered
224
+ subject.call.should_receive(:hangup).once.ordered
225
225
  lambda { subject.send :hangup }.should raise_error Call::Hangup
226
226
  end
227
227
  end
228
228
 
229
229
  describe "#join" do
230
230
  it "delegates to the call, blocking first until it is allowed to execute, and unblocking when an unjoined event is received" do
231
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
232
- flexmock(subject.call).should_receive(:join).once.with('call1', :foo => :bar).ordered.and_return Punchblock::Command::Join.new(:call_id => 'call1')
231
+ subject.should_receive(:block_until_resumed).once.ordered
232
+ subject.call.should_receive(:join).once.with('call1', :foo => :bar).ordered.and_return Punchblock::Command::Join.new(:call_id => 'call1')
233
233
  latch = CountDownLatch.new 1
234
234
  Thread.new do
235
235
  subject.join 'call1', :foo => :bar
@@ -244,8 +244,8 @@ module Adhearsion
244
244
 
245
245
  context "with a mixer" do
246
246
  it "delegates to the call, blocking first until it is allowed to execute, and unblocking when an unjoined event is received" do
247
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
248
- flexmock(subject.call).should_receive(:join).once.with({:mixer_name => 'foobar', :foo => :bar}, {}).ordered.and_return Punchblock::Command::Join.new(:mixer_name => 'foobar')
247
+ subject.should_receive(:block_until_resumed).once.ordered
248
+ subject.call.should_receive(:join).once.with({:mixer_name => 'foobar', :foo => :bar}, {}).ordered.and_return Punchblock::Command::Join.new(:mixer_name => 'foobar')
249
249
  latch = CountDownLatch.new 1
250
250
  Thread.new do
251
251
  subject.join :mixer_name => 'foobar', :foo => :bar
@@ -261,8 +261,8 @@ module Adhearsion
261
261
 
262
262
  context "with :async => true" do
263
263
  it "delegates to the call, blocking first until it is allowed to execute, and unblocking when the joined event is received" do
264
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
265
- flexmock(subject.call).should_receive(:join).once.with('call1', :foo => :bar).ordered.and_return Punchblock::Command::Join.new(:call_id => 'call1')
264
+ subject.should_receive(:block_until_resumed).once.ordered
265
+ subject.call.should_receive(:join).once.with('call1', :foo => :bar).ordered.and_return Punchblock::Command::Join.new(:call_id => 'call1')
266
266
  latch = CountDownLatch.new 1
267
267
  Thread.new do
268
268
  subject.join 'call1', :foo => :bar, :async => true
@@ -275,8 +275,8 @@ module Adhearsion
275
275
 
276
276
  context "with a mixer" do
277
277
  it "delegates to the call, blocking first until it is allowed to execute, and unblocking when the joined event is received" do
278
- flexmock(subject).should_receive(:block_until_resumed).once.ordered
279
- flexmock(subject.call).should_receive(:join).once.with({:mixer_name => 'foobar', :foo => :bar}, {}).ordered.and_return Punchblock::Command::Join.new(:mixer_name => 'foobar')
278
+ subject.should_receive(:block_until_resumed).once.ordered
279
+ subject.call.should_receive(:join).once.with({:mixer_name => 'foobar', :foo => :bar}, {}).ordered.and_return Punchblock::Command::Join.new(:mixer_name => 'foobar')
280
280
  latch = CountDownLatch.new 1
281
281
  Thread.new do
282
282
  subject.join :mixer_name => 'foobar', :foo => :bar, :async => true
@@ -414,8 +414,8 @@ describe ExampleCallController do
414
414
  include CallControllerTestHelpers
415
415
 
416
416
  before do
417
- flexmock subject, :execute_component_and_await_completion => nil
418
- flexmock call.wrapped_object, :write_and_await_response => nil
417
+ subject.stub :execute_component_and_await_completion => nil
418
+ call.wrapped_object.stub :write_and_await_response => nil
419
419
  end
420
420
 
421
421
  it "should execute the before_call callbacks before processing the call" do
@@ -432,8 +432,8 @@ describe ExampleCallController do
432
432
  end
433
433
 
434
434
  it "should capture errors in callbacks" do
435
- subject.should_receive(:setup_models).and_raise StandardError
436
- subject.should_receive(:clean_up_models).and_raise StandardError
435
+ subject.should_receive(:setup_models).twice.and_raise StandardError
436
+ subject.should_receive(:clean_up_models).twice.and_raise StandardError
437
437
  latch = CountDownLatch.new 4
438
438
  Adhearsion::Events.exception do |e, l|
439
439
  e.should be_a StandardError
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  module Adhearsion
12
12
  describe Call do
13
- let(:mock_client) { flexmock('Client').tap(&:should_ignore_missing) }
13
+ let(:mock_client) { mock('Client').as_null_object }
14
14
 
15
15
  let(:call_id) { rand }
16
16
  let(:headers) { nil }
@@ -26,7 +26,7 @@ module Adhearsion
26
26
  subject { Adhearsion::Call.new offer }
27
27
 
28
28
  before do
29
- flexmock(offer).should_receive(:client).and_return(mock_client)
29
+ offer.stub(:client).and_return(mock_client)
30
30
  end
31
31
 
32
32
  after do
@@ -97,16 +97,16 @@ module Adhearsion
97
97
  end
98
98
 
99
99
  it 'allows the registration of event handlers which are called when messages are delivered' do
100
- event = flexmock 'Event'
100
+ event = mock 'Event'
101
101
  event.should_receive(:foo?).and_return true
102
- response = flexmock 'Response'
102
+ response = mock 'Response'
103
103
  response.should_receive(:call).once
104
104
  subject.register_event_handler(:foo?) { response.call }
105
105
  subject << event
106
106
  end
107
107
 
108
108
  describe "event handlers" do
109
- let(:response) { flexmock 'Response' }
109
+ let(:response) { mock 'Response' }
110
110
 
111
111
  describe "for joined events" do
112
112
  context "joined to another call" do
@@ -178,7 +178,8 @@ module Adhearsion
178
178
 
179
179
  it "should trigger any on_unjoined callbacks set for the matching call" do
180
180
  response.should_receive(:call).once.with(event)
181
- call = flexmock Call.new, :id => 'foobar'
181
+ call = Call.new
182
+ call.stub :id => 'foobar'
182
183
  subject.on_unjoined(call) { |event| response.call event }
183
184
  subject << event
184
185
  end
@@ -227,7 +228,8 @@ module Adhearsion
227
228
 
228
229
  it "should not trigger any on_unjoined callbacks set for the matching call" do
229
230
  response.should_receive(:call).never
230
- call = flexmock Call.new, :id => 'foobar'
231
+ call = Call.new
232
+ call.stub :id => 'foobar'
231
233
  subject.on_unjoined(call) { |event| response.call event }
232
234
  subject << event
233
235
  end
@@ -271,7 +273,9 @@ module Adhearsion
271
273
 
272
274
  context "peer registry" do
273
275
  let(:other_call_id) { 'foobar' }
274
- let(:other_call) { flexmock Call.new, :id => other_call_id }
276
+ let(:other_call) { Call.new }
277
+
278
+ before { other_call.stub :id => other_call_id }
275
279
 
276
280
  let :joined_event do
277
281
  Punchblock::Event::Joined.new :call_id => other_call_id
@@ -329,7 +333,7 @@ module Adhearsion
329
333
  end
330
334
 
331
335
  it "should instruct the command registry to terminate" do
332
- flexmock(subject.commands).should_receive(:terminate).once
336
+ subject.commands.should_receive(:terminate).once
333
337
  subject << end_event
334
338
  end
335
339
 
@@ -401,18 +405,17 @@ module Adhearsion
401
405
  end
402
406
 
403
407
  describe "#write_command" do
404
- let(:mock_command) { flexmock('Command') }
408
+ let(:mock_command) { mock('Command') }
405
409
 
406
410
  it "should asynchronously write the command to the Punchblock connection" do
407
- mock_client = flexmock('Client')
408
- flexmock(subject.wrapped_object).should_receive(:client).once.and_return mock_client
411
+ subject.wrapped_object.should_receive(:client).once.and_return mock_client
409
412
  mock_client.should_receive(:execute_command).once.with(mock_command, :call_id => subject.id, :async => true).and_return true
410
413
  subject.write_command mock_command
411
414
  end
412
415
 
413
416
  describe "with a hungup call" do
414
417
  before do
415
- flexmock(subject.wrapped_object).should_receive(:active?).and_return(false)
418
+ subject.wrapped_object.should_receive(:active?).and_return(false)
416
419
  end
417
420
 
418
421
  it "should raise a Hangup exception" do
@@ -434,12 +437,12 @@ module Adhearsion
434
437
  let(:response) { :foo }
435
438
 
436
439
  before do
437
- flexmock(message).should_receive(:execute!).and_return true
440
+ message.should_receive(:execute!).and_return true
438
441
  message.response = response
439
442
  end
440
443
 
441
444
  it "writes a command to the call" do
442
- flexmock(subject.wrapped_object).should_receive(:write_command).once.with(message)
445
+ subject.wrapped_object.should_receive(:write_command).once.with(message)
443
446
  subject.write_and_await_response message
444
447
  end
445
448
 
@@ -471,7 +474,7 @@ module Adhearsion
471
474
  let(:response) { new_exception.new }
472
475
 
473
476
  it "raises the error" do
474
- flexmock(Events).should_receive(:trigger).never
477
+ Events.should_receive(:trigger).never
475
478
  lambda { subject.write_and_await_response message }.should raise_error new_exception
476
479
  end
477
480
 
@@ -479,7 +482,7 @@ module Adhearsion
479
482
  let(:response) { new_exception.new.setup :item_not_found }
480
483
 
481
484
  it "should raise a Hangup exception" do
482
- flexmock(Events).should_receive(:trigger).never
485
+ Events.should_receive(:trigger).never
483
486
  lambda { subject.write_and_await_response message }.should raise_error Call::Hangup
484
487
  end
485
488
  end
@@ -499,10 +502,14 @@ module Adhearsion
499
502
  end
500
503
 
501
504
  describe "basic control commands" do
502
- include FlexMock::ArgumentTypes
503
-
504
- def expect_message_waiting_for_response(message)
505
- flexmock(subject.wrapped_object).should_receive(:write_and_await_response).once.with(message).and_return(message)
505
+ def expect_message_waiting_for_response(message = nil, fail = false, &block)
506
+ expectation = subject.wrapped_object.should_receive(:write_and_await_response, &block).once
507
+ expectation = expectation.with message if message
508
+ if fail
509
+ expectation.and_raise fail
510
+ else
511
+ expectation.and_return message
512
+ end
506
513
  end
507
514
 
508
515
  describe '#accept' do
@@ -564,7 +571,9 @@ module Adhearsion
564
571
 
565
572
  describe "with no headers" do
566
573
  it 'should send a Reject message' do
567
- expect_message_waiting_for_response on { |c| c.is_a?(Punchblock::Command::Reject) && c.headers_hash == {} }
574
+ expect_message_waiting_for_response do |c|
575
+ c.is_a?(Punchblock::Command::Reject) && c.headers_hash == {}
576
+ end
568
577
  subject.reject
569
578
  end
570
579
  end
@@ -572,14 +581,16 @@ module Adhearsion
572
581
  describe "with headers set" do
573
582
  it 'should send a Hangup message with the correct headers' do
574
583
  headers = {:foo => 'bar'}
575
- expect_message_waiting_for_response on { |c| c.is_a?(Punchblock::Command::Reject) && c.headers_hash == headers }
584
+ expect_message_waiting_for_response do |c|
585
+ c.is_a?(Punchblock::Command::Reject) && c.headers_hash == headers
586
+ end
576
587
  subject.reject nil, headers
577
588
  end
578
589
  end
579
590
 
580
591
  it "should immediately fire the :call_rejected event giving the call and the reason" do
581
- expect_message_waiting_for_response Punchblock::Command::Reject
582
- flexmock(Adhearsion::Events).should_receive(:trigger_immediately).once.with(:call_rejected, :call => subject, :reason => :decline)
592
+ expect_message_waiting_for_response kind_of(Punchblock::Command::Reject)
593
+ Adhearsion::Events.should_receive(:trigger_immediately).once.with(:call_rejected, :call => subject, :reason => :decline)
583
594
  subject.reject :decline
584
595
  end
585
596
  end
@@ -587,11 +598,11 @@ module Adhearsion
587
598
  describe "#hangup" do
588
599
  describe "if the call is not active" do
589
600
  before do
590
- flexmock(subject.wrapped_object).should_receive(:active?).and_return false
601
+ subject.wrapped_object.should_receive(:active?).and_return false
591
602
  end
592
603
 
593
604
  it "should do nothing and return false" do
594
- flexmock(subject).should_receive(:write_and_await_response).never
605
+ subject.should_receive(:write_and_await_response).never
595
606
  subject.hangup.should be false
596
607
  end
597
608
  end
@@ -629,7 +640,9 @@ module Adhearsion
629
640
 
630
641
  context "with a call" do
631
642
  let(:call_id) { rand.to_s }
632
- let(:target) { flexmock Call.new, :id => call_id }
643
+ let(:target) { described_class.new }
644
+
645
+ before { target.stub id: call_id }
633
646
 
634
647
  it "should send a join command joining to the provided call ID" do
635
648
  expect_join_with_options :call_id => call_id
@@ -714,7 +727,9 @@ module Adhearsion
714
727
 
715
728
  context "with a call" do
716
729
  let(:call_id) { rand.to_s }
717
- let(:target) { flexmock Call.new, :id => call_id }
730
+ let(:target) { described_class.new }
731
+
732
+ before { target.stub id: call_id }
718
733
 
719
734
  it "should send an unjoin command unjoining from the provided call ID" do
720
735
  expect_unjoin_with_options :call_id => call_id
@@ -778,10 +793,10 @@ module Adhearsion
778
793
 
779
794
  describe "#execute_controller" do
780
795
  let(:latch) { CountDownLatch.new 1 }
781
- let(:mock_controller) { flexmock CallController.new(subject) }
796
+ let(:mock_controller) { CallController.new(subject) }
782
797
 
783
798
  before do
784
- flexmock subject.wrapped_object, :write_and_await_response => true
799
+ subject.wrapped_object.stub :write_and_await_response => true
785
800
  end
786
801
 
787
802
  it "should call #bg_exec on the controller instance" do
@@ -792,7 +807,7 @@ module Adhearsion
792
807
 
793
808
  it "should use the passed block as a controller if none is specified" do
794
809
  mock_controller.should_receive(:exec).once
795
- flexmock(CallController).should_receive(:new).once.and_return mock_controller
810
+ CallController.should_receive(:new).once.and_return mock_controller
796
811
  subject.execute_controller nil, lambda { |call| latch.countdown! } do
797
812
  foo
798
813
  end
@@ -816,7 +831,6 @@ module Adhearsion
816
831
  end
817
832
 
818
833
  it "should execute a callback after the controller executes" do
819
- flexmock(CallController).should_receive(:exec)
820
834
  foo = nil
821
835
  subject.execute_controller mock_controller, lambda { |call| foo = call; latch.countdown! }
822
836
  latch.wait(3).should be_true
@@ -832,8 +846,8 @@ module Adhearsion
832
846
  end
833
847
 
834
848
  context "with two controllers registered" do
835
- let(:controller1) { flexmock 'CallController1' }
836
- let(:controller2) { flexmock 'CallController2' }
849
+ let(:controller1) { mock 'CallController1' }
850
+ let(:controller2) { mock 'CallController2' }
837
851
 
838
852
  before { subject.controllers << controller1 << controller2 }
839
853