adhearsion 2.5.4 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/CHANGELOG.md +15 -0
  4. data/README.markdown +2 -1
  5. data/Rakefile +1 -6
  6. data/adhearsion.gemspec +4 -3
  7. data/features/cli_daemon.feature +2 -4
  8. data/features/cli_restart.feature +14 -5
  9. data/features/cli_start.feature +0 -2
  10. data/features/cli_stop.feature +15 -6
  11. data/lib/adhearsion.rb +21 -23
  12. data/lib/adhearsion/call.rb +49 -5
  13. data/lib/adhearsion/call_controller.rb +29 -11
  14. data/lib/adhearsion/call_controller/dial.rb +21 -9
  15. data/lib/adhearsion/call_controller/menu_dsl.rb +12 -12
  16. data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +1 -1
  17. data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +1 -0
  18. data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +1 -1
  19. data/lib/adhearsion/call_controller/output.rb +36 -7
  20. data/lib/adhearsion/call_controller/output/abstract_player.rb +4 -0
  21. data/lib/adhearsion/call_controller/record.rb +1 -0
  22. data/lib/adhearsion/cli_commands/ahn_command.rb +7 -4
  23. data/lib/adhearsion/cli_commands/plugin_command.rb +2 -0
  24. data/lib/adhearsion/generators.rb +2 -4
  25. data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +20 -20
  26. data/lib/adhearsion/initializer.rb +2 -2
  27. data/lib/adhearsion/plugin.rb +6 -6
  28. data/lib/adhearsion/punchblock_plugin.rb +3 -4
  29. data/lib/adhearsion/punchblock_plugin/initializer.rb +2 -1
  30. data/lib/adhearsion/router.rb +7 -7
  31. data/lib/adhearsion/router/route.rb +10 -4
  32. data/lib/adhearsion/rspec.rb +2 -0
  33. data/lib/adhearsion/version.rb +1 -1
  34. data/spec/adhearsion/call_controller/dial_spec.rb +589 -557
  35. data/spec/adhearsion/call_controller/input_spec.rb +91 -91
  36. data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +29 -29
  37. data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +6 -6
  38. data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +19 -19
  39. data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +6 -6
  40. data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +1 -1
  41. data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +21 -17
  42. data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +96 -83
  43. data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +5 -5
  44. data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +9 -9
  45. data/spec/adhearsion/call_controller/output/async_player_spec.rb +14 -4
  46. data/spec/adhearsion/call_controller/output/formatter_spec.rb +14 -14
  47. data/spec/adhearsion/call_controller/output/player_spec.rb +15 -5
  48. data/spec/adhearsion/call_controller/output_spec.rb +126 -78
  49. data/spec/adhearsion/call_controller/record_spec.rb +38 -26
  50. data/spec/adhearsion/call_controller/utility_spec.rb +11 -11
  51. data/spec/adhearsion/call_controller_spec.rb +176 -136
  52. data/spec/adhearsion/call_spec.rb +443 -218
  53. data/spec/adhearsion/calls_spec.rb +33 -33
  54. data/spec/adhearsion/configuration_spec.rb +61 -61
  55. data/spec/adhearsion/console_spec.rb +29 -29
  56. data/spec/adhearsion/events_spec.rb +14 -14
  57. data/spec/adhearsion/generators_spec.rb +1 -1
  58. data/spec/adhearsion/initializer_spec.rb +42 -42
  59. data/spec/adhearsion/logging_spec.rb +33 -33
  60. data/spec/adhearsion/outbound_call_spec.rb +69 -55
  61. data/spec/adhearsion/plugin_spec.rb +53 -44
  62. data/spec/adhearsion/process_spec.rb +21 -21
  63. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +68 -52
  64. data/spec/adhearsion/punchblock_plugin_spec.rb +6 -6
  65. data/spec/adhearsion/router/evented_route_spec.rb +2 -2
  66. data/spec/adhearsion/router/openended_route_spec.rb +9 -9
  67. data/spec/adhearsion/router/route_spec.rb +61 -31
  68. data/spec/adhearsion/router/unaccepting_route_spec.rb +13 -13
  69. data/spec/adhearsion/router_spec.rb +47 -33
  70. data/spec/adhearsion/statistics/dump_spec.rb +6 -6
  71. data/spec/adhearsion/statistics_spec.rb +9 -9
  72. data/spec/adhearsion_spec.rb +23 -20
  73. data/spec/spec_helper.rb +3 -6
  74. data/spec/support/call_controller_test_helpers.rb +7 -7
  75. data/spec/support/initializer_stubs.rb +1 -1
  76. data/spec/support/punchblock_mocks.rb +1 -1
  77. metadata +22 -10
  78. data/features/support/utils.rb +0 -9
@@ -1,11 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'adhearsion/plugin'
4
+ require 'adhearsion/punchblock_plugin/initializer'
5
+
3
6
  module Adhearsion
4
7
  class PunchblockPlugin < Plugin
5
- extend ActiveSupport::Autoload
6
-
7
- autoload :Initializer
8
-
9
8
  config :punchblock do
10
9
  enabled true , :transform => Proc.new { |v| v == 'true' }, :desc => "Enable or disable Punchblock connectivity to a Voice server"
11
10
  platform :xmpp , :transform => Proc.new { |v| v.to_sym }, :desc => <<-__
@@ -1,9 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'blather'
4
+ require 'active_support/core_ext/class/attribute_accessors'
4
5
 
5
6
  module Adhearsion
6
- class PunchblockPlugin
7
+ class PunchblockPlugin < Plugin
7
8
  class Initializer
8
9
  cattr_accessor :config, :client, :dispatcher, :attempts
9
10
 
@@ -1,14 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
+ %w(
4
+ evented_route
5
+ openended_route
6
+ route
7
+ unaccepting_route
8
+ ).each { |r| require "adhearsion/router/#{r}" }
9
+
3
10
  module Adhearsion
4
11
  class Router
5
- extend ActiveSupport::Autoload
6
-
7
- autoload :EventedRoute
8
- autoload :OpenendedRoute
9
- autoload :Route
10
- autoload :UnacceptingRoute
11
-
12
12
  NoMatchError = Class.new Adhearsion::Error
13
13
 
14
14
  attr_reader :routes
@@ -28,6 +28,8 @@ module Adhearsion
28
28
  def dispatch(call, callback = nil)
29
29
  Adhearsion::Events.trigger_immediately :call_routed, call: call, route: self
30
30
 
31
+ call_id = call.id # Grab this to use later incase the actor is dead
32
+
31
33
  controller = if target.respond_to?(:call)
32
34
  CallController.new call, controller_metadata, &target
33
35
  else
@@ -38,11 +40,15 @@ module Adhearsion
38
40
 
