adhearsion 2.0.1 → 2.1.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 (62) hide show
  1. data/.travis.yml +4 -3
  2. data/CHANGELOG.md +30 -0
  3. data/README.markdown +1 -0
  4. data/adhearsion.gemspec +3 -4
  5. data/bin/ahn +0 -20
  6. data/features/cli_create.feature +1 -1
  7. data/features/cli_restart.feature +25 -1
  8. data/features/cli_start.feature +0 -2
  9. data/features/plugin_generator.feature +66 -15
  10. data/features/support/env.rb +0 -13
  11. data/lib/adhearsion.rb +26 -6
  12. data/lib/adhearsion/call.rb +42 -7
  13. data/lib/adhearsion/call_controller.rb +5 -2
  14. data/lib/adhearsion/call_controller/dial.rb +92 -50
  15. data/lib/adhearsion/call_controller/input.rb +19 -6
  16. data/lib/adhearsion/call_controller/menu_dsl/menu.rb +4 -0
  17. data/lib/adhearsion/call_controller/output.rb +143 -161
  18. data/lib/adhearsion/call_controller/output/abstract_player.rb +30 -0
  19. data/lib/adhearsion/call_controller/output/async_player.rb +26 -0
  20. data/lib/adhearsion/call_controller/output/formatter.rb +81 -0
  21. data/lib/adhearsion/call_controller/output/player.rb +25 -0
  22. data/lib/adhearsion/call_controller/record.rb +19 -2
  23. data/lib/adhearsion/events.rb +3 -0
  24. data/lib/adhearsion/foundation.rb +12 -6
  25. data/lib/adhearsion/foundation/exception_handler.rb +8 -6
  26. data/lib/adhearsion/generators/app/templates/README.md +13 -0
  27. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +7 -1
  28. data/lib/adhearsion/generators/plugin/plugin_generator.rb +1 -0
  29. data/lib/adhearsion/generators/plugin/templates/plugin-template.gemspec.tt +3 -7
  30. data/lib/adhearsion/generators/plugin/templates/spec/spec_helper.rb.tt +0 -1
  31. data/lib/adhearsion/outbound_call.rb +15 -5
  32. data/lib/adhearsion/punchblock_plugin.rb +13 -2
  33. data/lib/adhearsion/punchblock_plugin/initializer.rb +13 -12
  34. data/lib/adhearsion/router.rb +43 -2
  35. data/lib/adhearsion/router/evented_route.rb +15 -0
  36. data/lib/adhearsion/router/openended_route.rb +16 -0
  37. data/lib/adhearsion/router/route.rb +31 -13
  38. data/lib/adhearsion/router/unaccepting_route.rb +11 -0
  39. data/lib/adhearsion/version.rb +1 -1
  40. data/pre-commit +14 -1
  41. data/spec/adhearsion/call_controller/dial_spec.rb +105 -10
  42. data/spec/adhearsion/call_controller/input_spec.rb +19 -21
  43. data/spec/adhearsion/call_controller/output/async_player_spec.rb +67 -0
  44. data/spec/adhearsion/call_controller/output/formatter_spec.rb +90 -0
  45. data/spec/adhearsion/call_controller/output/player_spec.rb +65 -0
  46. data/spec/adhearsion/call_controller/output_spec.rb +436 -190
  47. data/spec/adhearsion/call_controller/record_spec.rb +49 -6
  48. data/spec/adhearsion/call_controller_spec.rb +10 -2
  49. data/spec/adhearsion/call_spec.rb +138 -0
  50. data/spec/adhearsion/calls_spec.rb +1 -1
  51. data/spec/adhearsion/outbound_call_spec.rb +48 -8
  52. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +34 -23
  53. data/spec/adhearsion/router/evented_route_spec.rb +34 -0
  54. data/spec/adhearsion/router/openended_route_spec.rb +61 -0
  55. data/spec/adhearsion/router/route_spec.rb +26 -4
  56. data/spec/adhearsion/router/unaccepting_route_spec.rb +72 -0
  57. data/spec/adhearsion/router_spec.rb +107 -2
  58. data/spec/adhearsion_spec.rb +19 -0
  59. data/spec/capture_warnings.rb +28 -21
  60. data/spec/spec_helper.rb +2 -3
  61. data/spec/support/call_controller_test_helpers.rb +31 -30
  62. metadata +32 -29
