spec/punchblock/translator/asterisk_spec.rb in punchblock-1.9.4 vs spec/punchblock/translator/asterisk_spec.rb in punchblock-2.0.0.beta1
- old
+ new
@@ -4,12 +4,12 @@
require 'ostruct'
module Punchblock
module Translator
describe Asterisk do
- let(:ami_client) { mock 'RubyAMI::Client' }
- let(:connection) { mock 'Connection::Asterisk', handle_event: nil }
+ let(:ami_client) { double 'RubyAMI::Client' }
+ let(:connection) { double 'Connection::Asterisk', handle_event: nil }
let(:media_engine) { :asterisk }
let(:translator) { Asterisk.new ami_client, connection, media_engine }
subject { translator }
@@ -110,34 +110,34 @@
subject.register_call call
end
it 'should make the call inaccessible by ID' do
subject.call_with_id(call_id).should be call
- subject.deregister_call call
+ subject.deregister_call call_id, channel
subject.call_with_id(call_id).should be_nil
end
it 'should make the call inaccessible by channel' do
subject.call_for_channel(channel).should be call
- subject.deregister_call call
+ subject.deregister_call call_id, channel
subject.call_for_channel(channel).should be_nil
end
end
describe '#register_component' do
let(:component_id) { 'abc123' }
- let(:component) { mock 'Asterisk::Component::Asterisk::AMIAction', :id => component_id }
+ let(:component) { double 'Asterisk::Component::Asterisk::AMIAction', :id => component_id }
it 'should make the component accessible by ID' do
subject.register_component component
subject.component_with_id(component_id).should be component
end
end
describe '#execute_call_command' do
let(:call_id) { 'abc123' }
- let(:command) { Command::Answer.new.tap { |c| c.target_call_id = call_id } }
+ let(:command) { Command::Answer.new target_call_id: call_id }
context "with a known call ID" do
let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject, ami_client, connection }
before do
@@ -151,20 +151,17 @@
subject.execute_call_command command
end
end
let :end_error_event do
- Punchblock::Event::End.new.tap do |e|
- e.target_call_id = call_id
- e.reason = :error
- end
+ Punchblock::Event::End.new reason: :error, target_call_id: call_id
end
context "for an outgoing call which began executing but crashed" do
let(:dial_command) { Command::Dial.new :to => 'SIP/1234', :from => 'abc123' }
- let(:call_id) { dial_command.response.id }
+ let(:call_id) { dial_command.response.call_id }
before do
subject.async.should_receive(:execute_global_command)
subject.execute_command dial_command
end
@@ -236,11 +233,11 @@
describe '#execute_component_command' do
let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject, ami_client, connection }
let(:component_node) { Component::Output.new }
let(:component) { Translator::Asterisk::Component::Output.new(component_node, call) }
- let(:command) { Component::Stop.new.tap { |c| c.component_id = component.id } }
+ let(:command) { Component::Stop.new component_id: component.id }
before do
command.request!
end
@@ -279,11 +276,11 @@
call_actor = subject.call_for_channel('SIP/1234')
call_actor.wrapped_object.should be_a Asterisk::Call
end
it 'should instruct the call to send a dial' do
- mock_call = stub('Asterisk::Call').as_null_object
+ mock_call = double('Asterisk::Call').as_null_object
Asterisk::Call.should_receive(:new_link).once.and_return mock_call
mock_call.async.should_receive(:dial).once.with command
subject.execute_global_command command
end
end
@@ -291,11 +288,11 @@
context 'with an AMI action' do
let :command do
Component::Asterisk::AMI::Action.new :name => 'Status', :params => { :channel => 'foo' }
end
- let(:mock_action) { stub('Asterisk::Component::Asterisk::AMIAction').as_null_object }
+ let(:mock_action) { double('Asterisk::Component::Asterisk::AMIAction').as_null_object }
it 'should create a component actor and execute it asynchronously' do
Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject, ami_client).and_return mock_action
mock_action.async.should_receive(:execute).once
subject.execute_global_command command
@@ -320,11 +317,11 @@
end
end
describe '#handle_pb_event' do
it 'should forward the event to the connection' do
- event = mock 'Punchblock::Event'
+ event = double 'Punchblock::Event'
subject.connection.should_receive(:handle_event).once.with event
subject.handle_pb_event event
end
end
@@ -336,15 +333,15 @@
'Callerid' => "101",
'Uniqueid' => "1094154427.10"
end
let :expected_pb_event do
- Event::Asterisk::AMI::Event.new :name => 'Newchannel',
- :attributes => { :channel => "SIP/101-3f3f",
- :state => "Ring",
- :callerid => "101",
- :uniqueid => "1094154427.10"}
+ Event::Asterisk::AMI::Event.new name: 'Newchannel',
+ headers: { 'Channel' => "SIP/101-3f3f",
+ 'State' => "Ring",
+ 'Callerid' => "101",
+ 'Uniqueid' => "1094154427.10"}
end
it 'should create a Punchblock AMI event object and pass it to the connection' do
subject.connection.should_receive(:handle_event).once.with expected_pb_event
subject.handle_ami_event ami_event
@@ -405,13 +402,12 @@
:agi_threadid => '4366221312'
}
end
it 'should instruct the call to send an offer' do
- mock_call = stub('Asterisk::Call').as_null_object
- Asterisk::Call.should_receive(:new).once.and_return mock_call
- subject.wrapped_object.should_receive(:link)
+ mock_call = double('Asterisk::Call').as_null_object
+ Asterisk::Call.should_receive(:new_link).once.and_return mock_call
mock_call.async.should_receive(:send_offer).once
subject.handle_ami_event ami_event
end
context 'if a call already exists for a matching channel' do
@@ -420,10 +416,10 @@
before do
subject.register_call call
end
it "should not create a new call" do
- Asterisk::Call.should_receive(:new).never
+ Asterisk::Call.should_receive(:new_link).never
subject.handle_ami_event ami_event
end
end
context "for a 'h' extension" do