39
41
  call.execute_controller controller, lambda { |call_actor|
40
42
  begin
41
- if call_actor.auto_hangup
42
- logger.info "Call #{call.id} routing completed. Hanging up now."
43
- call_actor.hangup
43
+ if call_actor.alive? && call_actor.active?
44
+ if call_actor.auto_hangup
45
+ logger.info "Call #{call_id} routing completed. Hanging up now."
46
+ call_actor.hangup
47
+ else
48
+ logger.info "Call #{call_id} routing completed. Keeping the call alive at controller/router request."
49
+ end
44
50
  else
45
- logger.info "Call #{call.id} routing completed. Keeping the call alive at controller/router request."
51
+ logger.info "Call #{call_id} routing completed. Call was already hung up."
46
52
  end
47
53
  rescue Call::Hangup, Call::ExpiredError
48
54
  end
@@ -8,3 +8,5 @@ initializer.load_lib_folder
8
8
  initializer.load_config_file
9
9
  initializer.load_events_file
10
10
  initializer.load_routes_file
11
+ initializer.start_logging
12
+ Adhearsion::Logging.logging_level = :error
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Adhearsion
4
- VERSION = '2.5.4'
4
+ VERSION = '2.6.0'
5
5
  end
@@ -22,41 +22,41 @@ module Adhearsion
22
22
  let(:join_options) { options[:join_options] || {} }
23
23
 
24
24
  before do
25
- other_mock_call.wrapped_object.stub id: other_call_id, write_command: true
26
- second_other_mock_call.wrapped_object.stub id: second_other_call_id, write_command: true
25
+ allow(other_mock_call.wrapped_object).to receive_messages id: other_call_id, write_command: true
26
+ allow(second_other_mock_call.wrapped_object).to receive_messages id: second_other_call_id, write_command: true
27
27
  end
28
28
 
29
29
  def mock_end(reason = :hangup_command)
30
- Punchblock::Event::End.new.tap { |event| event.stub reason: reason }
30
+ Punchblock::Event::End.new.tap { |event| allow(event).to receive_messages reason: reason }
31
31
  end
32
32
 
33
33
  describe "#dial" do
34
34
  it "should dial the call to the correct endpoint and return a dial status object" do
35
- OutboundCall.should_receive(:new).and_return other_mock_call
36
- other_mock_call.should_receive(:dial).with(to, :from => 'foo').once
35
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
36
+ expect(other_mock_call).to receive(:dial).with(to, :from => 'foo').once
37
37
  dial_thread = Thread.new do
38
38
  status = subject.dial(to, :from => 'foo')
39
39
 
40
- status.should be_a Dial::DialStatus
40
+ expect(status).to be_a Dial::DialStatus
41
41
  joined_status = status.joins[status.calls.first]
42
- joined_status.duration.should == 0.0
43
- joined_status.result.should == :no_answer
42
+ expect(joined_status.duration).to eq(0.0)
43
+ expect(joined_status.result).to eq(:no_answer)
44
44
  end
45
45
  sleep 0.1
46
46
  other_mock_call << mock_end
47
- dial_thread.join.should be_true
47
+ expect(dial_thread.join).to be_truthy
48
48
  end
49
49
 
50
50
  it "should default the caller ID to that of the original call" do
51
- call.stub :from => 'sip:foo@bar.com'
52
- OutboundCall.should_receive(:new).and_return other_mock_call
53
- other_mock_call.should_receive(:dial).with(to, :from => 'sip:foo@bar.com').once
51
+ allow(call).to receive_messages :from => 'sip:foo@bar.com'
52
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
53
+ expect(other_mock_call).to receive(:dial).with(to, :from => 'sip:foo@bar.com').once
54
54
  dial_thread = Thread.new do
55
55
  subject.dial to
56
56
  end
57
57
  sleep 0.1
58
58
  other_mock_call << mock_end
59
- dial_thread.join.should be_true
59
+ expect(dial_thread.join).to be_truthy
60
60
  end
61
61
 
62
62
  let(:options) { { :foo => :bar } }
@@ -71,61 +71,61 @@ module Adhearsion
71
71
 
72
72
  describe "without a block" do
73
73
  before do
74
- other_mock_call.should_receive(:dial).once.with(to, options)
75
- OutboundCall.should_receive(:new).and_return other_mock_call
74
+ expect(other_mock_call).to receive(:dial).once.with(to, options)
75
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
76
76
  end
77
77
 
78
78
  it "blocks the original controller until the new call ends" do
79
79
  dial_in_thread
80
80
 
81
- latch.wait(2).should be_false
81
+ expect(latch.wait(2)).to be_falsey
82
82
 
83
83
  other_mock_call << mock_end
84
84
 
85
- latch.wait(2).should be_true
85
+ expect(latch.wait(2)).to be_truthy
86
86
  end
87
87
 
88
88
  it "unblocks the original controller if the original call ends" do
89
- other_mock_call.should_receive(:hangup).once
89
+ expect(other_mock_call).to receive(:hangup).once
90
90
  dial_in_thread
91
91
 
92
- latch.wait(2).should be_false
92
+ expect(latch.wait(2)).to be_falsey
93
93
 
94
94
  call << mock_end
95
95
 
96
- latch.wait(2).should be_true
96
+ expect(latch.wait(2)).to be_truthy
97
97
  end
98
98
 
99
99
  it "joins the new call to the existing one on answer" do
100
- call.should_receive(:answer).once
101
- other_mock_call.should_receive(:join).once.with(call, {})
100
+ expect(call).to receive(:answer).once
101
+ expect(other_mock_call).to receive(:join).once.with(call, {})
102
102
 
103
103
  dial_in_thread
104
104
 
105
- latch.wait(2).should be_false
105
+ expect(latch.wait(2)).to be_falsey
106
106
 
107
107
  other_mock_call << mock_answered
108
108
  other_mock_call << mock_end
109
109
 
110
- latch.wait(2).should be_true
110
+ expect(latch.wait(2)).to be_truthy
111
111
  end
112
112
 
113
113
  context "with a join target specified" do
114
114
  let(:options) { { join_target: {mixer_name: 'foobar'} } }
115
115
 
116
116
  it "joins the calls to the specified target on answer" do
117
- call.should_receive(:answer).once
118
- call.should_receive(:join).once.with({mixer_name: 'foobar'}, {})
119
- other_mock_call.should_receive(:join).once.with({mixer_name: 'foobar'}, {})
117
+ expect(call).to receive(:answer).once
118
+ expect(call).to receive(:join).once.with({mixer_name: 'foobar'}, {})
119
+ expect(other_mock_call).to receive(:join).once.with({mixer_name: 'foobar'}, {})
120
120
 
121
121
  dial_in_thread
122
122
 
123
- latch.wait(2).should be_false
123
+ expect(latch.wait(2)).to be_falsey
124
124
 
125
125
  other_mock_call << mock_answered
126
126
  other_mock_call << mock_end
127
127
 
128
- latch.wait(2).should be_true
128
+ expect(latch.wait(2)).to be_truthy
129
129
  end
130
130
  end
131
131
 
@@ -134,18 +134,18 @@ module Adhearsion
134
134
  let(:options) { { pre_join: ->(call) { foo.bar call } } }
135
135
 
136
136
  it "executes the callback prior to joining" do
137
- foo.should_receive(:bar).once.with(other_mock_call).ordered
138
- call.should_receive(:answer).once.ordered
139
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
137
+ expect(foo).to receive(:bar).once.with(other_mock_call).ordered
138
+ expect(call).to receive(:answer).once.ordered
139
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
140
140
 
141
141
  dial_in_thread
142
142
 
143
- latch.wait(2).should be_false
143
+ expect(latch.wait(2)).to be_falsey
144
144
 
145
145
  other_mock_call << mock_answered
146
146
  other_mock_call << mock_end
147
147
 
148
- latch.wait(2).should be_true
148
+ expect(latch.wait(2)).to be_truthy
149
149
  end
150
150
  end
151
151
 
@@ -159,19 +159,19 @@ module Adhearsion
159
159
  end
160
160
 
161
161
  it "plays the ringback asynchronously, terminating prior to joining" do
162
- subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
163
- component.should_receive(:stop!).twice
164
- call.should_receive(:answer).once.ordered
165
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
162
+ expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
163
+ expect(component).to receive(:stop!).twice
164
+ expect(call).to receive(:answer).once.ordered
165
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
166
166
 
167
167
  dial_in_thread
168
168
 
169
- latch.wait(2).should be_false
169
+ expect(latch.wait(2)).to be_falsey
170
170
 
171
171
  other_mock_call << mock_answered
172
172
  other_mock_call << mock_end
173
173
 
174
- latch.wait(2).should be_true
174
+ expect(latch.wait(2)).to be_truthy
175
175
  end
176
176
 
177
177
  context "as a callback" do
@@ -179,51 +179,51 @@ module Adhearsion
179
179
  let(:options) { { ringback: -> { foo.bar; component } } }
180
180
 
181
181
  it "calls the callback to start, and uses the return value of the callback to stop the ringback" do
182
- foo.should_receive(:bar).once.ordered
183
- component.should_receive(:stop!).twice
184
- call.should_receive(:answer).once.ordered
185
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
182
+ expect(foo).to receive(:bar).once.ordered
183
+ expect(component).to receive(:stop!).twice
184
+ expect(call).to receive(:answer).once.ordered
185
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
186
186
 
187
187
  dial_in_thread
188
188
 
189
- latch.wait(2).should be_false
189
+ expect(latch.wait(2)).to be_falsey
190
190
 
191
191
  other_mock_call << mock_answered
192
192
  other_mock_call << mock_end
193
193
 
194
- latch.wait(2).should be_true
194
+ expect(latch.wait(2)).to be_truthy
195
195
  end
196
196
  end
197
197
 
198
198
  context "when the call is rejected" do
199
199
  it "terminates the ringback before returning" do
200
- subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
201
- component.should_receive(:stop!).once
200
+ expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
201
+ expect(component).to receive(:stop!).once
202
202
 
203
203
  t = dial_in_thread
204
204
 
205
- latch.wait(2).should be_false
205
+ expect(latch.wait(2)).to be_falsey
206
206
 
207
207
  other_mock_call << mock_end(:reject)
208
208
 
209
- latch.wait(2).should be_true
209
+ expect(latch.wait(2)).to be_truthy
210
210
  end
211
211
  end
212
212
  end
213
213
 
214
214
  it "hangs up the new call when the root call ends" do
215
- call.should_receive(:answer).once
216
- other_mock_call.should_receive(:join).once.with(call, {})
217
- other_mock_call.should_receive(:hangup).once
215
+ expect(call).to receive(:answer).once
216
+ expect(other_mock_call).to receive(:join).once.with(call, {})
217
+ expect(other_mock_call).to receive(:hangup).once
218
218
 
219
219
  dial_in_thread
220
220
 
221
- latch.wait(2).should be_false
221
+ expect(latch.wait(2)).to be_falsey
222
222
 
223
223
  other_mock_call << mock_answered
224
224
  call << mock_end
225
225
 
226
- latch.wait(2).should be_true
226
+ expect(latch.wait(2)).to be_truthy
227
227
  end
228
228
 
229
229
  context "when the call is rejected" do
@@ -234,11 +234,11 @@ module Adhearsion
234
234
 
235
235
  other_mock_call << mock_end(:reject)
236
236
 
237
- latch.wait(2).should be_true
237
+ expect(latch.wait(2)).to be_truthy
238
238
 
239
239
  t.join
240
240
  status = t.value
241
- status.result.should be == :no_answer
241
+ expect(status.result).to eq(:no_answer)
242
242
  end
243
243
  end
244
244
 
@@ -250,22 +250,22 @@ module Adhearsion
250
250
 
251
251
  other_mock_call << mock_end(:error)
252
252
 
253
- latch.wait(2).should be_true
253
+ expect(latch.wait(2)).to be_truthy
254
254
 
255
255
  t.join
256
256
  status = t.value
257
- status.result.should be == :error
257
+ expect(status.result).to eq(:error)
258
258
 
259
259
  joined_status = status.joins[status.calls.first]
260
- joined_status.duration.should == 0.0
261
- joined_status.result.should == :error
260
+ expect(joined_status.duration).to eq(0.0)
261
+ expect(joined_status.result).to eq(:error)
262
262
  end
263
263
  end
264
264
 
265
265
  context "when the call is answered and joined" do
266
266
  it "has an overall dial status of :answer" do
267
- call.should_receive(:answer).once
268
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
267
+ expect(call).to receive(:answer).once
268
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
269
269
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
270
270
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
271
271
  end
@@ -277,23 +277,23 @@ module Adhearsion
277
277
  other_mock_call << mock_answered
278
278
  other_mock_call << mock_end
279
279
 
280
- latch.wait(2).should be_true
280
+ expect(latch.wait(2)).to be_truthy
281
281
 
282
282
  t.join
283
283
  status = t.value
284
- status.result.should be == :answer
284
+ expect(status.result).to eq(:answer)
285
285
 
286
286
  joined_status = status.joins[status.calls.first]
287
- joined_status.result.should == :joined
287
+ expect(joined_status.result).to eq(:joined)
288
288
  end
289
289
 
290
290
  it "records the duration of the join" do
291
- call.should_receive(:answer).once
292
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
291
+ expect(call).to receive(:answer).once
292
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
293
293
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
294
294
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
295
295
  end
296
- other_mock_call.stub hangup: true
296
+ allow(other_mock_call).to receive_messages hangup: true
297
297
 
298
298
  t = dial_in_thread
299
299
 
@@ -309,22 +309,22 @@ module Adhearsion
309
309
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
310
310
  other_mock_call << mock_end
311
311
 
312
- latch.wait(2).should be_true
312
+ expect(latch.wait(2)).to be_truthy
313
313
 
314
314
  t.join
315
315
  status = t.value
316
- status.result.should be == :answer
316
+ expect(status.result).to eq(:answer)
317
317
  joined_status = status.joins[status.calls.first]
318
- joined_status.duration.should == 37.0
318
+ expect(joined_status.duration).to eq(37.0)
319
319
  end
320
320
 
321
321
  context "when join options are specified" do
322
322
  let(:options) { { join_options: {media: :direct} } }
323
323
 
324
324
  it "joins the calls with those options" do
325
- call.should_receive(:answer).once
326
- other_mock_call.should_receive(:join).once.with(call, media: :direct)
327
- other_mock_call.stub hangup: true
325
+ expect(call).to receive(:answer).once
326
+ expect(other_mock_call).to receive(:join).once.with(call, media: :direct)
327
+ allow(other_mock_call).to receive_messages hangup: true
328
328
 
329
329
  t = dial_in_thread
330
330
 
@@ -335,7 +335,7 @@ module Adhearsion
335
335
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
336
336
  other_mock_call << mock_end
337
337
 
338
- latch.wait(2).should be_true
338
+ expect(latch.wait(2)).to be_truthy
339
339
 
340
340
  t.join
341
341
  end
@@ -346,19 +346,19 @@ module Adhearsion
346
346
  let(:join_target) { call }
347
347
 
348
348
  before do
349
- call.should_receive(:answer).once
350
- other_mock_call.should_receive(:join).once.with(join_target, join_options).and_return do
349
+ expect(call).to receive(:answer).once
350
+ expect(other_mock_call).to receive(:join).once.with(join_target, join_options) do
351
351
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
352
352
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
353
353
  end
354
- other_mock_call.stub(:unjoin).and_return do
354
+ allow(other_mock_call).to receive(:unjoin) do
355
355
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
356
356
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
357
357
  end
358
358
  end
359
359
 
360
360
  it "should unjoin the calls" do
361
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
361
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
362
362
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
363
363
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
364
364
  end
@@ -378,10 +378,10 @@ module Adhearsion
378
378
  dial.split
379
379
  other_mock_call << mock_end
380
380
 
381
- latch.wait(2).should be_true
381
+ expect(latch.wait(2)).to be_truthy
382
382
 
383
383
  waiter_thread.join
384
- dial.status.result.should be == :answer
384
+ expect(dial.status.result).to eq(:answer)
385
385
  end
386
386
 
387
387
  it "should not unblock immediately" do
@@ -399,14 +399,14 @@ module Adhearsion
399
399
 
400
400
  dial.split
401
401
 
402
- latch.wait(2).should be_false
402
+ expect(latch.wait(2)).to be_falsey
403
403
 
404
404
  other_mock_call << mock_end
405
405
 
406
- latch.wait(2).should be_true
406
+ expect(latch.wait(2)).to be_truthy
407
407
 
408
408
  waiter_thread.join
409
- dial.status.result.should be == :answer
409
+ expect(dial.status.result).to eq(:answer)
410
410
  end
411
411
 
412
412
  it "should set end time" do
@@ -433,13 +433,13 @@ module Adhearsion
433
433
  Timecop.freeze base_time
434
434
  other_mock_call << mock_end
435
435
 
436
- latch.wait(2).should be_true
436
+ expect(latch.wait(2)).to be_truthy
437
437
 
438
438
  waiter_thread.join
439
439
  status = dial.status
440
- status.result.should be == :answer
440
+ expect(status.result).to eq(:answer)
441
441
  joined_status = status.joins[status.calls.first]
442
- joined_status.duration.should == 37.0
442
+ expect(joined_status.duration).to eq(37.0)
443
443
  end
444
444
 
445
445
  context "with new controllers specified" do
@@ -474,32 +474,32 @@ module Adhearsion
474
474
 
475
475
  other_mock_call << mock_answered
476
476
 
477
- should_receive(:callback).once.with(call)
478
- should_receive(:callback).once.with(other_mock_call)
477
+ expect(self).to receive(:callback).once.with(call)
478
+ expect(self).to receive(:callback).once.with(other_mock_call)
479
479
 
480
480
  dial.split main: main_split_controller, others: others_split_controller, main_callback: ->(call) { self.callback(call) }, others_callback: ->(call) { self.callback(call) }
481
481
 
482
- latch.wait(2).should be_false
483
- split_latch.wait(2).should be_true
482
+ expect(latch.wait(2)).to be_falsey
483
+ expect(split_latch.wait(2)).to be_truthy
484
484
 
485
- call['hit_split_controller'].should == main_split_controller
486
- call['split_controller_metadata']['current_dial'].should be dial
485
+ expect(call['hit_split_controller']).to eq(main_split_controller)
486
+ expect(call['split_controller_metadata']['current_dial']).to be dial
487
487
 
488
- other_mock_call['hit_split_controller'].should == others_split_controller
489
- other_mock_call['split_controller_metadata']['current_dial'].should be dial
488
+ expect(other_mock_call['hit_split_controller']).to eq(others_split_controller)
489
+ expect(other_mock_call['split_controller_metadata']['current_dial']).to be dial
490
490
 
491
491
  other_mock_call << mock_end
492
492
 
493
- latch.wait(2).should be_true
493
+ expect(latch.wait(2)).to be_truthy
494
494
 
495
495
  waiter_thread.join
496
- dial.status.result.should be == :answer
496
+ expect(dial.status.result).to eq(:answer)
497
497
  end
498
498
  end
499
499
 
500
500
  context "when rejoining" do
501
501
  it "should rejoin the calls" do
502
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
502
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
503
503
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
504
504
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
505
505
  end
@@ -518,22 +518,22 @@ module Adhearsion
518
518
 
519
519
  dial.split
520
520
 
521
- other_mock_call.should_receive(:join).once.ordered.with(call, {})
521
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, {})
522
522
  dial.rejoin
523
523
 
524
524
  other_mock_call << mock_end
525
525
 
526
- latch.wait(2).should be_true
526
+ expect(latch.wait(2)).to be_truthy
527
527
 
528
528
  waiter_thread.join
529
- dial.status.result.should be == :answer
529
+ expect(dial.status.result).to eq(:answer)
530
530
  end
531
531
 
532
532
  context "when join options were set originally" do
533
533
  let(:options) { { join_options: {media: :direct} } }
534
534
 
535
535
  it "should rejoin with the same parameters" do
536
- other_mock_call.stub(:unjoin)
536
+ allow(other_mock_call).to receive(:unjoin)
537
537
 
538
538
  dial = Dial::Dial.new to, options, call
539
539
  dial.run subject
@@ -542,14 +542,14 @@ module Adhearsion
542
542
 
543
543
  dial.split
544
544
 
545
- other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct)
545
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct)
546
546
  dial.rejoin
547
547
  end
548
548
  end
549
549
 
550
550
  context "when join options are passed to rejoin" do
551
551
  it "should rejoin with those parameters" do
552
- other_mock_call.stub(:unjoin)
552
+ allow(other_mock_call).to receive(:unjoin)
553
553
 
554
554
  dial = Dial::Dial.new to, options, call
555
555
  dial.run subject
@@ -558,7 +558,7 @@ module Adhearsion
558
558
 
559
559
  dial.split
560
560
 
561
- other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct)
561
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct)
562
562
  dial.rejoin nil, media: :direct
563
563
  end
564
564
  end
@@ -568,9 +568,9 @@ module Adhearsion
568
568
  let(:options) { { join_target: join_target } }
569
569
 
570
570
  it "joins the calls to the specified target on answer" do
571
- call.should_receive(:join).once.with(join_target, {})
572
- other_mock_call.should_receive(:unjoin).once.ordered.with(join_target)
573
- call.should_receive(:unjoin).once.ordered.with(join_target).and_return do
571
+ expect(call).to receive(:join).once.with(join_target, {})
572
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(join_target)
573
+ expect(call).to receive(:unjoin).once.ordered.with(join_target) do
574
574
  call << Punchblock::Event::Unjoined.new(join_target)
575
575
  other_mock_call << Punchblock::Event::Unjoined.new(join_target)
576
576
  end
@@ -589,16 +589,16 @@ module Adhearsion
589
589
 
590
590
  dial.split
591
591
 