@@ -14,16 +14,17 @@ module Adhearsion
14
14
  :max_duration => 5000
15
15
  }
16
16
  end
17
- let(:component) { ::Punchblock::Component::Record.new options }
18
- let(:response) { ::Punchblock::Event::Complete.new }
17
+ let(:component) { Punchblock::Component::Record.new options }
18
+ let(:response) { Punchblock::Event::Complete.new }
19
19
 
20
20
  describe "with :async => true and an :on_complete callback" do
21
21
  before do
22
22
  component
23
- flexmock(::Punchblock::Component::Record).should_receive(:new).once.with(options).and_return component
23
+ flexmock(Punchblock::Component::Record).should_receive(:new).once.with(options).and_return component
24
24
  expect_message_waiting_for_response component
25
25
  @rec = Queue.new
26
26
  subject.record(options.merge(async: true)) { |rec| @rec.push rec }
27
+ component.request!
27
28
  component.execute!
28
29
  end
29
30
 
@@ -39,7 +40,7 @@ module Adhearsion
39
40
  before do
40
41
  TestException = Class.new StandardError
41
42
  component
42
- flexmock(::Punchblock::Component::Record).should_receive(:new).once.with({}).and_return component
43
+ flexmock(Punchblock::Component::Record).should_receive(:new).once.with({}).and_return component
43
44
  end
44
45
 
45
46
  it "should pass the exception to the events system" do
@@ -62,7 +63,7 @@ module Adhearsion
62
63
  describe "with :async => false" do
63
64
  before do
64
65
  component
65
- flexmock(::Punchblock::Component::Record).should_receive(:new).once.with(options).and_return component
66
+ flexmock(Punchblock::Component::Record).should_receive(:new).once.with(options).and_return component
66
67
  expect_component_execution component
67
68
  @rec = Queue.new
68
69
  subject.record(options.merge(:async => false)) { |rec| @rec.push rec }
@@ -77,8 +78,50 @@ module Adhearsion
77
78
  end
78
79
  end
79
80
  end
80
- end
81
81
 
82
+ describe "with :interruptible => false" do
83
+ let(:input_component) { Punchblock::Component::Input.new }
84
+ it "does not use an Input component" do
85
+ subject.should_receive(:execute_component_and_await_completion).once.with(component)
86
+ subject.should_receive(:write_and_await_response).never.with(input_component)
87
+ subject.record(options.merge(:async => false, :interruptible => false)) { |rec| @rec.push rec }
88
+ end
89
+ end
90
+
91
+ describe "with :interruptible => true" do
92
+ let(:input_component) { Punchblock::Component::Input.new }
93
+ it "stops the recording" do
94
+ flexmock(Punchblock::Event::Complete).new_instances.should_receive(:reason => flexmock(:name => :input))
95
+
96
+ def subject.write_and_await_response(input_component)
97
+ input_component.trigger_event_handler Punchblock::Event::Complete.new
98
+ end
99
+
100
+ complete_event = Punchblock::Event::Complete.new
101
+ flexmock(complete_event).should_receive(:reason => flexmock(:name => :input))
102
+ flexmock(Punchblock::Component::Input).new_instances do |input|
103
+ input.should_receive(:complete?).and_return(false)
104
+ input.should_receive(:complete_event).and_return(complete_event)
105
+ end
106
+ flexmock(Punchblock::Component::Record).new_instances.should_receive(:stop!)
107
+ subject.should_receive(:execute_component_and_await_completion).once.with(component)
108
+ subject.record(options.merge(:async => false, :interruptible => true)) { |rec| @rec.push rec }
109
+ end
110
+
111
+ end
112
+
113
+ describe "check for the return value" do
114
+ it "returns a Record component" do
115
+ component
116
+ flexmock(Punchblock::Component::Record).should_receive(:new).once.with(options).and_return component
117
+ expect_component_execution component
118
+ subject.record(options.merge(:async => false)).should be == component
119
+ component.request!
120
+ component.execute!
121
+ end
122
+ end
123
+
124
+ end
82
125
  end
