spec/punchblock/translator/asterisk/call_spec.rb in punchblock-0.8.0 vs spec/punchblock/translator/asterisk/call_spec.rb in punchblock-0.8.1

- old
+ new

@@ -128,10 +128,32 @@ it 'should send the event to the component' do component.expects(:handle_ami_event!).once.with ami_event subject.process_ami_event ami_event end end + + context 'with a handler registered for a matching event' do + let :ami_event do + RubyAMI::Event.new('DTMF').tap do |e| + e['Digit'] = '4' + e['Start'] = 'Yes' + e['End'] = 'No' + e['Uniqueid'] = "1320842458.8" + e['Channel'] = "SIP/1234-00000000" + end + end + + let(:response) { mock 'Response' } + + it 'should execute the handler' do + response.expects(:call).once.with ami_event + subject.register_handler :ami, :name => 'DTMF' do |event| + response.call event + end + subject.process_ami_event ami_event + end + end end describe '#execute_command' do let :expected_agi_complete_event do Punchblock::Event::Complete.new.tap do |c| @@ -204,9 +226,23 @@ let(:mock_action) { mock 'Component::Asterisk::Output', :id => 'foo' } it 'should create an AGI command component actor and execute it asynchronously' do Component::Asterisk::Output.expects(:new).once.with(command, subject).returns mock_action + mock_action.expects(:execute!).once + subject.execute_command command + end + end + + context 'with an Input component' do + let :command do + Punchblock::Component::Input.new + end + + let(:mock_action) { mock 'Component::Asterisk::Input', :id => 'foo' } + + it 'should create an AGI command component actor and execute it asynchronously' do + Component::Asterisk::Input.expects(:new).once.with(command, subject).returns mock_action mock_action.expects(:execute!).once subject.execute_command command end end