592
- call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
593
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
592
+ expect(call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
593
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
594
594
  dial.rejoin
595
595
 
596
596
  other_mock_call << mock_end
597
597
 
598
- latch.wait(2).should be_true
598
+ expect(latch.wait(2)).to be_truthy
599
599
 
600
600
  waiter_thread.join
601
- dial.status.result.should be == :answer
601
+ expect(dial.status.result).to eq(:answer)
602
602
  end
603
603
  end
604
604
 
@@ -606,7 +606,7 @@ module Adhearsion
606
606
  let(:mixer) { SecureRandom.uuid }
607
607
 
608
608
  it "should join all calls to the mixer" do
609
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
609
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
610
610
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
611
611
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
612
612
  end
@@ -625,20 +625,20 @@ module Adhearsion
625
625
 
626
626
  dial.split
627
627
 
628
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
629
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
628
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
629
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
630
630
  dial.rejoin mixer_name: mixer
631
631
 
632
632
  other_mock_call << mock_end
633
633
 
634
- latch.wait(2).should be_true
634
+ expect(latch.wait(2)).to be_truthy
635
635
 
636
636
  waiter_thread.join
637
- dial.status.result.should be == :answer
637
+ expect(dial.status.result).to eq(:answer)
638
638
  end
639
639
 
640
640
  it "#split should then unjoin calls from the mixer" do
641
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
641
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
642
642
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
643
643
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
644
644
  end
@@ -657,24 +657,24 @@ module Adhearsion
657
657
 
658
658
  dial.split
659
659
 
660
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
661
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
660
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
661
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
662
662
  dial.rejoin mixer_name: mixer
663
663
 
664
- other_mock_call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do
664
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do
665
665
  other_mock_call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
666
666
  end
667
- call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do
667
+ expect(call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do
668
668
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
669
669
  end
670
670
  dial.split
671
671
 
672
672
  other_mock_call << mock_end
673
673
 
674
- latch.wait(2).should be_true
674
+ expect(latch.wait(10)).to be_truthy
675
675
 
676
676
  waiter_thread.join
677
- dial.status.result.should be == :answer
677
+ expect(dial.status.result).to eq(:answer)
678
678
  end
679
679
  end
680
680
  end
@@ -688,13 +688,13 @@ module Adhearsion
688
688
  let(:other_dial) { Dial::Dial.new second_to, options, second_root_call }
689
689
 
690
690
  before do
691
- second_root_call.stub write_command: true, id: second_root_call_id
692
- OutboundCall.should_receive(:new).and_return second_other_mock_call
693
- second_other_mock_call.should_receive(:join).once.with(second_root_call, {})
694
- second_other_mock_call.should_receive(:dial).once.with(second_to, options)
695
- second_root_call.should_receive(:answer).once
691
+ allow(second_root_call).to receive_messages write_command: true, id: second_root_call_id
692
+ expect(OutboundCall).to receive(:new).and_return second_other_mock_call
693
+ expect(second_other_mock_call).to receive(:join).once.with(second_root_call, {})
694
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, options)
695
+ expect(second_root_call).to receive(:answer).once
696
696
 
697
- SecureRandom.stub uuid: mixer
697
+ allow(SecureRandom).to receive_messages uuid: mixer
698
698
 
699
699
  dial.run subject
700
700
  other_dial.run subject
@@ -704,20 +704,20 @@ module Adhearsion
704
704
  end
705
705
 
706
706
  it "should split calls, rejoin to a mixer, and rejoin other calls to mixer" do
707
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
707
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
708
708
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
709
709
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
710
710
  end
711
- second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_return do
711
+ expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call) do
712
712
  second_root_call << Punchblock::Event::Unjoined.new(call_uri: second_other_mock_call.id)
713
713
  second_other_mock_call << Punchblock::Event::Unjoined.new(call_uri: second_root_call.id)
714
714
  end
715
715
 
716
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
717
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
716
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
717
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
718
718
 
719
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
720
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
719
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
720
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
721
721
 
722
722
  dial.merge other_dial
723
723
 
@@ -732,31 +732,31 @@ module Adhearsion
732
732
  second_root_call.async << mock_end
733
733
  second_other_mock_call.async << mock_end
734
734
 
735
- latch.wait(2).should be_true
735
+ expect(latch.wait(2)).to be_truthy
736
736
 
737
737
  waiter_thread.join
738
- dial.status.result.should be == :answer
738
+ expect(dial.status.result).to eq(:answer)
739
739
  end
740
740
 
741
741
  context "when join options were specified originally" do
742
742
  let(:options) { { join_options: {media: :direct} } }
743
743
 
744
744
  it "should rejoin with default options" do
745
- other_mock_call.stub(:unjoin)
746
- second_other_mock_call.stub(:unjoin)
745
+ allow(other_mock_call).to receive(:unjoin)
746
+ allow(second_other_mock_call).to receive(:unjoin)
747
747
 
748
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
749
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
748
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
749
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
750
750
 
751
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
752
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
751
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
752
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
753
753
 
754
754
  dial.merge other_dial
755
755
  end
756
756
  end
757
757
 
758
758
  it "should add the merged calls to the returned status" do
759
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
759
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
760
760
  dial.merge other_dial
761
761
 
762
762
  waiter_thread = Thread.new do
@@ -770,15 +770,15 @@ module Adhearsion
770
770
  second_root_call.async << mock_end
771
771
  second_other_mock_call.async << mock_end
772
772
 
773
- latch.wait(2).should be_true
773
+ expect(latch.wait(2)).to be_truthy
774
774
 
775
775
  waiter_thread.join
776
- dial.status.result.should be == :answer
777
- dial.status.calls.should include(second_root_call, second_other_mock_call)
776
+ expect(dial.status.result).to eq(:answer)
777
+ expect(dial.status.calls).to include(second_root_call, second_other_mock_call)
778
778
  end
779
779
 
780
780
  it "should not unblock until all joined calls end" do
781
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
781
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
782
782
 
783
783
  dial.merge other_dial
784
784
 
@@ -790,24 +790,24 @@ module Adhearsion
790
790
  sleep 0.5
791
791
 
792
792
  other_mock_call << mock_end
793
- latch.wait(2).should be_false
793
+ expect(latch.wait(2)).to be_falsey
794
794
 
795
795
  second_other_mock_call << mock_end
796
- latch.wait(2).should be_false
796
+ expect(latch.wait(2)).to be_falsey
797
797
 
798
798
  second_root_call << mock_end
799
- latch.wait(2).should be_true
799
+ expect(latch.wait(2)).to be_truthy
800
800
 
801
801
  waiter_thread.join
802
- dial.status.result.should be == :answer
802
+ expect(dial.status.result).to eq(:answer)
803
803
  end
804
804
 
805
805
  it "should cleanup merged calls when the root call ends" do
806
806
  [call, other_mock_call, second_root_call, second_other_mock_call].each do |c|
807
- c.stub join: true, unjoin: true
807
+ allow(c).to receive_messages join: true, unjoin: true
808
808
  end
809
809
  [other_mock_call, second_root_call, second_other_mock_call].each do |c|
810
- c.should_receive(:hangup).once
810
+ expect(c).to receive(:hangup).once
811
811
  end
812
812
 
813
813
  dial.merge other_dial
@@ -821,14 +821,14 @@ module Adhearsion
821
821
  sleep 0.5
822
822
 
823
823
  call << mock_end
824
- latch.wait(2).should be_true
824
+ expect(latch.wait(2)).to be_truthy
825
825
 
826
826
  waiter_thread.join
827
- dial.status.result.should be == :answer
827
+ expect(dial.status.result).to eq(:answer)
828
828
  end
829
829
 
830
830
  it "should subsequently rejoin to a mixer" do
831
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
831
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
832
832
 
833
833
  dial.merge other_dial
834
834
 
@@ -840,10 +840,10 @@ module Adhearsion
840
840
  sleep 0.5
841
841
 
842
842
  other_mock_call << mock_end
843
- latch.wait(2).should be_false
843
+ expect(latch.wait(2)).to be_falsey
844
844
 
845
845
  [call, second_root_call, second_other_mock_call].each do |call|
846
- call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do
846
+ expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do
847
847
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
848
848
  end
849
849
  end
@@ -851,7 +851,7 @@ module Adhearsion
851
851
  dial.split
852
852
 
853
853
  [call, second_root_call, second_other_mock_call].each do |call|
854
- call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do
854
+ expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do
855
855
  call << Punchblock::Event::Joined.new(mixer_name: mixer)
856
856
  end
857
857
  end
@@ -861,8 +861,8 @@ module Adhearsion
861
861
 
862
862
  describe "if splitting fails" do
863
863
  it "should not add the merged calls to the returned status" do
864
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
865
- other_dial.should_receive(:split).and_raise StandardError
864
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
865
+ expect(other_dial).to receive(:split).and_raise StandardError
866
866
  expect { dial.merge other_dial }.to raise_error(StandardError)
867
867
 
868
868
  waiter_thread = Thread.new do
@@ -876,17 +876,17 @@ module Adhearsion
876
876
  second_root_call.async << mock_end
877
877
  second_other_mock_call.async << mock_end
878
878
 
879
- latch.wait(2).should be_true
879
+ expect(latch.wait(2)).to be_truthy
880
880
 
881
881
  waiter_thread.join
882
- dial.status.result.should be == :answer
883
- dial.status.calls.should_not include(second_root_call, second_other_mock_call)
882
+ expect(dial.status.result).to eq(:answer)
883
+ expect(dial.status.calls).not_to include(second_root_call, second_other_mock_call)
884
884
  end
885
885
 
886
886
  it "should unblock before all joined calls end" do
887
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
887
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
888
888
 
889
- other_dial.should_receive(:split).and_raise StandardError
889
+ expect(other_dial).to receive(:split).and_raise StandardError
890
890
  expect { dial.merge other_dial }.to raise_error(StandardError)
891
891
 
892
892
  waiter_thread = Thread.new do
@@ -897,28 +897,28 @@ module Adhearsion
897
897
  sleep 0.5
898
898
 
899
899
  other_mock_call << mock_end
900
- latch.wait(2).should be_true
900
+ expect(latch.wait(2)).to be_truthy
901
901
 
902
902
  second_other_mock_call << mock_end
903
- latch.wait(2).should be_true
903
+ expect(latch.wait(2)).to be_truthy
904
904
 
905
905
  second_root_call << mock_end
906
- latch.wait(2).should be_true
906
+ expect(latch.wait(2)).to be_truthy
907
907
 
908
908
  waiter_thread.join
909
- dial.status.result.should be == :answer
909
+ expect(dial.status.result).to eq(:answer)
910
910
  end
911
911
 
912
912
  it "should not cleanup merged calls when the root call ends" do
913
913
  [call, other_mock_call, second_root_call, second_other_mock_call].each do |c|
914
- c.stub join: true, unjoin: true
914
+ allow(c).to receive_messages join: true, unjoin: true
915
915
  end
916
- other_mock_call.should_receive(:hangup).once
916
+ expect(other_mock_call).to receive(:hangup).once
917
917
  [second_root_call, second_other_mock_call].each do |c|
918
- c.should_receive(:hangup).never
918
+ expect(c).to receive(:hangup).never
919
919
  end
920
920
 
921
- other_dial.should_receive(:split).and_raise StandardError
921
+ expect(other_dial).to receive(:split).and_raise StandardError
922
922
  expect { dial.merge other_dial }.to raise_error(StandardError)
923
923
 
924
924
  waiter_thread = Thread.new do
@@ -930,16 +930,16 @@ module Adhearsion
930
930
  sleep 0.5
931
931
 
932
932
  call << mock_end
933
- latch.wait(2).should be_true
933
+ expect(latch.wait(2)).to be_truthy
934
934
 
935
935
  waiter_thread.join
936
- dial.status.result.should be == :answer
936
+ expect(dial.status.result).to eq(:answer)
937
937
  end
938
938
  end
939
939
 
940
940
  context "if a call hangs up" do
941
941
  it "should still allow splitting and rejoining" do
942
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
942
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
943
943
 
944
944
  dial.merge other_dial
945
945
 
@@ -951,25 +951,25 @@ module Adhearsion
951
951
  sleep 0.5
952
952
 
953
953
  [call, second_root_call, second_other_mock_call].each do |call|
954
- call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do
954
+ expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do
955
955
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
956
956
  end
957
957
  end
958
958
 
959
- other_mock_call.should_receive(:unjoin).and_raise Adhearsion::Call::Hangup
959
+ expect(other_mock_call).to receive(:unjoin).and_raise Adhearsion::Call::Hangup
960
960
 
961
961
  dial.split
962
962
 
963
963
  other_mock_call << mock_end
964
- latch.wait(2).should be_false
964
+ expect(latch.wait(2)).to be_falsey
965
965
 
966
966
  [call, second_root_call, second_other_mock_call].each do |call|
967
- call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do
967
+ expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do
968
968
  call << Punchblock::Event::Joined.new(mixer_name: mixer)
969
969
  end
970
970
  end
971
971
 
972
- other_mock_call.should_receive(:join).and_raise Adhearsion::Call::ExpiredError
972
+ expect(other_mock_call).to receive(:join).and_raise Adhearsion::Call::ExpiredError
973
973
 
974
974
  dial.rejoin
975
975
  end
@@ -977,14 +977,14 @@ module Adhearsion
977
977
 
978
978
  context "if the calls were not joined" do
979
979
  it "should still join to mixer" do
980
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
981
- second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
980
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
981
+ expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
982
982
 
983
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
984
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
983
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
984
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
985
985
 
986
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
987
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
986
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
987
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
988
988
 
989
989
  dial.merge other_dial
990
990
 
@@ -999,10 +999,10 @@ module Adhearsion
999
999
  second_root_call.async << mock_end
1000
1000
  second_other_mock_call.async << mock_end
1001
1001
 
1002
- latch.wait(2).should be_true
1002
+ expect(latch.wait(2)).to be_truthy
1003
1003
 
1004
1004
  waiter_thread.join
1005
- dial.status.result.should be == :answer
1005
+ expect(dial.status.result).to eq(:answer)
1006
1006
  end
1007
1007
  end
1008
1008
  end
@@ -1019,7 +1019,7 @@ module Adhearsion
1019
1019
  end
1020
1020
 
1021
1021
  it "should not make any outbound calls" do
1022
- OutboundCall.should_receive(:new).never
1022
+ expect(OutboundCall).to receive(:new).never
1023
1023
  expect { subject.dial to, options }.to raise_error
1024
1024
  end
1025
1025
  end
@@ -1030,12 +1030,12 @@ module Adhearsion
1030
1030
  let(:second_other_options) { options }
1031
1031
 
1032
1032
  before do
1033
- OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call
1033
+ expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call
1034
1034
 
1035
- other_mock_call.should_receive(:dial).once.with(to, other_options)
1035
+ expect(other_mock_call).to receive(:dial).once.with(to, other_options)
1036
1036
 
