punchblock 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/Guardfile +1 -1
  3. data/Rakefile +1 -1
  4. data/lib/punchblock/client.rb +5 -8
  5. data/lib/punchblock/client/component_registry.rb +8 -1
  6. data/lib/punchblock/component/component_node.rb +1 -0
  7. data/lib/punchblock/component/output.rb +15 -1
  8. data/lib/punchblock/translator/asterisk.rb +1 -1
  9. data/lib/punchblock/translator/asterisk/call.rb +1 -1
  10. data/lib/punchblock/translator/asterisk/component/output.rb +5 -1
  11. data/lib/punchblock/translator/freeswitch.rb +7 -1
  12. data/lib/punchblock/translator/freeswitch/call.rb +10 -6
  13. data/lib/punchblock/translator/freeswitch/component.rb +1 -1
  14. data/lib/punchblock/version.rb +1 -1
  15. data/punchblock.gemspec +1 -2
  16. data/spec/punchblock/client/component_registry_spec.rb +7 -0
  17. data/spec/punchblock/client_spec.rb +14 -12
  18. data/spec/punchblock/command_node_spec.rb +2 -2
  19. data/spec/punchblock/component/component_node_spec.rb +10 -3
  20. data/spec/punchblock/component/input_spec.rb +1 -1
  21. data/spec/punchblock/component/output_spec.rb +32 -27
  22. data/spec/punchblock/component/record_spec.rb +5 -5
  23. data/spec/punchblock/connection/asterisk_spec.rb +7 -7
  24. data/spec/punchblock/connection/freeswitch_spec.rb +8 -8
  25. data/spec/punchblock/connection/xmpp_spec.rb +9 -9
  26. data/spec/punchblock/translator/asterisk/call_spec.rb +65 -65
  27. data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +17 -20
  28. data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +13 -16
  29. data/spec/punchblock/translator/asterisk/component/input_spec.rb +9 -12
  30. data/spec/punchblock/translator/asterisk/component/output_spec.rb +62 -29
  31. data/spec/punchblock/translator/asterisk/component/record_spec.rb +38 -42
  32. data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +2 -2
  33. data/spec/punchblock/translator/asterisk/component_spec.rb +5 -5
  34. data/spec/punchblock/translator/asterisk_spec.rb +55 -55
  35. data/spec/punchblock/translator/freeswitch/call_spec.rb +80 -54
  36. data/spec/punchblock/translator/freeswitch/component/flite_output_spec.rb +7 -10
  37. data/spec/punchblock/translator/freeswitch/component/input_spec.rb +8 -10
  38. data/spec/punchblock/translator/freeswitch/component/output_spec.rb +9 -12
  39. data/spec/punchblock/translator/freeswitch/component/record_spec.rb +31 -34
  40. data/spec/punchblock/translator/freeswitch/component/tts_output_spec.rb +7 -10
  41. data/spec/punchblock/translator/freeswitch/component_spec.rb +6 -6
  42. data/spec/punchblock/translator/freeswitch_spec.rb +27 -27
  43. data/spec/punchblock_spec.rb +5 -6
  44. data/spec/spec_helper.rb +2 -3
  45. data/spec/support/mock_connection_with_event_handler.rb +8 -19
  46. metadata +5 -21
@@ -12,7 +12,7 @@ module Punchblock
12
12
  let(:translator) { described_class.new connection, media_engine, default_voice }
13
13
  let(:stream) { mock 'RubyFS::Stream' }
14
14
 
15
- before { connection.expects(:stream).times(0..1).returns stream }
15
+ before { connection.should_receive(:stream).at_most(:once).and_return stream }
16
16
 
17
17
  subject { translator }
18
18
 
@@ -34,7 +34,7 @@ module Punchblock
34
34
  let(:call_id) { 'abc123' }
35
35
 
36
36
  it 'executes the call command' do
37
- subject.wrapped_object.expects(:execute_call_command).with do |c|
37
+ subject.wrapped_object.should_receive(:execute_call_command).with do |c|
38
38
  c.should be command
39
39
  c.target_call_id.should be == call_id
40
40
  end
@@ -47,7 +47,7 @@ module Punchblock
47
47
  let(:component_id) { '123abc' }
48
48
 
49
49
  it 'executes the component command' do