83
126
  end
84
127
  end
@@ -201,7 +201,6 @@ module Adhearsion
201
201
 
202
202
  [ :answer,
203
203
  :reject,
204
- :hangup,
205
204
  :mute,
206
205
  :unmute].each do |method_name|
207
206
  describe "##{method_name}" do
@@ -213,6 +212,14 @@ module Adhearsion
213
212
  end
214
213
  end
215
214
 
215
+ describe "#hangup" do
216
+ it "delegates to the call, blocking first until it is allowed to execute" do
217
+ flexmock(subject).should_receive(:block_until_resumed).once.ordered
218
+ flexmock(subject.call).should_receive(:hangup).once.ordered
219
+ lambda { subject.send :hangup }.should raise_error Call::Hangup
220
+ end
221
+ end
222
+
216
223
  describe "#join" do
217
224
  it "delegates to the call, blocking first until it is allowed to execute, and unblocking when an unjoined event is received" do
218
225
  flexmock(subject).should_receive(:block_until_resumed).once.ordered
@@ -318,6 +325,7 @@ module Adhearsion
318
325
 
319
326
  before do
320
327
  expect_message_of_type_waiting_for_response component
328
+ component.request!
321
329
  component.execute!
322
330
  component.complete_event = response
323
331
  end
@@ -417,7 +425,7 @@ describe ExampleCallController do
417
425
  it "should execute the after_call callbacks after the call is hung up" do
418
426
  subject.should_receive(:join_to_conference).once.ordered
419
427
  subject.should_receive(:clean_up_models).twice.ordered
420
- subject.should_receive(:foobar).once.ordered
428
+ subject.should_receive(:foobar).never
421
429
  subject.execute!
422
430
  end
423
431
 
@@ -110,6 +110,132 @@ module Adhearsion
110
110
  describe "event handlers" do
111
111
  let(:response) { flexmock 'Response' }
112
112
 