1037
- second_other_mock_call.should_receive(:dial).once.with(second_to, second_other_options)
1038
- second_other_mock_call.should_receive(:join).never
1037
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, second_other_options)
1038
+ expect(second_other_mock_call).to receive(:join).never
1039
1039
  end
1040
1040
 
1041
1041
  def dial_in_thread
@@ -1047,50 +1047,50 @@ module Adhearsion
1047
1047
  end
1048
1048
 
1049
1049
  it "dials all parties and joins the first one to answer, hanging up the rest" do
1050
- call.should_receive(:answer).once
1051
- other_mock_call.should_receive(:join).once.with(call, {})
1052
- second_other_mock_call.should_receive(:hangup).once.and_return do
1050
+ expect(call).to receive(:answer).once
1051
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1052
+ expect(second_other_mock_call).to receive(:hangup).once do
1053
1053
  second_other_mock_call << mock_end
1054
1054
  end
1055
1055
 
1056
1056
  t = dial_in_thread
1057
1057
 
1058
- latch.wait(2).should be_false
1058
+ expect(latch.wait(2)).to be_falsey
1059
1059
 
1060
1060
  other_mock_call << mock_answered
1061
1061
  other_mock_call << mock_end
1062
1062
 
1063
- latch.wait(2).should be_true
1063
+ expect(latch.wait(2)).to be_truthy
1064
1064
 
1065
1065
  t.join
1066
1066
  status = t.value
1067
- status.should be_a Dial::DialStatus
1068
- status.should have(2).calls
1069
- status.calls.each { |c| c.should be_a OutboundCall }
1067
+ expect(status).to be_a Dial::DialStatus
1068
+ expect(status.calls.size).to eq(2)
1069
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
1070
1070
  end
1071
1071
 
1072
1072
  it "unblocks when the joined call unjoins, allowing it to proceed further" do
1073
- call.should_receive(:answer).once
1074
- other_mock_call.should_receive(:join).once.with(call, {})
1075
- other_mock_call.should_receive(:hangup).once
1076
- second_other_mock_call.should_receive(:hangup).once.and_return do
1073
+ expect(call).to receive(:answer).once
1074
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1075
+ expect(other_mock_call).to receive(:hangup).once
1076
+ expect(second_other_mock_call).to receive(:hangup).once do
1077
1077
  second_other_mock_call << mock_end
1078
1078
  end
1079
1079
 
1080
1080
  t = dial_in_thread
1081
1081
 
1082
- latch.wait(2).should be_false
1082
+ expect(latch.wait(2)).to be_falsey
1083
1083
 
1084
1084
  other_mock_call << mock_answered
1085
1085
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1086
1086
 
1087
- latch.wait(2).should be_true
1087
+ expect(latch.wait(2)).to be_truthy
1088
1088
 
1089
1089
  t.join
1090
1090
  status = t.value
1091
- status.should be_a Dial::DialStatus
1092
- status.should have(2).calls
1093
- status.calls.each { |c| c.should be_a OutboundCall }
1091
+ expect(status).to be_a Dial::DialStatus
1092
+ expect(status.calls.size).to eq(2)
1093
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
1094
1094
  end
1095
1095
 
1096
1096
  describe "with options overrides" do
@@ -1154,11 +1154,11 @@ module Adhearsion
1154
1154
  latch.countdown!
1155
1155
  end
1156
1156
 
1157
- latch.wait(2).should be_false
1157
+ expect(latch.wait(2)).to be_falsey
1158
1158
  other_mock_call << mock_end
1159
- latch.wait(2).should be_false
1159
+ expect(latch.wait(2)).to be_falsey
1160
1160
  second_other_mock_call << mock_end
1161
- latch.wait(2).should be_true
1161
+ expect(latch.wait(2)).to be_truthy
1162
1162
  t.join
1163
1163
  end
1164
1164
  end
@@ -1172,19 +1172,19 @@ module Adhearsion
1172
1172
  other_mock_call << mock_end(:reject)
1173
1173
  second_other_mock_call << mock_end(:reject)
1174
1174
 
1175
- latch.wait(2).should be_true
1175
+ expect(latch.wait(2)).to be_truthy
1176
1176
 
1177
1177
  t.join
1178
1178
  status = t.value
1179
- status.result.should be == :no_answer
1179
+ expect(status.result).to eq(:no_answer)
1180
1180
  end
1181
1181
  end
1182
1182
 
1183
1183
  context "when a call is answered and joined, and the other ends with an error" do
1184
1184
  it "has an overall dial status of :answer" do
1185
- call.should_receive(:answer).once
1186
- other_mock_call.should_receive(:join).once.with(call, {})
1187
- second_other_mock_call.should_receive(:hangup).once.and_return do
1185
+ expect(call).to receive(:answer).once
1186
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1187
+ expect(second_other_mock_call).to receive(:hangup).once do
1188
1188
  second_other_mock_call << mock_end(:error)
1189
1189
  end
1190
1190
 
@@ -1195,11 +1195,11 @@ module Adhearsion
1195
1195
  other_mock_call << mock_answered
1196
1196
  other_mock_call << mock_end
1197
1197
 
1198
- latch.wait(2).should be_true
1198
+ expect(latch.wait(2)).to be_truthy
1199
1199
 
1200
1200
  t.join
1201
1201
  status = t.value
1202
- status.result.should be == :answer
1202
+ expect(status.result).to eq(:answer)
1203
1203
  end
1204
1204
  end
1205
1205
  end
@@ -1208,9 +1208,9 @@ module Adhearsion
1208
1208
  let(:timeout) { 3 }
1209
1209
 
1210
1210
  it "should abort the dial after the specified timeout" do
1211
- other_mock_call.should_receive(:dial).once
1212
- other_mock_call.should_receive(:hangup).once
1213
- OutboundCall.should_receive(:new).and_return other_mock_call
1211
+ expect(other_mock_call).to receive(:dial).once
1212
+ expect(other_mock_call).to receive(:hangup).once
1213
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1214
1214
 
1215
1215
  time = Time.now
1216
1216
 
@@ -1222,18 +1222,18 @@ module Adhearsion
1222
1222
 
1223
1223
  latch.wait
1224
1224
  time = Time.now - time
1225
- time.round.should be == timeout
1225
+ expect(time.round).to eq(timeout)
1226
1226
  t.join
1227
1227
  status = t.value
1228
- status.result.should be == :timeout
1228
+ expect(status.result).to eq(:timeout)
1229
1229
  end
1230
1230
 
1231
1231
  describe "if someone answers before the timeout elapses" do
1232
1232
  it "should not abort until the far end hangs up" do
1233
- other_mock_call.should_receive(:dial).once.with(to, hash_including(:timeout => timeout))
1234
- call.should_receive(:answer).once
1235
- other_mock_call.should_receive(:join).once.with(call, {})
1236
- OutboundCall.should_receive(:new).and_return other_mock_call
1233
+ expect(other_mock_call).to receive(:dial).once.with(to, hash_including(:timeout => timeout))
1234
+ expect(call).to receive(:answer).once
1235
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1236
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1237
1237
 
1238
1238
  time = Time.now
1239
1239
 
@@ -1243,20 +1243,20 @@ module Adhearsion
1243
1243
  status
1244
1244
  end
1245
1245
 
1246
- latch.wait(2).should be_false
1246
+ expect(latch.wait(2)).to be_falsey
1247
1247
 
1248
1248
  other_mock_call << mock_answered
1249
1249
 
1250
- latch.wait(2).should be_false
1250
+ expect(latch.wait(2)).to be_falsey
1251
1251
 
1252
1252
  other_mock_call << mock_end
1253
1253
 
1254
- latch.wait(0.1).should be_true
1254
+ expect(latch.wait(0.1)).to be_truthy
1255
1255
  time = Time.now - time
1256
- time.to_i.should be > timeout
1256
+ expect(time.to_i).to be > timeout
1257
1257
  t.join
1258
1258
  status = t.value
1259
- status.result.should be == :answer
1259
+ expect(status.result).to eq(:answer)
1260
1260
  end
1261
1261
  end
1262
1262
  end
@@ -1286,62 +1286,65 @@ module Adhearsion
1286
1286
  let(:options) { {:confirm => confirmation_controller, :confirm_metadata => {:foo => 'bar'}} }
1287
1287
 
1288
1288
  before do
1289
- other_mock_call.should_receive(:dial).once
1290
- OutboundCall.should_receive(:new).and_return other_mock_call
1289
+ expect(other_mock_call).to receive(:dial).once
1290
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1291
1291
  end
1292
1292
 
1293
1293
  it "should set the metadata on the controller" do
1294
- other_mock_call.should_receive(:hangup).once.and_return do
1294
+ expect(other_mock_call).to receive(:hangup).once do
1295
1295
  other_mock_call << mock_end
1296
1296
  end
1297
1297
  other_mock_call['confirm'] = false
1298
1298
 
1299
1299
  dial_in_thread
1300
1300
 
1301
- latch.wait(0.1).should be_false
1301
+ expect(latch.wait(0.1)).to be_falsey
1302
1302
 
1303
1303
  other_mock_call << mock_answered
1304
1304
 
1305
- confirmation_latch.wait(2).should be_true
1306
- latch.wait(2).should be_true
1305
+ expect(confirmation_latch.wait(2)).to be_truthy
1306
+ expect(latch.wait(2)).to be_truthy
1307
1307
 
1308
- other_mock_call[:foo].should == 'bar'
1308
+ expect(other_mock_call[:foo]).to eq('bar')
1309
1309
  end
1310
1310
  end
1311
1311
 
1312
1312
  context "when an outbound call is answered" do
1313
1313
  before do
1314
- other_mock_call.should_receive(:dial).once
1315
- OutboundCall.should_receive(:new).and_return other_mock_call
1314
+ expect(other_mock_call).to receive(:dial).once
1315
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1316
1316
  end
1317
1317
 
1318
1318
  it "should execute the specified confirmation controller" do
1319
- other_mock_call.should_receive(:hangup).once.and_return do
1319
+ expect(other_mock_call).to receive(:hangup).once do
1320
1320
  other_mock_call << mock_end
1321
1321
  end
1322
1322
  other_mock_call['confirm'] = false
1323
1323
 
1324
1324
  dial_in_thread
1325
1325
 
1326
- latch.wait(0.1).should be_false
1326
+ expect(latch.wait(0.1)).to be_falsey
1327
1327
 
1328
1328
  other_mock_call << mock_answered
1329
1329
 
1330
- confirmation_latch.wait(2).should be_true
1331
- latch.wait(2).should be_true
1330
+ expect(confirmation_latch.wait(2)).to be_truthy
1331
+ expect(latch.wait(2)).to be_truthy
1332
1332
  end
1333
1333
 
1334
1334
  it "should join the calls if the call is still active after execution of the call controller" do
1335
1335
  other_mock_call['confirm'] = true
1336
- call.should_receive(:answer).once
1337
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
1336
+ expect(call).to receive(:answer).once
1337
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
1338
1338
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1339
1339
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1340
1340
  end
1341
+ expect(other_mock_call).to receive(:hangup).once do
1342
+ other_mock_call << mock_end
1343
+ end
1341
1344
 
1342
1345
  t = dial_in_thread
1343
1346
 
1344
- latch.wait(2).should be_false
1347
+ expect(latch.wait(2)).to be_falsey
1345
1348
 
1346
1349
  base_time = Time.local(2008, 9, 1, 12, 0, 0)
1347
1350
  Timecop.freeze base_time
@@ -1351,48 +1354,47 @@ module Adhearsion
1351
1354
  base_time = Time.local(2008, 9, 1, 12, 0, 42)
1352
1355
  Timecop.freeze base_time
1353
1356
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1354
- other_mock_call << mock_end
1355
1357
 
1356
- latch.wait(2).should be_true
1358
+ expect(latch.wait(3)).to be_truthy
1357
1359
 
1358
1360
  t.join
1359
1361
  status = t.value
1360
- status.result.should be == :answer
1362
+ expect(status.result).to eq(:answer)
1361
1363
 
1362
1364
  joined_status = status.joins[status.calls.first]
1363
- joined_status.duration.should == 42.0
1364
- joined_status.result.should == :joined
1365
+ expect(joined_status.duration).to eq(42.0)
1366
+ expect(joined_status.result).to eq(:joined)
1365
1367
  end
1366
1368
 
1367
1369
  it "should not join the calls if the call is not active after execution of the call controller" do
1368
- other_mock_call.should_receive(:hangup).once.and_return do
1370
+ expect(other_mock_call).to receive(:hangup).once do
1369
1371
  other_mock_call << mock_end
1370
1372
  end
1371
1373
  other_mock_call['confirm'] = false
1372
- call.should_receive(:answer).never
1373
- other_mock_call.should_receive(:join).never.with(call)
1374
+ expect(call).to receive(:answer).never
1375
+ expect(other_mock_call).to receive(:join).never.with(call)
1374
1376
 
1375
1377
  t = dial_in_thread
1376
1378
 
1377
- latch.wait(2).should be_false
1379
+ expect(latch.wait(2)).to be_falsey
1378
1380
 
1379
1381
  other_mock_call << mock_answered
1380
1382
 
1381
- latch.wait(2).should be_true
1383
+ expect(latch.wait(2)).to be_truthy
1382
1384
 
1383
1385
  t.join
1384
1386
  status = t.value
1385
- status.result.should be == :unconfirmed
1387
+ expect(status.result).to eq(:unconfirmed)
1386
1388
 
1387
1389
  joined_status = status.joins[status.calls.first]
1388
- joined_status.duration.should == 0.0
1389
- joined_status.result.should == :unconfirmed
1390
+ expect(joined_status.duration).to eq(0.0)
1391
+ expect(joined_status.result).to eq(:unconfirmed)
1390
1392
  end
1391
1393
  end
1392
1394
 
1393
1395
  context "when multiple calls are made" do
1394
1396
  before do
1395
- OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call
1397
+ expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call
1396
1398
  end
1397
1399
 
1398
1400
  def dial_in_thread
@@ -1406,41 +1408,41 @@ module Adhearsion
1406
1408
  context "when one answers" do
1407
1409
  it "should only execute the confirmation controller on the first call to answer, immediately hanging up all others" do
1408
1410
  other_mock_call['confirm'] = true
1409
- call.should_receive(:answer).once
1411
+ expect(call).to receive(:answer).once
1410
1412
 