50
- subject.wrapped_object.expects(:execute_component_command).with do |c|
50
+ subject.wrapped_object.should_receive(:execute_component_command).with do |c|
51
51
  c.should be command
52
52
  c.component_id.should be == component_id
53
53
  end
@@ -59,7 +59,7 @@ module Punchblock
59
59
  let(:command) { Command::Dial.new }
60
60
 
61
61
  it 'executes the command directly' do
62
- subject.wrapped_object.expects(:execute_global_command).with command
62
+ subject.wrapped_object.should_receive(:execute_global_command).with command
63
63
  subject.execute_command command
64
64
  end
65
65
  end
@@ -112,12 +112,12 @@ module Punchblock
112
112
 
113
113
  before do
114
114
  command.request!
115
- call.stubs(:id).returns call_id
115
+ call.stub(:id).and_return call_id
116
116
  subject.register_call call
117
117
  end
118
118
 
119
119
  it 'sends the command to the call for execution' do
120
- call.expects(:execute_command!).once.with command
120
+ call.should_receive(:execute_command!).once.with command
121
121
  subject.execute_call_command command
122
122
  end
123
123
  end
@@ -135,7 +135,7 @@ module Punchblock
135
135
  let(:call_id) { dial_command.response.id }
136
136
 
137
137
  before do
138
- stream.stub_everything
138
+ stream.as_null_object
139
139
  subject.execute_command dial_command
140
140
  end
141
141
 
@@ -146,7 +146,7 @@ module Punchblock
146
146
  raise 'Woops, I died'
147
147
  end
148
148
 
149
- connection.expects(:handle_event).once.with end_error_event
149
+ connection.should_receive(:handle_event).once.with end_error_event
150
150
 
151
151
  lambda { call.oops }.should raise_error(/Woops, I died/)
152
152
  sleep 0.1
@@ -168,7 +168,7 @@ module Punchblock
168
168
  let(:call_id) { call.id }
169
169
 
170
170
  before do
171
- connection.expects(:handle_event).at_least(1)
171
+ connection.stub :handle_event
172
172
  subject.handle_es_event es_event
173
173
  call_id
174
174
  end
@@ -178,7 +178,7 @@ module Punchblock
178
178
  raise 'Woops, I died'
179
179
  end
180
180
 
181
- connection.expects(:handle_event).once.with end_error_event
181
+ connection.should_receive(:handle_event).once.with end_error_event
182
182
 
183
183
  lambda { call.oops }.should raise_error(/Woops, I died/)
184
184
  sleep 0.1
@@ -216,7 +216,7 @@ module Punchblock
216
216
  end
217
217
 
218
218
  it 'sends the command to the component for execution' do
219
- component.expects(:execute_command!).once.with command
219
+ component.should_receive(:execute_command!).once.with command
220
220
  subject.execute_component_command command
221
221
  end
222
222
  end
@@ -239,9 +239,9 @@ module Punchblock
239
239
 
240
240
  before do
241
241
  id
242
- Punchblock.expects(:new_uuid).once.returns id
242
+ Punchblock.should_receive(:new_uuid).once.and_return id
243
243
  command.request!
244
- stream.stub_everything
244
+ stream.as_null_object
245
245
  end
246
246
 
247
247
  it 'should be able to look up the call by ID' do
@@ -255,9 +255,9 @@ module Punchblock
255
255
  end
256
256
 
257
257
  it 'should instruct the call to send a dial' do
258
- mock_call = stub_everything 'Freeswitch::Call'
259
- Freeswitch::Call.expects(:new_link).once.returns mock_call
260
- mock_call.expects(:dial!).once.with command
258
+ mock_call = stub('Freeswitch::Call').as_null_object
259
+ Freeswitch::Call.should_receive(:new_link).once.and_return mock_call
260
+ mock_call.should_receive(:dial!).once.with command
261
261
  subject.execute_global_command command
262
262
  end
263
263
  end
@@ -277,13 +277,13 @@ module Punchblock
277
277
  describe '#handle_pb_event' do
278
278
  it 'should forward the event to the connection' do
279
279
  event = mock 'Punchblock::Event'
280
- subject.connection.expects(:handle_event).once.with event
280
+ subject.connection.should_receive(:handle_event).once.with event
281
281
  subject.handle_pb_event event