113
+ describe "for joined events" do
114
+ context "joined to another call" do
115
+ let :event do
116
+ Punchblock::Event::Joined.new :call_id => 'foobar'
117
+ end
118
+
119
+ it "should trigger any on_joined callbacks set for the matching call ID" do
120
+ response.should_receive(:call).once.with(event)
121
+ subject.on_joined(:call_id => 'foobar') { |event| response.call event }
122
+ subject << event
123
+ end
124
+
125
+ it "should not trigger on_joined callbacks for other call IDs" do
126
+ response.should_receive(:call).never
127
+ subject.on_joined(:call_id => 'barfoo') { |event| response.call event }
128
+ subject << event
129
+ end
130
+
131
+ it "should not trigger on_joined callbacks for mixers" do
132
+ response.should_receive(:call).never
133
+ subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
134
+ subject << event
135
+ end
136
+ end
137
+
138
+ context "joined to a mixer" do
139
+ let :event do
140
+ Punchblock::Event::Joined.new :mixer_name => 'foobar'
141
+ end
142
+
143
+ it "should trigger on_joined callbacks for the matching mixer name" do
144
+ response.should_receive(:call).once.with(event)
145
+ subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
146
+ subject << event
147
+ end
148
+
149
+ it "should not trigger on_joined callbacks for other mixer names" do
150
+ response.should_receive(:call).never
151
+ subject.on_joined(:mixer_name => 'barfoo') { |event| response.call event }
152
+ subject << event
153
+ end
154
+
155
+ it "should not trigger any on_joined callbacks set for calls" do
156
+ response.should_receive(:call).never
157
+ subject.on_joined(:call_id => 'foobar') { |event| response.call event }
158
+ subject << event
159
+ end
160
+ end
161
+ end
162
+
163
+ describe "for unjoined events" do
164
+ context "unjoined from another call" do
165
+ let :event do
166
+ Punchblock::Event::Unjoined.new :call_id => 'foobar'
167
+ end
168
+
169
+ it "should trigger any on_unjoined callbacks set for the matching call ID" do
170
+ response.should_receive(:call).once.with(event)
171
+ subject.on_unjoined(:call_id => 'foobar') { |event| response.call event }
172
+ subject << event
173
+ end
174
+
175
+ it "should trigger any on_unjoined callbacks set for the matching call ID as a string" do
176
+ response.should_receive(:call).once.with(event)
177
+ subject.on_unjoined('foobar') { |event| response.call event }
178
+ subject << event
179
+ end
180
+
181
+ it "should trigger any on_unjoined callbacks set for the matching call" do
182
+ response.should_receive(:call).once.with(event)
183
+ call = flexmock Call.new, :id => 'foobar'
184
+ subject.on_unjoined(call) { |event| response.call event }
185
+ subject << event
186
+ end
187
+
188
+ it "should not trigger on_unjoined callbacks for other call IDs" do
189
+ response.should_receive(:call).never
190
+ subject.on_unjoined(:call_id => 'barfoo') { |event| response.call event }
191
+ subject << event
192
+ end
193
+
194
+ it "should not trigger on_unjoined callbacks for mixers" do
195
+ response.should_receive(:call).never
196
+ subject.on_joined(:mixer_name => 'foobar') { |event| response.call event }
197
+ subject << event
198
+ end
199
+ end
200
+
201
+ context "unjoined from a mixer" do
202
+ let :event do
203
+ Punchblock::Event::Unjoined.new :mixer_name => 'foobar'
204
+ end
205
+
206
+ it "should trigger on_unjoined callbacks for the matching mixer name" do
207
+ response.should_receive(:call).once.with(event)
208
+ subject.on_unjoined(:mixer_name => 'foobar') { |event| response.call event }
209
+ subject << event
210
+ end
211
+
212
+ it "should not trigger on_unjoined callbacks for other mixer names" do
213
+ response.should_receive(:call).never
214
+ subject.on_unjoined(:mixer_name => 'barfoo') { |event| response.call event }
215
+ subject << event
216
+ end
217
+
218
+ it "should not trigger any on_unjoined callbacks set for calls" do
219
+ response.should_receive(:call).never
220
+ subject.on_unjoined(:call_id => 'foobar') { |event| response.call event }
221
+ subject << event
222
+ end
223
+
224
+ it "should not trigger any on_unjoined callbacks set for the matching call ID as a string" do
225
+ response.should_receive(:call).never
226
+ subject.on_unjoined('foobar') { |event| response.call event }
227
+ subject << event
228
+ end
229
+
230
+ it "should not trigger any on_unjoined callbacks set for the matching call" do
231
+ response.should_receive(:call).never
232
+ call = flexmock Call.new, :id => 'foobar'
233
+ subject.on_unjoined(call) { |event| response.call event }
234
+ subject << event
235
+ end
236
+ end
237
+ end
238
+
113
239
  describe "for end events" do
114
240
  let :event do
115
241
  Punchblock::Event::End.new.tap do |e|
@@ -621,6 +747,18 @@ module Adhearsion
621
747
  latch.wait(3).should be_true
622
748
  end
623
749
 
750
+ it "should use the passed block as a controller if none is specified" do
751
+ flexmock(CallController).should_receive(:exec).once.with CallController
752
+ subject.execute_controller nil, lambda { |call| latch.countdown! } do
753
+ foo
754
+ end
755
+ latch.wait(3).should be_true
756
+ end
757
+
758
+ it "should raise ArgumentError if both a controller and a block are passed" do
759
+ lambda { subject.execute_controller(mock_controller) { foo } }.should raise_error(ArgumentError)
760
+ end
761
+
624
762
  it "should add the controller thread to the important threads" do
625
763
  flexmock(CallController).should_receive(:exec)
626
764
  controller_thread = subject.execute_controller mock_controller, lambda { |call| latch.countdown! }
@@ -46,7 +46,7 @@ module Adhearsion
46
46
  context "by dead call object" do
47
47
  before do
48
48
  @call_id = deleted_call.id
49
- deleted_call.terminate
49
+ deleted_call.kill
50
50
  deleted_call.should_not be_alive
51
51
  subject.remove_inactive_call deleted_call
52
52
  end
@@ -22,24 +22,56 @@ module Adhearsion
22
22
 
23
23
  let(:mock_call) { OutboundCall.new }
24
24
 
25
- it "should dial the call to the correct endpoint and return it" do
25
+ before do
26
26
  mock_call
27
27
  flexmock(OutboundCall).should_receive(:new).and_return mock_call
28
+ end
29
+
30
+ it "should dial the call to the correct endpoint and return it" do
28
31
  flexmock(mock_call.wrapped_object).should_receive(:dial).with(to, :from => 'foo').once
29
32
  OutboundCall.originate(to, :from => 'foo').should be mock_call
30
33
  end
31
34
 
32
35
  it "should run through the router when the call is answered" do
33
- mock_call
34
-
35
- flexmock(OutboundCall).should_receive(:new).and_return mock_call
36
36
  flexmock(mock_call.wrapped_object).should_receive(:dial).once
37
37
 
38
- mock_dispatcher = flexmock 'dispatcher'
39
- mock_dispatcher.should_receive(:call).once.with mock_call
40
- flexmock(Adhearsion.router).should_receive(:handle).once.with(mock_call).and_return mock_dispatcher
38
+ flexmock(Adhearsion.router).should_receive(:handle).once.with(mock_call)
41
39
 
42
- OutboundCall.originate(to).deliver_message Punchblock::Event::Answered.new
40
+ OutboundCall.originate(to) << Punchblock::Event::Answered.new
41
+ end
42
+
43
+ context "when a controller class is specified for the call" do
44
+ let(:controller) { CallController }
45
+
46
+ it "should execute the controller on the call when it is answered" do
47
+ flexmock(mock_call).should_receive(:dial).once.with(to, {})
48
+ flexmock(mock_call).should_receive(:execute_controller).once.with controller, Proc
49
+ call = OutboundCall.originate to, :controller => controller
50
+ call << Punchblock::Event::Answered.new
51
+ end
52
+
53
+ it "should hangup the call after all controllers have executed" do
54
+ flexmock(mock_call).should_receive(:dial).once
55
+ flexmock(mock_call).should_receive(:hangup).once
56
+
57
+ call = OutboundCall.originate to, :controller => controller
58
+ call << Punchblock::Event::Answered.new
59
+ sleep 0.5
60
+ end
61
+ end
62
+
63
+ context "when given a block" do
64
+ it "should execute the block as a controller on the call when it is answered" do
65
+ flexmock(mock_call).should_receive(:dial).once.with(to, {})
66
+ flexmock(mock_call).should_receive(:execute_controller).once.with(CallController, Proc).and_return do |controller|
67
+ controller.block.call.should be == :foobar
68
+ end
69
+
70
+ call = OutboundCall.originate to do
71
+ :foobar
72
+ end
73
+ call << Punchblock::Event::Answered.new
74
+ end
43
75
  end
44
76
  end
45
77
 
@@ -104,6 +136,14 @@ module Adhearsion
104
136
  subject.dial to, :from => from
105
137
  Adhearsion.active_calls[call_id].should be subject
106
138
  end
139
+
140
+ it "should not modify the provided options" do
141
+ options = {:from => from}
142
+ original_options = Marshal.load(Marshal.dump(options))
143
+ options.should be == original_options
144
+ subject.dial to, options
145
+ options.should be == original_options
146
+ end
107
147
  end