1411
- other_mock_call.should_receive(:dial).once.with(to, from: nil)
1412
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
1413
+ expect(other_mock_call).to receive(:dial).once.with(to, from: nil)
1414
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
1413
1415
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1414
1416
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1415
1417
  end
1416
- other_mock_call.should_receive(:hangup).once.and_return do
1418
+ expect(other_mock_call).to receive(:hangup).once do
1417
1419
  other_mock_call << mock_end
1418
1420
  end
1419
1421
 
1420
- second_other_mock_call.should_receive(:dial).once.with(second_to, from: nil)
1421
- second_other_mock_call.should_receive(:join).never
1422
- second_other_mock_call.should_receive(:execute_controller).never
1423
- second_other_mock_call.should_receive(:hangup).once.and_return do
1422
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, from: nil)
1423
+ expect(second_other_mock_call).to receive(:join).never
1424
+ expect(second_other_mock_call).to receive(:execute_controller).never
1425
+ expect(second_other_mock_call).to receive(:hangup).once do
1424
1426
  second_other_mock_call << mock_end(:foo)
1425
1427
  end
1426
1428
 
1427
1429
  t = dial_in_thread
1428
1430
 
1429
- latch.wait(2).should be_false
1431
+ expect(latch.wait(2)).to be_falsey
1430
1432
 
1431
1433
  other_mock_call << mock_answered
1432
- confirmation_latch.wait(2).should be_true
1434
+ expect(confirmation_latch.wait(2)).to be_truthy
1433
1435
 
1434
1436
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1435
1437
 
1436
- latch.wait(2).should be_true
1438
+ expect(latch.wait(2)).to be_truthy
1437
1439
 
1438
1440
  t.join
1439
1441
  status = t.value
1440
- status.should be_a Dial::DialStatus
1441
- status.should have(2).calls
1442
- status.calls.each { |c| c.should be_a OutboundCall }
1443
- status.result.should be == :answer
1442
+ expect(status).to be_a Dial::DialStatus
1443
+ expect(status.calls.size).to eq(2)
1444
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
1445
+ expect(status.result).to eq(:answer)
1444
1446
  end
1445
1447
  end
1446
1448
  end
@@ -1449,31 +1451,31 @@ module Adhearsion
1449
1451
 
1450
1452
  describe "#dial_and_confirm" do
1451
1453
  it "should dial the call to the correct endpoint and return a dial status object" do
1452
- OutboundCall.should_receive(:new).and_return other_mock_call
1453
- other_mock_call.should_receive(:dial).with(to, :from => 'foo').once
1454
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1455
+ expect(other_mock_call).to receive(:dial).with(to, :from => 'foo').once
1454
1456
  dial_thread = Thread.new do
1455
1457
  status = subject.dial_and_confirm(to, :from => 'foo')
1456
1458
 
1457
- status.should be_a Dial::DialStatus
1459
+ expect(status).to be_a Dial::DialStatus
1458
1460
  joined_status = status.joins[status.calls.first]
1459
- joined_status.duration.should == 0.0
1460
- joined_status.result.should == :no_answer
1461
+ expect(joined_status.duration).to eq(0.0)
1462
+ expect(joined_status.result).to eq(:no_answer)
1461
1463
  end
1462
1464
  sleep 0.1
1463
1465
  other_mock_call << mock_end
1464
- dial_thread.join.should be_true
1466
+ expect(dial_thread.join).to be_truthy
1465
1467
  end
1466
1468
 
1467
1469
  it "should default the caller ID to that of the original call" do
1468
- call.stub :from => 'sip:foo@bar.com'
1469
- OutboundCall.should_receive(:new).and_return other_mock_call
1470
- other_mock_call.should_receive(:dial).with(to, :from => 'sip:foo@bar.com').once
1470
+ allow(call).to receive_messages :from => 'sip:foo@bar.com'
1471
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1472
+ expect(other_mock_call).to receive(:dial).with(to, :from => 'sip:foo@bar.com').once
1471
1473
  dial_thread = Thread.new do
1472
1474
  subject.dial_and_confirm to
1473
1475
  end
1474
1476
  sleep 0.1
1475
1477
  other_mock_call << mock_end
1476
- dial_thread.join.should be_true
1478
+ expect(dial_thread.join).to be_truthy
1477
1479
  end
1478
1480
 
1479
1481
  let(:options) { { :foo => :bar } }
@@ -1488,61 +1490,61 @@ module Adhearsion
1488
1490
 
1489
1491
  describe "without a block" do
1490
1492
  before do
1491
- other_mock_call.should_receive(:dial).once.with(to, options)
1492
- OutboundCall.should_receive(:new).and_return other_mock_call
1493
+ expect(other_mock_call).to receive(:dial).once.with(to, options)
1494
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
1493
1495
  end
1494
1496
 
1495
1497
  it "blocks the original controller until the new call ends" do
1496
1498
  dial_in_thread
1497
1499
 
1498
- latch.wait(2).should be_false
1500
+ expect(latch.wait(2)).to be_falsey
1499
1501
 
1500
1502
  other_mock_call << mock_end
1501
1503
 
1502
- latch.wait(2).should be_true
1504
+ expect(latch.wait(2)).to be_truthy
1503
1505
  end
1504
1506
 
1505
1507
  it "unblocks the original controller if the original call ends" do
1506
- other_mock_call.should_receive(:hangup).once
1508
+ expect(other_mock_call).to receive(:hangup).once
1507
1509
  dial_in_thread
1508
1510
 
1509
- latch.wait(2).should be_false
1511
+ expect(latch.wait(2)).to be_falsey
1510
1512
 
1511
1513
  call << mock_end
1512
1514
 
1513
- latch.wait(2).should be_true
1515
+ expect(latch.wait(2)).to be_truthy
1514
1516
  end
1515
1517
 
1516
1518
  it "joins the new call to the existing one on answer" do
1517
- call.should_receive(:answer).once
1518
- other_mock_call.should_receive(:join).once.with(call, {})
1519
+ expect(call).to receive(:answer).once
1520
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1519
1521
 
1520
1522
  dial_in_thread
1521
1523
 
1522
- latch.wait(2).should be_false
1524
+ expect(latch.wait(2)).to be_falsey
1523
1525
 
1524
1526
  other_mock_call << mock_answered
1525
1527
  other_mock_call << mock_end
1526
1528
 
1527
- latch.wait(2).should be_true
1529
+ expect(latch.wait(2)).to be_truthy
1528
1530
  end
1529
1531
 
1530
1532
  context "with a join target specified" do
1531
1533
  let(:options) { { join_target: {mixer_name: 'foobar'} } }
1532
1534
 
1533
1535
  it "joins the calls to the specified target on answer" do
1534
- call.should_receive(:answer).once
1535
- call.should_receive(:join).once.with({mixer_name: 'foobar'}, {})
1536
- other_mock_call.should_receive(:join).once.with({mixer_name: 'foobar'}, {})
1536
+ expect(call).to receive(:answer).once
1537
+ expect(call).to receive(:join).once.with({mixer_name: 'foobar'}, {})
1538
+ expect(other_mock_call).to receive(:join).once.with({mixer_name: 'foobar'}, {})
1537
1539
 
1538
1540
  dial_in_thread
1539
1541
 
1540
- latch.wait(2).should be_false
1542
+ expect(latch.wait(2)).to be_falsey
1541
1543
 
1542
1544
  other_mock_call << mock_answered
1543
1545
  other_mock_call << mock_end
1544
1546
 
1545
- latch.wait(2).should be_true
1547
+ expect(latch.wait(2)).to be_truthy
1546
1548
  end
1547
1549
  end
1548
1550
 
@@ -1551,18 +1553,18 @@ module Adhearsion
1551
1553
  let(:options) { { pre_join: ->(call) { foo.bar call } } }
1552
1554
 
1553
1555
  it "executes the callback prior to joining" do
1554
- foo.should_receive(:bar).once.with(other_mock_call).ordered
1555
- call.should_receive(:answer).once.ordered
1556
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
1556
+ expect(foo).to receive(:bar).once.with(other_mock_call).ordered
1557
+ expect(call).to receive(:answer).once.ordered
1558
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
1557
1559
 
1558
1560
  dial_in_thread
1559
1561
 
1560
- latch.wait(2).should be_false
1562
+ expect(latch.wait(2)).to be_falsey
1561
1563
 
1562
1564
  other_mock_call << mock_answered
1563
1565
  other_mock_call << mock_end
1564
1566
 
1565
- latch.wait(2).should be_true
1567
+ expect(latch.wait(2)).to be_truthy
1566
1568
  end
1567
1569
  end
1568
1570
 
@@ -1576,19 +1578,19 @@ module Adhearsion
1576
1578
  end
1577
1579
 
1578
1580
  it "plays the ringback asynchronously, terminating prior to joining" do
1579
- subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
1580
- component.should_receive(:stop!).twice
1581
- call.should_receive(:answer).once.ordered
1582
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
1581
+ expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
1582
+ expect(component).to receive(:stop!).twice
1583
+ expect(call).to receive(:answer).once.ordered
1584
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
1583
1585
 
1584
1586
  dial_in_thread
1585
1587
 
1586
- latch.wait(2).should be_false
1588
+ expect(latch.wait(2)).to be_falsey
1587
1589
 
1588
1590
  other_mock_call << mock_answered
1589
1591
  other_mock_call << mock_end
1590
1592
 
1591
- latch.wait(2).should be_true
1593
+ expect(latch.wait(2)).to be_truthy
1592
1594
  end
1593
1595
 
1594
1596
  context "as a callback" do
@@ -1596,51 +1598,51 @@ module Adhearsion
1596
1598
  let(:options) { { ringback: -> { foo.bar; component } } }
1597
1599
 
1598
1600
  it "calls the callback to start, and uses the return value of the callback to stop the ringback" do
1599
- foo.should_receive(:bar).once.ordered
1600
- component.should_receive(:stop!).twice
1601
- call.should_receive(:answer).once.ordered
1602
- other_mock_call.should_receive(:join).once.with(call, {}).ordered
1601
+ expect(foo).to receive(:bar).once.ordered
1602
+ expect(component).to receive(:stop!).twice
1603
+ expect(call).to receive(:answer).once.ordered
1604
+ expect(other_mock_call).to receive(:join).once.with(call, {}).ordered
1603
1605
 
1604
1606
  dial_in_thread
1605
1607
 
1606
- latch.wait(2).should be_false
1608
+ expect(latch.wait(2)).to be_falsey
1607
1609
 
1608
1610
  other_mock_call << mock_answered
1609
1611
  other_mock_call << mock_end
1610
1612
 
1611
- latch.wait(2).should be_true
1613
+ expect(latch.wait(2)).to be_truthy
1612
1614
  end
1613
1615
  end
1614
1616
 
1615
1617
  context "when the call is rejected" do
1616
1618
  it "terminates the ringback before returning" do
1617
- subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
1618
- component.should_receive(:stop!).once
1619
+ expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component)
1620
+ expect(component).to receive(:stop!).once
1619
1621
 
1620
1622
  t = dial_in_thread
1621
1623
 
1622
- latch.wait(2).should be_false
1624
+ expect(latch.wait(2)).to be_falsey
1623
1625
 
1624
1626
  other_mock_call << mock_end(:reject)
1625
1627
 
1626
- latch.wait(2).should be_true
1628
+ expect(latch.wait(2)).to be_truthy
1627
1629
  end
1628
1630
  end
1629
1631
  end
1630
1632
 
1631
1633
  it "hangs up the new call when the root call ends" do
1632
- other_mock_call.should_receive(:hangup).once
1633
- call.should_receive(:answer).once
1634
- other_mock_call.should_receive(:join).once.with(call, {})
1634
+ expect(other_mock_call).to receive(:hangup).once
1635
+ expect(call).to receive(:answer).once
1636
+ expect(other_mock_call).to receive(:join).once.with(call, {})
1635
1637
 
1636
1638
  dial_in_thread
1637
1639
 
1638
- latch.wait(2).should be_false
1640
+ expect(latch.wait(2)).to be_falsey
1639
1641
 
1640
1642
  other_mock_call << mock_answered
1641
1643
  call << mock_end
1642
1644
 
1643
- latch.wait(2).should be_true
1645
+ expect(latch.wait(2)).to be_truthy
1644
1646
  end
1645
1647
 
1646
1648
  context "when the call is rejected" do
@@ -1651,11 +1653,11 @@ module Adhearsion
1651
1653
 
1652
1654
  other_mock_call << mock_end(:reject)
1653
1655
 
1654
- latch.wait(2).should be_true
1656
+ expect(latch.wait(2)).to be_truthy
1655
1657
 
1656
1658
  t.join
1657
1659
  status = t.value
1658
- status.result.should be == :no_answer
1660
+ expect(status.result).to eq(:no_answer)
1659
1661
  end
1660
1662
  end
1661
1663
 
@@ -1667,22 +1669,22 @@ module Adhearsion
1667
1669
 
1668
1670
  other_mock_call << mock_end(:error)
1669
1671
 
1670
- latch.wait(2).should be_true
1672
+ expect(latch.wait(2)).to be_truthy
1671
1673
 
1672
1674
  t.join
1673
1675
  status = t.value
1674
- status.result.should be == :error
1676
+ expect(status.result).to eq(:error)
1675
1677
 
1676
1678
  joined_status = status.joins[status.calls.first]
1677
- joined_status.duration.should == 0.0
1678
- joined_status.result.should == :error
1679
+ expect(joined_status.duration).to eq(0.0)
1680
+ expect(joined_status.result).to eq(:error)
1679
1681
  end
1680
1682
  end
1681
1683
 
1682
1684
  context "when the call is answered and joined" do
1683
1685
  it "has an overall dial status of :answer" do
1684
- call.should_receive(:answer).once
1685
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
1686
+ expect(call).to receive(:answer).once
1687
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
1686
1688
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1687
1689
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1688
1690
  end
@@ -1694,23 +1696,23 @@ module Adhearsion
1694
1696
  other_mock_call << mock_answered
1695
1697
  other_mock_call << mock_end
1696
1698
 
1697
- latch.wait(2).should be_true
1699
+ expect(latch.wait(2)).to be_truthy
1698
1700
 
1699
1701
  t.join
1700
1702
  status = t.value
1701
- status.result.should be == :answer
1703
+ expect(status.result).to eq(:answer)
1702
1704
 
1703
1705
  joined_status = status.joins[status.calls.first]
1704
- joined_status.result.should == :joined
1706
+ expect(joined_status.result).to eq(:joined)
1705
1707
  end
1706
1708
 
1707
1709
  it "records the duration of the join" do