282
282
  end
283
283
  end
284
284
 
285
285
  describe '#handle_es_event' do
286
- before { subject.wrapped_object.stubs :handle_pb_event }
286
+ before { subject.wrapped_object.stub :handle_pb_event }
287
287
 
288
288
  let(:unique_id) { "3f0e1e18-c056-11e1-b099-fffeda3ce54f" }
289
289
 
@@ -514,7 +514,7 @@ module Punchblock
514
514
  let(:es_event) { RubyFS::Stream::Connected.new }
515
515
 
516
516
  it "should send a Punchblock::Connection::Connected event" do
517
- subject.wrapped_object.expects(:handle_pb_event).once.with(Punchblock::Connection::Connected.new)
517
+ subject.wrapped_object.should_receive(:handle_pb_event).once.with(Punchblock::Connection::Connected.new)
518
518
  subject.handle_es_event es_event
519
519
  end
520
520
  end
@@ -529,10 +529,10 @@ module Punchblock
529
529
 
530
530
  describe 'with a CHANNEL_PARK event' do
531
531
  it 'should instruct the call to send an offer' do
532
- mock_call = stub_everything 'Freeswitch::Call'
533
- Freeswitch::Call.expects(:new).once.returns mock_call
534
- subject.wrapped_object.expects(:link)
535
- mock_call.expects(:send_offer!).once
532
+ mock_call = stub('Freeswitch::Call').as_null_object
533
+ Freeswitch::Call.should_receive(:new).once.and_return mock_call
534
+ subject.wrapped_object.should_receive(:link)
535
+ mock_call.should_receive(:send_offer!).once
536
536
  subject.handle_es_event es_event
537
537
  end
538
538
 
@@ -544,7 +544,7 @@ module Punchblock
544
544
  end
545
545
 
546
546
  it "should not create a new call" do
547
- Freeswitch::Call.expects(:new).never
547
+ Freeswitch::Call.should_receive(:new).never
548
548
  subject.handle_es_event es_event
549
549
  end
550
550
  end
@@ -567,12 +567,12 @@ module Punchblock
567
567
  end
568
568
 
569
569
  it "is delivered to the bridging leg" do
570
- call_a.expects(:handle_es_event!).once.with es_event
570
+ call_a.should_receive(:handle_es_event!).once.with es_event
571
571
  subject.handle_es_event es_event
572
572
  end
573
573
 
574
574
  it "is delivered to the other leg" do
575
- call_b.expects(:handle_es_event!).once.with es_event
575
+ call_b.should_receive(:handle_es_event!).once.with es_event
576
576
  subject.handle_es_event es_event
577
577
  end
578
578
  end
@@ -587,7 +587,7 @@ module Punchblock
587
587
  end
588
588
 
589
589
  it 'sends the ES event to the call' do
590
- call.expects(:handle_es_event!).once.with es_event
590
+ call.should_receive(:handle_es_event!).once.with es_event
591
591
  subject.handle_es_event es_event
592
592
  end
593
593
  end
@@ -2,11 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Punchblock do
4
4
  describe '#client_with_connection' do
5
+ let(:mock_connection) { stub('Connection').as_null_object }
6
+
5
7
  context 'with :XMPP' do
6
8
  it 'sets up an XMPP connection, passing options, and a client with the connection attached' do
7
- mock_connection = stub_everything 'Connection'
8
9
  options = {:username => 'foo', :password => 'bar'}
9
- Punchblock::Connection::XMPP.expects(:new).once.with(options).returns mock_connection
10
+ Punchblock::Connection::XMPP.should_receive(:new).once.with(options).and_return mock_connection
10
11
  client = Punchblock.client_with_connection :XMPP, options
11
12
  client.should be_a Punchblock::Client
12
13
  client.connection.should be mock_connection
@@ -15,9 +16,8 @@ describe Punchblock do
15
16
 
16
17
  context 'with :asterisk' do
17
18
  it 'sets up an Asterisk connection, passing options, and a client with the connection attached' do
18
- mock_connection = stub_everything 'Connection'
19
19
  options = {:username => 'foo', :password => 'bar'}
20
- Punchblock::Connection::Asterisk.expects(:new).once.with(options).returns mock_connection
20
+ Punchblock::Connection::Asterisk.should_receive(:new).once.with(options).and_return mock_connection
21
21
  client = Punchblock.client_with_connection :asterisk, options