108
148
 
109
149
  describe "basic control commands" do
@@ -20,6 +20,7 @@ module Adhearsion
20
20
  config.reconnect_attempts = 1.0/0.0
21
21
  config.reconnect_timer = 5
22
22
  config.media_engine = nil
23
+ config.default_voice = nil
23
24
  end
24
25
  end
25
26
 
@@ -39,6 +40,7 @@ module Adhearsion
39
40
  config.reconnect_attempts = options[:reconnect_attempts] if options.has_key?(:reconnect_attempts)
40
41
  config.reconnect_timer = options[:reconnect_timer] if options.has_key?(:reconnect_timer)
41
42
  config.media_engine = options[:media_engine] if options.has_key?(:media_engine)
43
+ config.default_voice = options[:default_voice] if options.has_key?(:default_voice)
42
44
  end
43
45
 
44
46
  Initializer.init
@@ -52,7 +54,7 @@ module Adhearsion
52
54
  end
53
55
 
54
56
  let(:call_id) { rand }
55
- let(:offer) { ::Punchblock::Event::Offer.new.tap { |o| o.target_call_id = call_id } }
57
+ let(:offer) { Punchblock::Event::Offer.new.tap { |o| o.target_call_id = call_id } }
56
58
  let(:mock_call) { flexmock('Call', :id => call_id).tap { |call| call.should_ignore_missing } }
57
59
 
58
60
  describe "starts the client with the default values" do
@@ -97,21 +99,25 @@ module Adhearsion
97
99
  it "should properly set the media_engine value" do
98
100
  subject.media_engine.should be == nil
99
101
  end
102
+
103
+ it "should properly set the default_voice value" do
104
+ subject.default_voice.should be == nil
105
+ end
100
106
  end
101
107
 
102
108
  it "starts the client with the correct resource" do
103
109
  username = "usera@127.0.0.1/hostname-1234"
104
110
 
105
- flexmock(::Punchblock::Connection::XMPP).should_receive(:new).once.with(FlexMock.hsh :username => username).and_return do
111
+ flexmock(Punchblock::Connection::XMPP).should_receive(:new).once.with(FlexMock.hsh :username => username).and_return do
106
112
  flexmock 'Client', :event_handler= => true
107
113
  end
108
114
  initialize_punchblock
109
115
  end
110
116
 
111
117
  it "starts the client with any overridden settings" do
112
- overrides = {:username => 'userb@127.0.0.1/foo', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift}
118
+ overrides = {:username => 'userb@127.0.0.1/foo', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal}
113
119
 
114
- flexmock(::Punchblock::Connection::XMPP).should_receive(:new).once.with(overrides).and_return do
120
+ flexmock(Punchblock::Connection::XMPP).should_receive(:new).once.with(overrides).and_return do
115
121
  flexmock 'Client', :event_handler= => true
116
122
  end
117
123
  initialize_punchblock overrides
@@ -122,12 +128,12 @@ module Adhearsion
122
128
  reset_default_config
123
129
  mock_connection = flexmock :mock_connection
124
130
  mock_connection.should_receive(:register_event_handler).once
125
- flexmock(::Punchblock::Client).should_receive(:new).once.and_return mock_connection
131
+ flexmock(Punchblock::Client).should_receive(:new).once.and_return mock_connection
126
132
  flexmock(mock_connection).should_receive(:run).once
127
133
  t = Thread.new { Initializer.init; Initializer.run }
128
134
  t.join 5
129
135
  t.status.should be == "sleep"
130
- Events.trigger_immediately :punchblock, ::Punchblock::Connection::Connected.new
136
+ Events.trigger_immediately :punchblock, Punchblock::Connection::Connected.new
131
137
  t.join
132
138
  end
133
139
  end
@@ -150,42 +156,53 @@ module Adhearsion
150
156
  it 'should reset the Adhearsion process state to "booting"' do