1708
- call.should_receive(:answer).once
1709
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
1710
+ expect(call).to receive(:answer).once
1711
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
1710
1712
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1711
1713
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1712
1714
  end
1713
- other_mock_call.stub hangup: true
1715
+ allow(other_mock_call).to receive_messages hangup: true
1714
1716
 
1715
1717
  t = dial_in_thread
1716
1718
 
@@ -1726,25 +1728,25 @@ module Adhearsion
1726
1728
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1727
1729
  other_mock_call << mock_end
1728
1730
 
1729
- latch.wait(2).should be_true
1731
+ expect(latch.wait(2)).to be_truthy
1730
1732
 
1731
1733
  t.join
1732
1734
  status = t.value
1733
- status.result.should be == :answer
1735
+ expect(status.result).to eq(:answer)
1734
1736
  joined_status = status.joins[status.calls.first]
1735
- joined_status.duration.should == 37.0
1737
+ expect(joined_status.duration).to eq(37.0)
1736
1738
  end
1737
1739
 
1738
1740
  context "when join options are specified" do
1739
1741
  let(:options) { { join_options: {media: :direct} } }
1740
1742
 
1741
1743
  it "joins the calls with those options" do
1742
- call.should_receive(:answer).once
1743
- other_mock_call.should_receive(:join).once.with(call, media: :direct).and_return do
1744
+ expect(call).to receive(:answer).once
1745
+ expect(other_mock_call).to receive(:join).once.with(call, media: :direct) do
1744
1746
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1745
1747
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1746
1748
  end
1747
- other_mock_call.stub hangup: true
1749
+ allow(other_mock_call).to receive_messages hangup: true
1748
1750
 
1749
1751
  t = dial_in_thread
1750
1752
 
@@ -1755,7 +1757,7 @@ module Adhearsion
1755
1757
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1756
1758
  other_mock_call << mock_end
1757
1759
 
1758
- latch.wait(2).should be_true
1760
+ expect(latch.wait(2)).to be_truthy
1759
1761
 
1760
1762
  t.join
1761
1763
  end
@@ -1766,19 +1768,19 @@ module Adhearsion
1766
1768
  let(:join_target) { call }
1767
1769
 
1768
1770
  before do
1769
- call.should_receive(:answer).once
1770
- other_mock_call.should_receive(:join).once.with(join_target, join_options).and_return do
1771
+ expect(call).to receive(:answer).once
1772
+ expect(other_mock_call).to receive(:join).once.with(join_target, join_options) do
1771
1773
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1772
1774
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1773
1775
  end
1774
- other_mock_call.stub(:unjoin).and_return do
1776
+ allow(other_mock_call).to receive(:unjoin) do
1775
1777
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
1776
1778
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1777
1779
  end
1778
1780
  end
1779
1781
 
1780
1782
  it "should unjoin the calls" do
1781
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
1783
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
1782
1784
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
1783
1785
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1784
1786
  end
@@ -1798,10 +1800,10 @@ module Adhearsion
1798
1800
  dial.split
1799
1801
  other_mock_call << mock_end
1800
1802
 
1801
- latch.wait(2).should be_true
1803
+ expect(latch.wait(2)).to be_truthy
1802
1804
 
1803
1805
  waiter_thread.join
1804
- dial.status.result.should be == :answer
1806
+ expect(dial.status.result).to eq(:answer)
1805
1807
  end
1806
1808
 
1807
1809
  it "should not unblock immediately" do
@@ -1819,14 +1821,14 @@ module Adhearsion
1819
1821
 
1820
1822
  dial.split
1821
1823
 
1822
- latch.wait(2).should be_false
1824
+ expect(latch.wait(2)).to be_falsey
1823
1825
 
1824
1826
  other_mock_call << mock_end
1825
1827
 
1826
- latch.wait(2).should be_true
1828
+ expect(latch.wait(2)).to be_truthy
1827
1829
 
1828
1830
  waiter_thread.join
1829
- dial.status.result.should be == :answer
1831
+ expect(dial.status.result).to eq(:answer)
1830
1832
  end
1831
1833
 
1832
1834
  it "should set end time" do
@@ -1853,13 +1855,13 @@ module Adhearsion
1853
1855
  Timecop.freeze base_time
1854
1856
  other_mock_call << mock_end
1855
1857
 
1856
- latch.wait(2).should be_true
1858
+ expect(latch.wait(2)).to be_truthy
1857
1859
 
1858
1860
  waiter_thread.join
1859
1861
  status = dial.status
1860
- status.result.should be == :answer
1862
+ expect(status.result).to eq(:answer)
1861
1863
  joined_status = status.joins[status.calls.first]
1862
- joined_status.duration.should == 37.0
1864
+ expect(joined_status.duration).to eq(37.0)
1863
1865
  end
1864
1866
 
1865
1867
  context "with new controllers specified" do
@@ -1894,32 +1896,32 @@ module Adhearsion
1894
1896
 
1895
1897
  other_mock_call << mock_answered
1896
1898
 
1897
- should_receive(:callback).once.with(call)
1898
- should_receive(:callback).once.with(other_mock_call)
1899
+ expect(self).to receive(:callback).once.with(call)
1900
+ expect(self).to receive(:callback).once.with(other_mock_call)
1899
1901
 
1900
1902
  dial.split main: main_split_controller, others: others_split_controller, main_callback: ->(call) { self.callback(call) }, others_callback: ->(call) { self.callback(call) }
1901
1903
 
1902
- latch.wait(2).should be_false
1903
- split_latch.wait(2).should be_true
1904
+ expect(latch.wait(2)).to be_falsey
1905
+ expect(split_latch.wait(2)).to be_truthy
1904
1906
 
1905
- call['hit_split_controller'].should == main_split_controller
1906
- call['split_controller_metadata']['current_dial'].should be dial
1907
+ expect(call['hit_split_controller']).to eq(main_split_controller)
1908
+ expect(call['split_controller_metadata']['current_dial']).to be dial
1907
1909
 
1908
- other_mock_call['hit_split_controller'].should == others_split_controller
1909
- other_mock_call['split_controller_metadata']['current_dial'].should be dial
1910
+ expect(other_mock_call['hit_split_controller']).to eq(others_split_controller)
1911
+ expect(other_mock_call['split_controller_metadata']['current_dial']).to be dial
1910
1912
 
1911
1913
  other_mock_call << mock_end
1912
1914
 
1913
- latch.wait(2).should be_true
1915
+ expect(latch.wait(2)).to be_truthy
1914
1916
 
1915
1917
  waiter_thread.join
1916
- dial.status.result.should be == :answer
1918
+ expect(dial.status.result).to eq(:answer)
1917
1919
  end
1918
1920
  end
1919
1921
 
1920
1922
  context "when rejoining" do
1921
1923
  it "should rejoin the calls" do
1922
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
1924
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
1923
1925
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
1924
1926
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
1925
1927
  end
@@ -1938,7 +1940,7 @@ module Adhearsion
1938
1940
 
1939
1941
  dial.split
1940
1942
 
1941
- other_mock_call.should_receive(:join).once.ordered.with(call, {}).and_return do
1943
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, {}) do
1942
1944
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1943
1945
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1944
1946
  end
@@ -1946,17 +1948,17 @@ module Adhearsion
1946
1948
 
1947
1949
  other_mock_call << mock_end
1948
1950
 
1949
- latch.wait(2).should be_true
1951
+ expect(latch.wait(2)).to be_truthy
1950
1952
 
1951
1953
  waiter_thread.join
1952
- dial.status.result.should be == :answer
1954
+ expect(dial.status.result).to eq(:answer)
1953
1955
  end
1954
1956
 
1955
1957
  context "when join options were set originally" do
1956
1958
  let(:options) { { join_options: {media: :direct} } }
1957
1959
 
1958
1960
  it "should rejoin with the same parameters" do
1959
- other_mock_call.stub(:unjoin)
1961
+ allow(other_mock_call).to receive(:unjoin)
1960
1962
 
1961
1963
  dial = Dial::ParallelConfirmationDial.new to, options, call
1962
1964
  dial.run subject
@@ -1965,7 +1967,7 @@ module Adhearsion
1965
1967
 
1966
1968
  dial.split
1967
1969
 
1968
- other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct).and_return do
1970
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) do
1969
1971
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1970
1972
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1971
1973
  end
@@ -1975,7 +1977,7 @@ module Adhearsion
1975
1977
 
1976
1978
  context "when join options are passed to rejoin" do
1977
1979
  it "should rejoin with those parameters" do
1978
- other_mock_call.stub(:unjoin)
1980
+ allow(other_mock_call).to receive(:unjoin)
1979
1981
 
1980
1982
  dial = Dial::ParallelConfirmationDial.new to, options, call
1981
1983
  dial.run subject
@@ -1984,7 +1986,7 @@ module Adhearsion
1984
1986
 
1985
1987
  dial.split
1986
1988
 
1987
- other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct).and_return do
1989
+ expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) do
1988
1990
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
1989
1991
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
1990
1992
  end
@@ -1997,9 +1999,9 @@ module Adhearsion
1997
1999
  let(:options) { { join_target: join_target } }
1998
2000
 
1999
2001
  it "joins the calls to the specified target on answer" do
2000
- call.should_receive(:join).once.with(join_target, {})
2001
- other_mock_call.should_receive(:unjoin).once.ordered.with(join_target)
2002
- call.should_receive(:unjoin).once.ordered.with(join_target).and_return do
2002
+ expect(call).to receive(:join).once.with(join_target, {})
2003
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(join_target)
2004
+ expect(call).to receive(:unjoin).once.ordered.with(join_target) do
2003
2005
  call << Punchblock::Event::Unjoined.new(join_target)
2004
2006
  other_mock_call << Punchblock::Event::Unjoined.new(join_target)
2005
2007
  end
@@ -2018,16 +2020,16 @@ module Adhearsion
2018
2020
 
2019
2021
  dial.split
2020
2022
 
2021
- call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
2022
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
2023
+ expect(call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
2024
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {})
2023
2025
  dial.rejoin
2024
2026
 
2025
2027
  other_mock_call << mock_end
2026
2028
 
2027
- latch.wait(2).should be_true
2029
+ expect(latch.wait(2)).to be_truthy
2028
2030
 
2029
2031
  waiter_thread.join
2030
- dial.status.result.should be == :answer
2032
+ expect(dial.status.result).to eq(:answer)
2031
2033
  end
2032
2034
  end
2033
2035
 
@@ -2035,7 +2037,7 @@ module Adhearsion
2035
2037
  let(:mixer) { SecureRandom.uuid }
2036
2038
 
2037
2039
  it "should join all calls to the mixer" do
2038
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
2040
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
2039
2041
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
2040
2042
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
2041
2043
  end
@@ -2054,20 +2056,20 @@ module Adhearsion
2054
2056
 
2055
2057
  dial.split
2056
2058
 
2057
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2058
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2059
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2060
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2059
2061
  dial.rejoin mixer_name: mixer
2060
2062
 
2061
2063
  other_mock_call << mock_end
2062
2064
 
2063
- latch.wait(2).should be_true
2065
+ expect(latch.wait(2)).to be_truthy
2064
2066
 
2065
2067
  waiter_thread.join
2066
- dial.status.result.should be == :answer
2068
+ expect(dial.status.result).to eq(:answer)
2067
2069
  end
2068
2070
 
2069
2071
  it "#split should then unjoin calls from the mixer" do
2070
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
2072
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
2071
2073
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
2072
2074
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
2073
2075
  end
@@ -2086,24 +2088,24 @@ module Adhearsion
2086
2088
 
2087
2089
  dial.split
2088
2090
 
2089
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2090
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2091
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2092
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2091
2093
  dial.rejoin mixer_name: mixer
2092
2094
 
2093
- other_mock_call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do
2095
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do
2094
2096
  other_mock_call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
2095
2097
  end
2096
- call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do
2098
+ expect(call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do
2097
2099
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
2098
2100
  end
2099
2101
  dial.split
2100
2102
 
2101
2103
  other_mock_call << mock_end
2102
2104
 
2103
- latch.wait(2).should be_true
2105
+ expect(latch.wait(2)).to be_truthy
2104
2106
 
2105
2107
  waiter_thread.join
2106
- dial.status.result.should be == :answer
2108
+ expect(dial.status.result).to eq(:answer)
2107
2109
  end
2108
2110
  end
2109
2111
  end
@@ -2117,13 +2119,13 @@ module Adhearsion
2117
2119
  let(:other_dial) { Dial::ParallelConfirmationDial.new second_to, options, second_root_call }
2118
2120
 
2119
2121
  before do
2120
- second_root_call.stub write_command: true, id: second_root_call_id
2121
- OutboundCall.should_receive(:new).and_return second_other_mock_call
2122
- second_other_mock_call.should_receive(:join).once.with(second_root_call, {})
2123
- second_other_mock_call.should_receive(:dial).once.with(second_to, options)
2124
- second_root_call.should_receive(:answer).once
2122
+ allow(second_root_call).to receive_messages write_command: true, id: second_root_call_id
2123
+ expect(OutboundCall).to receive(:new).and_return second_other_mock_call
2124
+ expect(second_other_mock_call).to receive(:join).once.with(second_root_call, {})
2125
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, options)
2126
+ expect(second_root_call).to receive(:answer).once
2125
2127
 
2126
- SecureRandom.stub uuid: mixer
2128
+ allow(SecureRandom).to receive_messages uuid: mixer
2127
2129
 
2128
2130
  dial.run subject
2129
2131
  other_dial.run subject
@@ -2133,20 +2135,20 @@ module Adhearsion
2133
2135
  end
2134
2136
 
2135
2137
  it "should split calls, rejoin to a mixer, and rejoin other calls to mixer" do
2136
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do
2138
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do
2137
2139
  call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id)
2138
2140
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
2139
2141
  end
2140
- second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_return do
2142
+ expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call) do
2141
2143
  second_root_call << Punchblock::Event::Unjoined.new(call_uri: second_other_mock_call.id)
2142
2144
  second_other_mock_call << Punchblock::Event::Unjoined.new(call_uri: second_root_call.id)
2143
2145
  end
2144
2146
 
2145
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2146
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2147
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2148
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2147
2149
 
2148
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2149
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2150
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2151
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2150
2152
 
2151
2153
  dial.merge other_dial
2152
2154
 
@@ -2161,31 +2163,31 @@ module Adhearsion
2161
2163
  second_root_call.async << mock_end
2162
2164
  second_other_mock_call.async << mock_end