22
22
  client.should be_a Punchblock::Client
23
23
  client.connection.should be mock_connection
@@ -26,9 +26,8 @@ describe Punchblock do
26
26
 
27
27
  context 'with :freeswitch' do
28
28
  it 'sets up an Freeswitch connection, passing options, and a client with the connection attached' do
29
- mock_connection = stub_everything 'Connection'
30
29
  options = {:username => 'foo', :password => 'bar'}
31
- Punchblock::Connection::Freeswitch.expects(:new).once.with(options).returns mock_connection
30
+ Punchblock::Connection::Freeswitch.should_receive(:new).once.with(options).and_return mock_connection
32
31
  client = Punchblock.client_with_connection :freeswitch, options
33
32
  client.should be_a Punchblock::Client
34
33
  client.connection.should be mock_connection
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,6 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
9
9
  Thread.abort_on_exception = true
10
10
 
11
11
  RSpec.configure do |config|
12
- config.mock_with :mocha
13
12
  config.filter_run :focus => true
14
13
  config.run_all_when_everything_filtered = true
15
14
 
@@ -32,8 +31,8 @@ def import_stanza(xml)
32
31
  end
33
32
 
34
33
  def stub_uuids(value)
35
- RubyAMI.stubs :new_uuid => value
36
- Punchblock.stubs :new_uuid => value
34
+ RubyAMI.stub :new_uuid => value
35
+ Punchblock.stub :new_uuid => value
37
36
  end
38
37
 
39
38
  # FIXME: change this to rayo_event? It can be ambigous
@@ -1,24 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- # This is a nasty hack due to the fact that Mocha does not support expectations returning a value calculated by executing a block with the parameters passed.
4
- # If it did, we could do this in our component tests:
5
- # mc = mock 'Connection'
6
- # mc.stubs(:handle_event).returns { |event| command.add_event event }
7
- #
8
- # Mocha does not support this feature because really, it's a smell in the tests
9
- # We shouldn't really be mocking out behaviour like this if we actually need it to have side effects
10
- # We only do this because of the difficulties in synchronising the tests with an asynchronous target in another thread.
11
- #
12
- def mock_connection_with_event_handler(&block)
13
- mock('Connection').tap do |mc|
14
- class << mc
15
- attr_accessor :target
16
- end
17
-
18
- mc.target = block
19
-
20
- def mc.handle_event(event)
21
- target.call event
3
+ module HasMockCallbackConnection
4
+ def self.included(test_case)
5
+ test_case.let(:connection) do
6
+ mock('Connection').tap do |mc|
7
+ mc.stub :handle_event do |event|
8
+ original_command.add_event event
9
+ end
10
+ end
22
11
  end
23
12
  end
24
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punchblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-14 00:00:00.000000000 Z
14
+ date: 2012-12-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: niceogiri
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: '1.3'
103
+ version: '1.5'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ dependencies:
108
108
  requirements:
109
109
  - - ~>
110
110
  - !ruby/object:Gem::Version
111
- version: '1.3'
111
+ version: '1.5'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: celluloid
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -265,22 +265,6 @@ dependencies:
265
265
  - - ! '>='
266
266
  - !ruby/object:Gem::Version
267
267
  version: '0'
268
- - !ruby/object:Gem::Dependency
269
- name: mocha
270
- requirement: !ruby/object:Gem::Requirement
271
- none: false
272
- requirements:
273
- - - ! '>='
274
- - !ruby/object:Gem::Version
275
- version: '0'
276
- type: :development
277
- prerelease: false
278
- version_requirements: !ruby/object:Gem::Requirement
279
- none: false
280
- requirements:
281
- - - ! '>='
282
- - !ruby/object:Gem::Version
283
- version: '0'
284
268
  - !ruby/object:Gem::Dependency
285
269
  name: i18n
286
270
  requirement: !ruby/object:Gem::Requirement
@@ -515,7 +499,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
515
499
  version: '0'
516
500
  segments:
517
501
  - 0
518
- hash: -2449922662339076716
502
+ hash: -475080832801704872
519
503
  required_rubygems_version: !ruby/object:Gem::Requirement
520
504
  none: false
521
505
  requirements: