spec/punchblock/translator/asterisk_spec.rb in punchblock-1.6.1 vs spec/punchblock/translator/asterisk_spec.rb in punchblock-1.7.0
- old
+ new
@@ -30,11 +30,11 @@
end
describe '#shutdown' do
it "instructs all calls to shutdown" do
call = Asterisk::Call.new 'foo', subject
- call.expects(:shutdown!).once
+ call.should_receive(:shutdown!).once
subject.register_call call
subject.shutdown
end
it "terminates the actor" do
@@ -48,11 +48,11 @@
describe 'with a call command' do
let(:command) { Command::Answer.new }
let(:call_id) { 'abc123' }
it 'executes the call command' do
- subject.wrapped_object.expects(:execute_call_command).with do |c|
+ subject.wrapped_object.should_receive(:execute_call_command).with do |c|
c.should be command
c.target_call_id.should be == call_id
end
subject.execute_command command, :call_id => call_id
end
@@ -61,11 +61,11 @@
describe 'with a global component command' do
let(:command) { Component::Stop.new }
let(:component_id) { '123abc' }
it 'executes the component command' do
- subject.wrapped_object.expects(:execute_component_command).with do |c|
+ subject.wrapped_object.should_receive(:execute_component_command).with do |c|
c.should be command
c.component_id.should be == component_id
end
subject.execute_command command, :component_id => component_id
end
@@ -73,11 +73,11 @@
describe 'with a global command' do
let(:command) { Command::Dial.new }
it 'executes the command directly' do
- subject.wrapped_object.expects(:execute_global_command).with command
+ subject.wrapped_object.should_receive(:execute_global_command).with command
subject.execute_command command
end
end
end
@@ -85,11 +85,11 @@
let(:call_id) { 'abc123' }
let(:channel) { 'SIP/foo' }
let(:call) { Translator::Asterisk::Call.new channel, subject }
before do
- call.stubs(:id).returns call_id
+ call.stub(:id).and_return call_id
subject.register_call call
end
it 'should make the call accessible by ID' do
subject.call_with_id(call_id).should be call
@@ -104,11 +104,11 @@
let(:call_id) { 'abc123' }
let(:channel) { 'SIP/foo' }
let(:call) { Translator::Asterisk::Call.new channel, subject }
before do
- call.stubs(:id).returns call_id
+ call.stub(:id).and_return call_id
subject.register_call call
end
it 'should make the call inaccessible by ID' do
subject.call_with_id(call_id).should be call
@@ -140,16 +140,16 @@
context "with a known call ID" do
let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject }
before do
command.request!
- call.stubs(:id).returns call_id
+ call.stub(:id).and_return call_id
subject.register_call call
end
it 'sends the command to the call for execution' do
- call.expects(:execute_command!).once.with command
+ call.should_receive(:execute_command!).once.with command
subject.execute_call_command command
end
end
let :end_error_event do
@@ -164,21 +164,21 @@
let(:call_id) { dial_command.response.id }
before do
subject.execute_command dial_command
- ami_client.stub_everything
+ ami_client.as_null_object
end
it 'sends an error in response to the command' do
call = subject.call_with_id call_id
call.wrapped_object.define_singleton_method(:oops) do
raise 'Woops, I died'
end
- connection.expects(:handle_event).once.with end_error_event
+ connection.should_receive(:handle_event).once.with end_error_event
lambda { call.oops }.should raise_error(/Woops, I died/)
sleep 0.1
call.should_not be_alive
subject.call_with_id(call_id).should be_nil
@@ -200,21 +200,21 @@
let(:call) { subject.call_for_channel('SIP/1234-00000000') }
let(:call_id) { call.id }
before do
- connection.expects(:handle_event).at_least(1)
+ connection.stub :handle_event
subject.handle_ami_event ami_event
call_id
end
it 'sends an error in response to the command' do
call.wrapped_object.define_singleton_method(:oops) do
raise 'Woops, I died'
end
- connection.expects(:handle_event).once.with end_error_event
+ connection.should_receive(:handle_event).once.with end_error_event
lambda { call.oops }.should raise_error(/Woops, I died/)
sleep 0.1
call.should_not be_alive
subject.call_with_id(call_id).should be_nil
@@ -248,11 +248,11 @@
before do
subject.register_component component
end
it 'sends the command to the component for execution' do
- component.expects(:execute_command!).once.with command
+ component.should_receive(:execute_command!).once.with command
subject.execute_component_command command
end
end
context "with an unknown component ID" do
@@ -269,43 +269,43 @@
Command::Dial.new :to => 'SIP/1234', :from => 'abc123'
end
before do
command.request!
- ami_client.stub_everything
+ ami_client.as_null_object
end
it 'should be able to look up the call by channel ID' do
subject.execute_global_command command
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_everything 'Asterisk::Call'
- Asterisk::Call.expects(:new_link).once.returns mock_call
- mock_call.expects(:dial!).once.with command
+ mock_call = stub('Asterisk::Call').as_null_object
+ Asterisk::Call.should_receive(:new_link).once.and_return mock_call
+ mock_call.should_receive(:dial!).once.with command
subject.execute_global_command command
end
end
context 'with an AMI action' do
let :command do
Component::Asterisk::AMI::Action.new :name => 'Status', :params => { :channel => 'foo' }
end
- let(:mock_action) { stub_everything 'Asterisk::Component::Asterisk::AMIAction' }
+ let(:mock_action) { stub('Asterisk::Component::Asterisk::AMIAction').as_null_object }
it 'should create a component actor and execute it asynchronously' do
- Asterisk::Component::Asterisk::AMIAction.expects(:new).once.with(command, subject).returns mock_action
- mock_action.expects(:execute!).once
+ Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
+ mock_action.should_receive(:execute!).once
subject.execute_global_command command
end
it 'registers the component' do
- Asterisk::Component::Asterisk::AMIAction.expects(:new).once.with(command, subject).returns mock_action
- subject.wrapped_object.expects(:register_component).with mock_action
+ Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
+ subject.wrapped_object.should_receive(:register_component).with mock_action
subject.execute_global_command command
end
end
context "with a command we don't understand" do
@@ -321,11 +321,11 @@
end
describe '#handle_pb_event' do
it 'should forward the event to the connection' do
event = mock 'Punchblock::Event'
- subject.connection.expects(:handle_event).once.with event
+ subject.connection.should_receive(:handle_event).once.with event
subject.handle_pb_event event
end
end
describe '#handle_ami_event' do
@@ -345,35 +345,35 @@
:callerid => "101",
:uniqueid => "1094154427.10"}
end
it 'should create a Punchblock AMI event object and pass it to the connection' do
- subject.connection.expects(:handle_event).once.with expected_pb_event
+ subject.connection.should_receive(:handle_event).once.with expected_pb_event
subject.handle_ami_event ami_event
end
context 'with something that is not a RubyAMI::Event' do
it 'does not send anything to the connection' do
- subject.connection.expects(:handle_event).never
+ subject.connection.should_receive(:handle_event).never
subject.handle_ami_event :foo
end
end
describe 'with a FullyBooted event' do
let(:ami_event) { RubyAMI::Event.new 'FullyBooted' }
context 'once' do
it 'does not send anything to the connection' do
- subject.connection.expects(:handle_event).never
+ subject.connection.should_receive(:handle_event).never
subject.handle_ami_event ami_event
end
end
context 'twice' do
it 'sends a connected event to the event handler' do
- subject.connection.expects(:handle_event).once.with Connection::Connected.new
- subject.wrapped_object.expects(:run_at_fully_booted).once
+ subject.connection.should_receive(:handle_event).once.with Connection::Connected.new
+ subject.wrapped_object.should_receive(:run_at_fully_booted).once
subject.handle_ami_event ami_event
subject.handle_ami_event ami_event
end
end
end
@@ -385,11 +385,11 @@
e['Channel'] = "SIP/1234-00000000"
e['Env'] = "agi_request%3A%20async%0Aagi_channel%3A%20SIP%2F1234-00000000%0Aagi_language%3A%20en%0Aagi_type%3A%20SIP%0Aagi_uniqueid%3A%201320835995.0%0Aagi_version%3A%201.8.4.1%0Aagi_callerid%3A%205678%0Aagi_calleridname%3A%20Jane%20Smith%0Aagi_callingpres%3A%200%0Aagi_callingani2%3A%200%0Aagi_callington%3A%200%0Aagi_callingtns%3A%200%0Aagi_dnid%3A%201000%0Aagi_rdnis%3A%20unknown%0Aagi_context%3A%20default%0Aagi_extension%3A%201000%0Aagi_priority%3A%201%0Aagi_enhanced%3A%200.0%0Aagi_accountcode%3A%20%0Aagi_threadid%3A%204366221312%0A%0A"
end
end
- before { subject.wrapped_object.stubs :handle_pb_event }
+ before { subject.wrapped_object.stub :handle_pb_event }
it 'should be able to look up the call by channel ID' do
subject.handle_ami_event ami_event
call_actor = subject.call_for_channel('SIP/1234-00000000')
call_actor.should be_a Asterisk::Call
@@ -417,14 +417,14 @@
:agi_threadid => '4366221312'
}
end
it 'should instruct the call to send an offer' do
- mock_call = stub_everything 'Asterisk::Call'
- Asterisk::Call.expects(:new).once.returns mock_call
- subject.wrapped_object.expects(:link)
- mock_call.expects(:send_offer!).once
+ 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.should_receive(:send_offer!).once
subject.handle_ami_event ami_event
end
context 'if a call already exists for a matching channel' do
let(:call) { Asterisk::Call.new "SIP/1234-00000000", subject }
@@ -432,11 +432,11 @@
before do
subject.register_call call
end
it "should not create a new call" do
- Asterisk::Call.expects(:new).never
+ Asterisk::Call.should_receive(:new).never
subject.handle_ami_event ami_event
end
end
context "for a 'h' extension" do
@@ -447,11 +447,11 @@
e['Env'] = "agi_extension%3A%20h%0A%0A"
end
end
it "should not create a new call" do
- Asterisk::Call.expects(:new).never
+ Asterisk::Call.should_receive(:new).never
subject.handle_ami_event ami_event
end
it 'should not be able to look up the call by channel ID' do
subject.handle_ami_event ami_event
@@ -467,11 +467,11 @@
e['Env'] = "agi_type%3A%20Kill%0A%0A"
end
end
it "should not create a new call" do
- Asterisk::Call.expects(:new).never
+ Asterisk::Call.should_receive(:new).never
subject.handle_ami_event ami_event
end
it 'should not be able to look up the call by channel ID' do
subject.handle_ami_event ami_event
@@ -490,12 +490,12 @@
e["Uniqueid"] = "1326210224.0"
end
end
before do
- ami_client.stub_everything
- subject.wrapped_object.stubs :handle_pb_event
+ ami_client.as_null_object
+ subject.wrapped_object.stub :handle_pb_event
end
context "matching a call that was created by a Dial command" do
let(:dial_command) { Punchblock::Command::Dial.new :to => 'SIP/1234', :from => 'abc123' }
@@ -552,11 +552,11 @@
before do
subject.register_call call
end
it 'sends the AMI event to the call and to the connection as a PB event' do
- call.expects(:process_ami_event!).once.with ami_event
+ call.should_receive(:process_ami_event!).once.with ami_event
subject.handle_ami_event ami_event
end
context 'with a Channel1 and Channel2 specified on the event' do
let :ami_event do
@@ -574,12 +574,12 @@
end
before { subject.register_call call2 }
it 'should send the event to both calls and to the connection once as a PB event' do
- call.expects(:process_ami_event!).once.with ami_event
- call2.expects(:process_ami_event!).once.with ami_event
+ call.should_receive(:process_ami_event!).once.with ami_event
+ call2.should_receive(:process_ami_event!).once.with ami_event
subject.handle_ami_event ami_event
end
end
end
end
@@ -610,25 +610,25 @@
before do
subject.register_call call
end
it 'sends the AMI event to the call and to the connection as a PB event if it is an allowed event' do
- call.expects(:process_ami_event!).once.with ami_event
+ call.should_receive(:process_ami_event!).once.with ami_event
subject.handle_ami_event ami_event
end
it 'does not send the AMI event to a bridged channel if it is not allowed' do
- call.expects(:process_ami_event!).never.with ami_event2
+ call.should_receive(:process_ami_event!).never.with ami_event2
subject.handle_ami_event ami_event2
end
end
end#handle_ami_event
describe '#send_ami_action' do
it 'should send the action to the AMI client' do
- ami_client.expects(:send_action).once.with 'foo', :foo => :bar
+ ami_client.should_receive(:send_action).once.with 'foo', :foo => :bar
subject.send_ami_action 'foo', :foo => :bar
end
end
describe '#run_at_fully_booted' do
@@ -639,42 +639,42 @@
let(:failed_show) do
OpenStruct.new({:text_body => "There is no existence of 'adhearsion-redirect' context\nCommand 'dialplan show adhearsion-redirect' failed."})
end
it 'should send the redirect extension Command to the AMI client' do
- ami_client.expects(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
- ami_client.expects(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}")
+ ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
+ ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}")
subject.run_at_fully_booted
end
it 'should check the context for existence and do nothing if it is there' do
- ami_client.expects(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
- ami_client.expects(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").yields(passed_show)
+ ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
+ ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_yield(passed_show)
subject.run_at_fully_booted
end
it 'should check the context for existence and log an error if it is not there' do
- ami_client.expects(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
- ami_client.expects(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").yields(failed_show)
- Punchblock.logger.expects(:error).once.with("Punchblock failed to add the #{Asterisk::REDIRECT_EXTENSION} extension to the #{Asterisk::REDIRECT_CONTEXT} context. Please add a [#{Asterisk::REDIRECT_CONTEXT}] entry to your dialplan.")
+ ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
+ ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_yield(failed_show)
+ Punchblock.logger.should_receive(:error).once.with("Punchblock failed to add the #{Asterisk::REDIRECT_EXTENSION} extension to the #{Asterisk::REDIRECT_CONTEXT} context. Please add a [#{Asterisk::REDIRECT_CONTEXT}] entry to your dialplan.")
subject.run_at_fully_booted
end
end
-
+
describe '#check_recording_directory' do
let(:broken_path) { "/this/is/not/a/valid/path" }
before do
@new_constant = broken_path
- @old_constant = Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH
- Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
+ @old_constant = Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH
+ Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @new_constant)
end
after do
Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @old_constant)
end
it 'logs a warning if the recording directory does not exist' do
- Punchblock.logger.expects(:warning).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
+ Punchblock.logger.should_receive(:warning).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
subject.check_recording_directory
end
end
end
end