2163
2165
 
2164
- latch.wait(2).should be_true
2166
+ expect(latch.wait(2)).to be_truthy
2165
2167
 
2166
2168
  waiter_thread.join
2167
- dial.status.result.should be == :answer
2169
+ expect(dial.status.result).to eq(:answer)
2168
2170
  end
2169
2171
 
2170
2172
  context "when join options were specified originally" do
2171
2173
  let(:options) { { join_options: {media: :direct} } }
2172
2174
 
2173
2175
  it "should rejoin with default options" do
2174
- other_mock_call.stub(:unjoin)
2175
- second_other_mock_call.stub(:unjoin)
2176
+ allow(other_mock_call).to receive(:unjoin)
2177
+ allow(second_other_mock_call).to receive(:unjoin)
2176
2178
 
2177
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2178
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2179
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2180
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2179
2181
 
2180
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2181
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2182
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2183
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2182
2184
 
2183
2185
  dial.merge other_dial
2184
2186
  end
2185
2187
  end
2186
2188
 
2187
2189
  it "should add the merged calls to the returned status" do
2188
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
2190
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
2189
2191
  dial.merge other_dial
2190
2192
 
2191
2193
  waiter_thread = Thread.new do
@@ -2199,15 +2201,15 @@ module Adhearsion
2199
2201
  second_root_call.async << mock_end
2200
2202
  second_other_mock_call.async << mock_end
2201
2203
 
2202
- latch.wait(2).should be_true
2204
+ expect(latch.wait(2)).to be_truthy
2203
2205
 
2204
2206
  waiter_thread.join
2205
- dial.status.result.should be == :answer
2206
- dial.status.calls.should include(second_root_call, second_other_mock_call)
2207
+ expect(dial.status.result).to eq(:answer)
2208
+ expect(dial.status.calls).to include(second_root_call, second_other_mock_call)
2207
2209
  end
2208
2210
 
2209
2211
  it "should not unblock until all joined calls end" do
2210
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
2212
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
2211
2213
 
2212
2214
  dial.merge other_dial
2213
2215
 
@@ -2219,24 +2221,24 @@ module Adhearsion
2219
2221
  sleep 0.5
2220
2222
 
2221
2223
  other_mock_call << mock_end
2222
- latch.wait(2).should be_false
2224
+ expect(latch.wait(2)).to be_falsey
2223
2225
 
2224
2226
  second_other_mock_call << mock_end
2225
- latch.wait(2).should be_false
2227
+ expect(latch.wait(2)).to be_falsey
2226
2228
 
2227
2229
  second_root_call << mock_end
2228
- latch.wait(2).should be_true
2230
+ expect(latch.wait(2)).to be_truthy
2229
2231
 
2230
2232
  waiter_thread.join
2231
- dial.status.result.should be == :answer
2233
+ expect(dial.status.result).to eq(:answer)
2232
2234
  end
2233
2235
 
2234
2236
  it "should cleanup merged calls when the root call ends" do
2235
2237
  [call, other_mock_call, second_root_call, second_other_mock_call].each do |c|
2236
- c.stub join: true, unjoin: true
2238
+ allow(c).to receive_messages join: true, unjoin: true
2237
2239
  end
2238
2240
  [other_mock_call, second_root_call, second_other_mock_call].each do |c|
2239
- c.should_receive(:hangup).once
2241
+ expect(c).to receive(:hangup).once
2240
2242
  end
2241
2243
 
2242
2244
  dial.merge other_dial
@@ -2250,14 +2252,14 @@ module Adhearsion
2250
2252
  sleep 0.5
2251
2253
 
2252
2254
  call << mock_end
2253
- latch.wait(2).should be_true
2255
+ expect(latch.wait(2)).to be_truthy
2254
2256
 
2255
2257
  waiter_thread.join
2256
- dial.status.result.should be == :answer
2258
+ expect(dial.status.result).to eq(:answer)
2257
2259
  end
2258
2260
 
2259
2261
  it "should subsequently rejoin to a mixer" do
2260
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
2262
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
2261
2263
 
2262
2264
  dial.merge other_dial
2263
2265
 
@@ -2269,10 +2271,10 @@ module Adhearsion
2269
2271
  sleep 0.5
2270
2272
 
2271
2273
  other_mock_call << mock_end
2272
- latch.wait(2).should be_false
2274
+ expect(latch.wait(2)).to be_falsey
2273
2275
 
2274
2276
  [call, second_root_call, second_other_mock_call].each do |call|
2275
- call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do
2277
+ expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do
2276
2278
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
2277
2279
  end
2278
2280
  end
@@ -2280,7 +2282,7 @@ module Adhearsion
2280
2282
  dial.split
2281
2283
 
2282
2284
  [call, other_mock_call, second_root_call, second_other_mock_call].each do |call|
2283
- call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do
2285
+ expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do
2284
2286
  call << Punchblock::Event::Joined.new(mixer_name: mixer)
2285
2287
  end
2286
2288
  end
@@ -2290,7 +2292,7 @@ module Adhearsion
2290
2292
 
2291
2293
  context "if a call hangs up" do
2292
2294
  it "should still allow splitting and rejoining" do
2293
- [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true }
2295
+ [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true }
2294
2296
 
2295
2297
  dial.merge other_dial
2296
2298
 
@@ -2302,25 +2304,25 @@ module Adhearsion
2302
2304
  sleep 0.5
2303
2305
 
2304
2306
  [call, second_root_call, second_other_mock_call].each do |call|
2305
- call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do
2307
+ expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do
2306
2308
  call << Punchblock::Event::Unjoined.new(mixer_name: mixer)
2307
2309
  end
2308
2310
  end
2309
2311
 
2310
- other_mock_call.should_receive(:unjoin).and_raise Adhearsion::Call::Hangup
2312
+ expect(other_mock_call).to receive(:unjoin).and_raise Adhearsion::Call::Hangup
2311
2313
 
2312
2314
  dial.split
2313
2315
 
2314
2316
  other_mock_call << mock_end
2315
- latch.wait(2).should be_false
2317
+ expect(latch.wait(2)).to be_falsey
2316
2318
 
2317
2319
  [call, second_root_call, second_other_mock_call].each do |call|
2318
- call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do
2320
+ expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do
2319
2321
  call << Punchblock::Event::Joined.new(mixer_name: mixer)
2320
2322
  end
2321
2323
  end
2322
2324
 
2323
- other_mock_call.should_receive(:join).and_raise Adhearsion::Call::ExpiredError
2325
+ expect(other_mock_call).to receive(:join).and_raise Adhearsion::Call::ExpiredError
2324
2326
 
2325
2327
  dial.rejoin
2326
2328
  end
@@ -2328,14 +2330,14 @@ module Adhearsion
2328
2330
 
2329
2331
  context "if the calls were not joined" do
2330
2332
  it "should still join to mixer" do
2331
- other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
2332
- second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
2333
+ expect(other_mock_call).to receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
2334
+ expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable)
2333
2335
 
2334
- call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2335
- other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2336
+ expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2337
+ expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2336
2338
 
2337
- second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2338
- second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {})
2339
+ expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2340
+ expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {})
2339
2341
 
2340
2342
  dial.merge other_dial
2341
2343
 
@@ -2350,10 +2352,10 @@ module Adhearsion
2350
2352
  second_root_call.async << mock_end
2351
2353
  second_other_mock_call.async << mock_end
2352
2354
 
2353
- latch.wait(2).should be_true
2355
+ expect(latch.wait(2)).to be_truthy
2354
2356
 
2355
2357
  waiter_thread.join
2356
- dial.status.result.should be == :answer
2358
+ expect(dial.status.result).to eq(:answer)
2357
2359
  end
2358
2360
  end
2359
2361
  end
@@ -2370,7 +2372,7 @@ module Adhearsion
2370
2372
  end
2371
2373
 
2372
2374
  it "should not make any outbound calls" do
2373
- OutboundCall.should_receive(:new).never
2375
+ expect(OutboundCall).to receive(:new).never
2374
2376
  expect { subject.dial_and_confirm to, options }.to raise_error
2375
2377
  end
2376
2378
  end
@@ -2381,12 +2383,12 @@ module Adhearsion
2381
2383
  let(:second_other_options) { options }
2382
2384
 
2383
2385
  before do
2384
- OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call
2386
+ expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call
2385
2387
 
2386
- other_mock_call.should_receive(:dial).once.with(to, other_options)
2388
+ expect(other_mock_call).to receive(:dial).once.with(to, other_options)
2387
2389
 
2388
- second_other_mock_call.should_receive(:dial).once.with(second_to, second_other_options)
2389
- second_other_mock_call.should_receive(:join).never
2390
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, second_other_options)
2391
+ expect(second_other_mock_call).to receive(:join).never
2390
2392
  end
2391
2393
 
2392
2394
  def dial_in_thread
@@ -2398,50 +2400,50 @@ module Adhearsion
2398
2400
  end
2399
2401
 
2400
2402
  it "dials all parties and joins the first one to answer, hanging up the rest" do
2401
- call.should_receive(:answer).once
2402
- other_mock_call.should_receive(:join).once.with(call, {})
2403
- second_other_mock_call.should_receive(:hangup).once.and_return do
2403
+ expect(call).to receive(:answer).once
2404
+ expect(other_mock_call).to receive(:join).once.with(call, {})
2405
+ expect(second_other_mock_call).to receive(:hangup).once do
2404
2406
  second_other_mock_call << mock_end
2405
2407
  end
2406
2408
 
2407
2409
  t = dial_in_thread
2408
2410
 
2409
- latch.wait(2).should be_false
2411
+ expect(latch.wait(2)).to be_falsey
2410
2412
 
2411
2413
  other_mock_call << mock_answered
2412
2414
  other_mock_call << mock_end
2413
2415
 
2414
- latch.wait(2).should be_true
2416
+ expect(latch.wait(2)).to be_truthy
2415
2417
 
2416
2418
  t.join
2417
2419
  status = t.value
2418
- status.should be_a Dial::DialStatus
2419
- status.should have(2).calls
2420
- status.calls.each { |c| c.should be_a OutboundCall }
2420
+ expect(status).to be_a Dial::DialStatus
2421
+ expect(status.calls.size).to eq(2)
2422
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
2421
2423
  end
2422
2424
 
2423
2425
  it "unblocks when the joined call unjoins, allowing it to proceed further" do
2424
- call.should_receive(:answer).once
2425
- other_mock_call.should_receive(:join).once.with(call, {})
2426
- other_mock_call.should_receive(:hangup).once
2427
- second_other_mock_call.should_receive(:hangup).once.and_return do
2426
+ expect(call).to receive(:answer).once
2427
+ expect(other_mock_call).to receive(:join).once.with(call, {})
2428
+ expect(other_mock_call).to receive(:hangup).once
2429
+ expect(second_other_mock_call).to receive(:hangup).once do
2428
2430
  second_other_mock_call << mock_end
2429
2431
  end
2430
2432
 
2431
2433
  t = dial_in_thread
2432
2434
 
2433
- latch.wait(2).should be_false
2435
+ expect(latch.wait(2)).to be_falsey
2434
2436
 
2435
2437
  other_mock_call << mock_answered
2436
2438
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
2437
2439
 
2438
- latch.wait(2).should be_true
2440
+ expect(latch.wait(2)).to be_truthy
2439
2441
 
2440
2442
  t.join
2441
2443
  status = t.value
2442
- status.should be_a Dial::DialStatus
2443
- status.should have(2).calls
2444
- status.calls.each { |c| c.should be_a OutboundCall }
2444
+ expect(status).to be_a Dial::DialStatus
2445
+ expect(status.calls.size).to eq(2)
2446
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
2445
2447
  end
2446
2448
 
2447
2449
  describe "with options overrides" do
@@ -2505,11 +2507,11 @@ module Adhearsion
2505
2507
  latch.countdown!
2506
2508
  end
2507
2509
 
2508
- latch.wait(2).should be_false
2510
+ expect(latch.wait(2)).to be_falsey
2509
2511
  other_mock_call << mock_end
2510
- latch.wait(2).should be_false
2512
+ expect(latch.wait(2)).to be_falsey
2511
2513
  second_other_mock_call << mock_end
2512
- latch.wait(2).should be_true
2514
+ expect(latch.wait(2)).to be_truthy
2513
2515
  t.join
2514
2516
  end
2515
2517
  end
@@ -2523,19 +2525,19 @@ module Adhearsion
2523
2525
  other_mock_call << mock_end(:reject)
2524
2526
  second_other_mock_call << mock_end(:reject)
2525
2527
 
2526
- latch.wait(2).should be_true
2528
+ expect(latch.wait(2)).to be_truthy
2527
2529
 
2528
2530
  t.join
2529
2531
  status = t.value
2530
- status.result.should be == :no_answer
2532
+ expect(status.result).to eq(:no_answer)
2531
2533
  end
2532
2534
  end
2533
2535
 
2534
2536
  context "when a call is answered and joined, and the other ends with an error" do
2535
2537
  it "has an overall dial status of :answer" do
2536
- call.should_receive(:answer).once
2537
- other_mock_call.should_receive(:join).once.with(call, {})
2538
- second_other_mock_call.should_receive(:hangup).once.and_return do
2538
+ expect(call).to receive(:answer).once
2539
+ expect(other_mock_call).to receive(:join).once.with(call, {})
2540
+ expect(second_other_mock_call).to receive(:hangup).once do
2539
2541
  second_other_mock_call << mock_end(:error)
2540
2542
  end
2541
2543
 
@@ -2546,11 +2548,11 @@ module Adhearsion
2546
2548
  other_mock_call << mock_answered
2547
2549
  other_mock_call << mock_end
2548
2550
 
2549
- latch.wait(2).should be_true
2551
+ expect(latch.wait(2)).to be_truthy
2550
2552
 
2551
2553
  t.join
2552
2554
  status = t.value
2553
- status.result.should be == :answer
2555
+ expect(status.result).to eq(:answer)
2554
2556
  end
2555
2557
  end
2556
2558
  end
@@ -2559,9 +2561,9 @@ module Adhearsion
2559
2561
  let(:timeout) { 3 }
2560
2562
 
2561
2563
  it "should abort the dial after the specified timeout" do
2562
- other_mock_call.should_receive(:dial).once
2563
- other_mock_call.should_receive(:hangup).once
2564
- OutboundCall.should_receive(:new).and_return other_mock_call
2564
+ expect(other_mock_call).to receive(:dial).once
2565
+ expect(other_mock_call).to receive(:hangup).once
2566
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2565
2567
 