151
157
  Adhearsion::Process.booted
152
158
  Adhearsion::Process.state_name.should be == :running
153
- mock_client.should_receive(:run).and_raise ::Punchblock::DisconnectedError
159
+ mock_client.should_receive(:run).and_raise Punchblock::DisconnectedError
154
160
  flexmock(Adhearsion::Process).should_receive(:reset).at_least.once
155
161
  Initializer.connect_to_server
156
162
  end
157
163
 
158
164
  it 'should retry the connection the specified number of times' do
159
165
  Initializer.config.reconnect_attempts = 3
160
- mock_client.should_receive(:run).and_raise ::Punchblock::DisconnectedError
166
+ mock_client.should_receive(:run).and_raise Punchblock::DisconnectedError
161
167
  Initializer.connect_to_server
162
168
  Initializer.attempts.should be == 3
163
169
  end
164
170
 
165
171
  it 'should preserve a Punchblock::ProtocolError exception and give up' do
166
- mock_client.should_receive(:run).and_raise ::Punchblock::ProtocolError
167
- expect { Initializer.connect_to_server }.should raise_error ::Punchblock::ProtocolError
172
+ mock_client.should_receive(:run).and_raise Punchblock::ProtocolError
173
+ expect { Initializer.connect_to_server }.to raise_error Punchblock::ProtocolError
168
174
  end
169
175
 
170
176
  it 'should not attempt to reconnect if Adhearsion is shutting down' do
171
177
  Adhearsion::Process.booted
172
178
  Adhearsion::Process.shutdown
173
- mock_client.should_receive(:run).and_raise ::Punchblock::DisconnectedError
174
- Initializer.should_not raise_error ::Punchblock::DisconnectedError
179
+ mock_client.should_receive(:run).and_raise Punchblock::DisconnectedError
180
+ Initializer.should_not raise_error Punchblock::DisconnectedError
175
181
  end
176
182
  end
177
183
 
178
184
  describe 'using Asterisk' do
179
- let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift} }
185
+ let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }
180
186
 
181
187
  it 'should start an Asterisk PB connection' do
182
- flexmock(::Punchblock::Connection::Asterisk).should_receive(:new).once.with(overrides).and_return do
188
+ flexmock(Punchblock::Connection::Asterisk).should_receive(:new).once.with(overrides).and_return do
183
189
  flexmock 'Client', :event_handler= => true
184
190
  end
185
191
  initialize_punchblock overrides.merge(:platform => :asterisk)
186
192
  end
187
193
  end
188
194
 
195
+ describe 'using FreeSWITCH' do
196
+ let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }
197
+
198
+ it 'should start an Asterisk PB connection' do
199
+ flexmock(Punchblock::Connection::Freeswitch).should_receive(:new).once.with(overrides).and_return do
200
+ flexmock 'Client', :event_handler= => true
201
+ end
202
+ initialize_punchblock overrides.merge(:platform => :freeswitch)
203
+ end
204
+ end
205
+
189
206
  it 'should place events from Punchblock into the event handler' do
190
207
  flexmock(Events.instance).should_receive(:trigger).once.with(:punchblock, offer)
191
208
  initialize_punchblock
@@ -210,17 +227,11 @@ module Adhearsion
210
227
  context "when when Adhearsion::Process is in :running" do
211
228
  let(:process_state) { :running }
212
229
 
213
- it "should accept the call" do
214
- mock_call.should_receive(:accept).once
215
- end
216
-
217
- it "should execute the dispatcher provided by the router" do
218
- controller = Class.new
230
+ it "should dispatch via the router" do
219
231
  Adhearsion.router do
220
- route 'foobar', controller
232
+ route 'foobar', Class.new
221
233
  end
222
- first_route = Adhearsion.router.routes.first
223
- flexmock(first_route.dispatcher).should_receive(:call).once.with mock_call
234
+ flexmock(Adhearsion.router).should_receive(:handle).once.with mock_call
224
235
  end
225
236
  end
226
237