2566
2568
  time = Time.now
2567
2569
 
@@ -2573,18 +2575,18 @@ module Adhearsion
2573
2575
 
2574
2576
  latch.wait
2575
2577
  time = Time.now - time
2576
- time.round.should be == timeout
2578
+ expect(time.round).to eq(timeout)
2577
2579
  t.join
2578
2580
  status = t.value
2579
- status.result.should be == :timeout
2581
+ expect(status.result).to eq(:timeout)
2580
2582
  end
2581
2583
 
2582
2584
  describe "if someone answers before the timeout elapses" do
2583
2585
  it "should not abort until the far end hangs up" do
2584
- other_mock_call.should_receive(:dial).once.with(to, hash_including(:timeout => timeout))
2585
- call.should_receive(:answer).once
2586
- other_mock_call.should_receive(:join).once.with(call, {})
2587
- OutboundCall.should_receive(:new).and_return other_mock_call
2586
+ expect(other_mock_call).to receive(:dial).once.with(to, hash_including(:timeout => timeout))
2587
+ expect(call).to receive(:answer).once
2588
+ expect(other_mock_call).to receive(:join).once.with(call, {})
2589
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2588
2590
 
2589
2591
  time = Time.now
2590
2592
 
@@ -2594,20 +2596,20 @@ module Adhearsion
2594
2596
  status
2595
2597
  end
2596
2598
 
2597
- latch.wait(2).should be_false
2599
+ expect(latch.wait(2)).to be_falsey
2598
2600
 
2599
2601
  other_mock_call << mock_answered
2600
2602
 
2601
- latch.wait(2).should be_false
2603
+ expect(latch.wait(2)).to be_falsey
2602
2604
 
2603
2605
  other_mock_call << mock_end
2604
2606
 
2605
- latch.wait(0.1).should be_true
2607
+ expect(latch.wait(0.1)).to be_truthy
2606
2608
  time = Time.now - time
2607
- time.to_i.should be > timeout
2609
+ expect(time.to_i).to be > timeout
2608
2610
  t.join
2609
2611
  status = t.value
2610
- status.result.should be == :answer
2612
+ expect(status.result).to eq(:answer)
2611
2613
  end
2612
2614
  end
2613
2615
  end
@@ -2640,65 +2642,65 @@ module Adhearsion
2640
2642
  let(:options) { {:confirm => confirmation_controller, :confirm_metadata => {:foo => 'bar'}} }
2641
2643
 
2642
2644
  before do
2643
- other_mock_call.should_receive(:dial).once
2644
- OutboundCall.should_receive(:new).and_return other_mock_call
2645
+ expect(other_mock_call).to receive(:dial).once
2646
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2645
2647
  end
2646
2648
 
2647
2649
  it "should set the metadata on the controller" do
2648
- other_mock_call.should_receive(:hangup).once.and_return do
2650
+ expect(other_mock_call).to receive(:hangup).once do
2649
2651
  other_mock_call << mock_end
2650
2652
  end
2651
2653
  other_mock_call['confirm'] = false
2652
2654
 
2653
2655
  dial_in_thread
2654
2656
 
2655
- latch.wait(0.1).should be_false
2657
+ expect(latch.wait(0.1)).to be_falsey
2656
2658
 
2657
2659
  other_mock_call << mock_answered
2658
2660
 
2659
- confirmation_latch.wait(2).should be_true
2660
- latch.wait(2).should be_true
2661
+ expect(confirmation_latch.wait(2)).to be_truthy
2662
+ expect(latch.wait(2)).to be_truthy
2661
2663
 
2662
- other_mock_call[:foo].should == 'bar'
2664
+ expect(other_mock_call[:foo]).to eq('bar')
2663
2665
  end
2664
2666
  end
2665
2667
 
2666
2668
  context "when an outbound call is answered" do
2667
2669
  before do
2668
- other_mock_call.should_receive(:dial).once
2669
- OutboundCall.should_receive(:new).and_return other_mock_call
2670
+ expect(other_mock_call).to receive(:dial).once
2671
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2670
2672
  end
2671
2673
 
2672
2674
  it "should execute the specified confirmation controller" do
2673
- other_mock_call.should_receive(:hangup).once.and_return do
2675
+ expect(other_mock_call).to receive(:hangup).once do
2674
2676
  other_mock_call << mock_end
2675
2677
  end
2676
2678
  other_mock_call['confirm'] = false
2677
2679
 
2678
2680
  dial_in_thread
2679
2681
 
2680
- latch.wait(0.1).should be_false
2682
+ expect(latch.wait(0.1)).to be_falsey
2681
2683
 
2682
2684
  other_mock_call << mock_answered
2683
2685
 
2684
- confirmation_latch.wait(2).should be_true
2685
- latch.wait(2).should be_true
2686
+ expect(confirmation_latch.wait(2)).to be_truthy
2687
+ expect(latch.wait(2)).to be_truthy
2686
2688
  end
2687
2689
 
2688
2690
  it "should join the calls if the call is still active after execution of the call controller" do
2689
- other_mock_call.should_receive(:hangup).once.and_return do
2691
+ expect(other_mock_call).to receive(:hangup).once do
2690
2692
  other_mock_call << mock_end
2691
2693
  end
2692
2694
  other_mock_call['confirm'] = true
2693
- call.should_receive(:answer).once
2694
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
2695
+ expect(call).to receive(:answer).once
2696
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
2695
2697
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
2696
2698
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
2697
2699
  end
2698
2700
 
2699
2701
  t = dial_in_thread
2700
2702
 
2701
- latch.wait(2).should be_false
2703
+ expect(latch.wait(2)).to be_falsey
2702
2704
 
2703
2705
  base_time = Time.local(2008, 9, 1, 12, 0, 0)
2704
2706
  Timecop.freeze base_time
@@ -2709,40 +2711,40 @@ module Adhearsion
2709
2711
  Timecop.freeze base_time
2710
2712
  other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id)
2711
2713
 
2712
- latch.wait(2).should be_true
2714
+ expect(latch.wait(2)).to be_truthy
2713
2715
 
2714
2716
  t.join
2715
2717
  status = t.value
2716
- status.result.should be == :answer
2718
+ expect(status.result).to eq(:answer)
2717
2719
 
2718
2720
  joined_status = status.joins[status.calls.first]
2719
- joined_status.duration.should == 42.0
2720
- joined_status.result.should == :joined
2721
+ expect(joined_status.duration).to eq(42.0)
2722
+ expect(joined_status.result).to eq(:joined)
2721
2723
  end
2722
2724
 
2723
2725
  it "should not join the calls if the call is not active after execution of the call controller" do
2724
- other_mock_call.should_receive(:hangup).once.and_return do
2726
+ expect(other_mock_call).to receive(:hangup).once do
2725
2727
  other_mock_call << mock_end
2726
2728
  end
2727
2729
  other_mock_call['confirm'] = false
2728
- call.should_receive(:answer).never
2729
- other_mock_call.should_receive(:join).never.with(call)
2730
+ expect(call).to receive(:answer).never
2731
+ expect(other_mock_call).to receive(:join).never.with(call)
2730
2732
 
2731
2733
  t = dial_in_thread
2732
2734
 
2733
- latch.wait(2).should be_false
2735
+ expect(latch.wait(2)).to be_falsey
2734
2736
 
2735
2737
  other_mock_call << mock_answered
2736
2738
 
2737
- latch.wait(2).should be_true
2739
+ expect(latch.wait(2)).to be_truthy
2738
2740
 
2739
2741
  t.join
2740
2742
  status = t.value
2741
- status.result.should be == :unconfirmed
2743
+ expect(status.result).to eq(:unconfirmed)
2742
2744
 
2743
2745
  joined_status = status.joins[status.calls.first]
2744
- joined_status.duration.should == 0.0
2745
- joined_status.result.should == :unconfirmed
2746
+ expect(joined_status.duration).to eq(0.0)
2747
+ expect(joined_status.result).to eq(:unconfirmed)
2746
2748
  end
2747
2749
  end
2748
2750
 
@@ -2760,7 +2762,7 @@ module Adhearsion
2760
2762
  let(:options) { {confirm: confirmation_controller, confirm_metadata: {'foo' => 'bar'}, apology: apology_controller} }
2761
2763
 
2762
2764
  before do
2763
- OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call
2765
+ expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call
2764
2766
  end
2765
2767
 
2766
2768
  def dial_in_thread
@@ -2778,48 +2780,48 @@ module Adhearsion
2778
2780
  second_other_mock_call['confirm'] = true
2779
2781
  second_other_mock_call['confirmation_delay'] = 1.3
2780
2782
 
2781
- call.should_receive(:answer).once
2783
+ expect(call).to receive(:answer).once
2782
2784
 
2783
- other_mock_call.should_receive(:dial).once.with(to, from: nil)
2784
- other_mock_call.should_receive(:join).once.with(call, {}).and_return do
2785
+ expect(other_mock_call).to receive(:dial).once.with(to, from: nil)
2786
+ expect(other_mock_call).to receive(:join).once.with(call, {}) do
2785
2787
  call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id)
2786
2788
  other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id)
2787
2789
  end
2788
- other_mock_call.should_receive(:hangup).once.and_return do
2790
+ expect(other_mock_call).to receive(:hangup).once do
2789
2791
  other_mock_call.async.deliver_message mock_end
2790
2792
  end
2791
2793
 
2792
- second_other_mock_call.should_receive(:dial).once.with(second_to, from: nil)
2793
- second_other_mock_call.should_receive(:join).never
2794
- second_other_mock_call.should_receive(:hangup).once.and_return do
2794
+ expect(second_other_mock_call).to receive(:dial).once.with(second_to, from: nil)
2795
+ expect(second_other_mock_call).to receive(:join).never
2796
+ expect(second_other_mock_call).to receive(:hangup).once do
2795
2797
  second_other_mock_call.async.deliver_message mock_end
2796
2798
  end
2797
2799
 
2798
2800
  t = dial_in_thread
2799
2801
 
2800
- latch.wait(2).should be_false
2802
+ expect(latch.wait(2)).to be_falsey
2801
2803
 
2802
2804
  other_mock_call.async.deliver_message mock_answered
2803
2805
  second_other_mock_call.async.deliver_message mock_answered
2804
- confirmation_latch.wait(2).should be_true
2806
+ expect(confirmation_latch.wait(2)).to be_truthy
2805
2807
 
2806
2808
  sleep 2
2807
2809
 
2808
2810
  other_mock_call.async.deliver_message Punchblock::Event::Unjoined.new(call_uri: call.id)
2809
2811
 
2810
- latch.wait(2).should be_true
2812
+ expect(latch.wait(2)).to be_truthy
2811
2813
 
2812
- second_other_mock_call['apology_done'].should be_true
2813
- second_other_mock_call['apology_metadata'].should == {'foo' => 'bar'}
2814
+ expect(second_other_mock_call['apology_done']).to be_truthy
2815
+ expect(second_other_mock_call['apology_metadata']).to eq({'foo' => 'bar'})
2814
2816
 
2815
2817
  t.join
2816
2818
  status = t.value
2817
- status.should be_a Dial::DialStatus
2818
- status.should have(2).calls
2819
- status.calls.each { |c| c.should be_a OutboundCall }
2820
- status.result.should be == :answer
2821
- status.joins[other_mock_call].result.should == :joined
2822
- status.joins[second_other_mock_call].result.should == :lost_confirmation
2819
+ expect(status).to be_a Dial::DialStatus
2820
+ expect(status.calls.size).to eq(2)
2821
+ status.calls.each { |c| expect(c).to be_a OutboundCall }
2822
+ expect(status.result).to eq(:answer)
2823
+ expect(status.joins[other_mock_call].result).to eq(:joined)
2824
+ expect(status.joins[second_other_mock_call].result).to eq(:lost_confirmation)
2823
2825
  end
2824
2826
  end
2825
2827
  end
@@ -2831,7 +2833,7 @@ module Adhearsion
2831
2833
 
2832
2834
  describe "#prep_calls" do
2833
2835
  it "yields all calls to the passed block" do
2834
- OutboundCall.should_receive(:new).and_return other_mock_call
2836
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2835
2837
 
2836
2838
  gathered_calls = []
2837
2839
  subject.prep_calls { |call| gathered_calls << call }
@@ -2842,11 +2844,11 @@ module Adhearsion
2842
2844
 
2843
2845
  context "#skip_cleanup" do
2844
2846
  it "allows the new call to continue after the root call ends" do
2845
- OutboundCall.should_receive(:new).and_return other_mock_call
2847
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2846
2848
 
2847
- call.stub answer: true
2848
- other_mock_call.stub dial: true, join: true
2849
- other_mock_call.should_receive(:hangup).never
2849
+ allow(call).to receive_messages answer: true
2850
+ allow(other_mock_call).to receive_messages dial: true, join: true
2851
+ expect(other_mock_call).to receive(:hangup).never
2850
2852
 
2851
2853
  subject.run double('controller')
2852
2854
 
@@ -2861,7 +2863,37 @@ module Adhearsion
2861
2863
  other_mock_call << mock_answered
2862
2864
  call << mock_end
2863
2865
 
2864
- latch.wait(2).should be_true
2866
+ expect(latch.wait(2)).to be_truthy
2867
+ end
2868
+ end
2869
+
2870
+ describe "#cleanup_calls" do
2871
+ let(:dial) { Dial::Dial.new to, dial_options, call }
2872
+
2873
+ before do
2874
+ allow(other_mock_call).to receive_messages dial: true
2875
+ expect(OutboundCall).to receive(:new).and_return other_mock_call
2876
+ end
2877
+
2878
+ context "when a Cleanup Controller is specified" do
2879
+ let(:cleanup_controller) do
2880
+ Class.new(Adhearsion::CallController) do
2881
+ def run
2882
+ logger.info "Cleaning up..."
2883
+ end
2884
+ end
2885
+ end
2886
+ let(:dial_options) { {cleanup: cleanup_controller} }
2887
+
2888
+ it "invokes the Cleanup Controller on each active outbound call before terminating the call" do
2889
+ expect(cleanup_controller).to receive(:new).with(other_mock_call, anything)
2890
+ Thread.new do
2891
+ dial.run double(Adhearsion::CallController)
2892
+ dial.cleanup_calls
2893
+ latch.countdown!
2894
+ end
2895
+ expect(latch.wait(2)).to be_truthy
2896
+ end
2865
2897
  end
2866
2898
  end
2867
2899
  end