spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-0.9.2 vs spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-0.10.0

- old
+ new

@@ -1,5 +1,7 @@ +# encoding: utf-8 + require 'spec_helper' module Punchblock module Translator class Asterisk @@ -38,10 +40,101 @@ subject.execute end before { mock_call.stubs :answer_if_not_answered } + context 'with a media engine of :swift' do + let(:media_engine) { :swift } + + let(:audio_filename) { 'http://foo.com/bar.mp3' } + + let :ssml_doc do + RubySpeech::SSML.draw do + audio :src => audio_filename + say_as(:interpret_as => :cardinal) { 'FOO' } + end + end + + let(:command_opts) { {} } + + let :command_options do + { :ssml => ssml_doc }.merge(command_opts) + end + + def ssml_with_options(prefix = '', postfix = '') + base_doc = ssml_doc.to_s.squish.gsub(/["\\]/) { |m| "\\#{m}" } + prefix + base_doc + postfix + end + + it "should execute Swift" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options + subject.execute + end + + it 'should send a complete event when Swift completes' do + def mock_call.send_agi_action!(*args, &block) + block.call Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new(:code => 200, :result => 1) + end + subject.execute + command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Success + end + + describe 'interrupt_on' do + context "set to nil" do + let(:command_opts) { { :interrupt_on => nil } } + it "should not add interrupt arguments" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options + subject.execute + end + end + + context "set to :any" do + let(:command_opts) { { :interrupt_on => :any } } + it "should add the interrupt options to the argument" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options('', '|1|1') + subject.execute + end + end + + context "set to :dtmf" do + let(:command_opts) { { :interrupt_on => :dtmf } } + it "should add the interrupt options to the argument" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options('', '|1|1') + subject.execute + end + end + + context "set to :speech" do + let(:command_opts) { { :interrupt_on => :speech } } + it "should return an error and not execute any actions" do + subject.execute + error = ProtocolError.new 'option error', 'An interrupt-on value of speech is unsupported.' + command.response(0.1).should be == error + end + end + end + + describe 'voice' do + context "set to nil" do + let(:command_opts) { { :voice => nil } } + it "should not add a voice at the beginning of the argument" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options + subject.execute + end + end + + context "set to Leonard" do + let(:command_opts) { { :voice => "Leonard" } } + it "should add a voice at the beginning of the argument" do + mock_call.expects(:send_agi_action!).once.with 'EXEC Swift', ssml_with_options('Leonard^', '') + subject.execute + end + end + + end + end + context 'with a media engine of :unimrcp' do let(:media_engine) { :unimrcp } let(:audio_filename) { 'http://foo.com/bar.mp3' } @@ -58,11 +151,11 @@ { :ssml => ssml_doc }.merge(command_opts) end def expect_mrcpsynth_with_options(options) mock_call.expects(:send_agi_action!).once.with do |*args| - args[0].should == 'EXEC MRCPSynth' + args[0].should be == 'EXEC MRCPSynth' args[2].should match options end end it "should execute MRCPSynth" do @@ -82,11 +175,11 @@ context 'unset' do let(:command_opts) { { :ssml => nil } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'An SSML document is required.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'start-offset' do @@ -101,11 +194,11 @@ context 'set' do let(:command_opts) { { :start_offset => 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A start_offset value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'start-paused' do @@ -120,11 +213,11 @@ context 'true' do let(:command_opts) { { :start_paused => true } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A start_paused value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'repeat-interval' do @@ -139,11 +232,11 @@ context 'set' do let(:command_opts) { { :repeat_interval => 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A repeat_interval value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'repeat-times' do @@ -158,11 +251,11 @@ context 'set' do let(:command_opts) { { :repeat_times => 2 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A repeat_times value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'max-time' do @@ -177,11 +270,11 @@ context 'set' do let(:command_opts) { { :max_time => 30 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A max_time value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'voice' do @@ -230,22 +323,22 @@ context "set to :speech" do let(:command_opts) { { :interrupt_on => :speech } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'An interrupt-on value of speech is unsupported.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end end context 'with a media engine of :asterisk' do let(:media_engine) { :asterisk } def expect_stream_file_with_options(options = nil) mock_call.expects(:send_agi_action!).once.with 'STREAM FILE', audio_filename, options do |*args| - args[2].should == options + args[2].should be == options subject.continue! true end end @@ -271,11 +364,11 @@ context 'unset' do let(:command_opts) { { :ssml => nil } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'An SSML document is required.' - command.response(0.1).should == error + command.response(0.1).should be == error end end context 'with a single audio SSML node' do let(:audio_filename) { 'http://foo.com/bar.mp3' } @@ -313,16 +406,14 @@ it 'should playback each audio file using STREAM FILE' do latch = CountDownLatch.new 2 mock_call.expects(:send_agi_action!).once.with 'STREAM FILE', audio_filename1, nil do subject.continue - true latch.countdown! end mock_call.expects(:send_agi_action!).once.with 'STREAM FILE', audio_filename2, nil do subject.continue - true latch.countdown! end subject.execute latch.wait 2 sleep 2 @@ -349,11 +440,11 @@ end it "should return an unrenderable document error" do subject.execute error = ProtocolError.new 'unrenderable document error', 'The provided document could not be rendered.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'start-offset' do @@ -368,11 +459,11 @@ context 'set' do let(:command_opts) { { :start_offset => 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A start_offset value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'start-paused' do @@ -387,11 +478,11 @@ context 'true' do let(:command_opts) { { :start_paused => true } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A start_paused value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'repeat-interval' do @@ -406,11 +497,11 @@ context 'set' do let(:command_opts) { { :repeat_interval => 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A repeat_interval value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'repeat-times' do @@ -425,11 +516,11 @@ context 'set' do let(:command_opts) { { :repeat_times => 2 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A repeat_times value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'max-time' do @@ -444,11 +535,11 @@ context 'set' do let(:command_opts) { { :max_time => 30 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A max_time value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'voice' do @@ -463,11 +554,11 @@ context 'set' do let(:command_opts) { { :voice => 'alison' } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'A voice value is unsupported on Asterisk.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end describe 'interrupt_on' do @@ -498,10 +589,10 @@ context "set to :speech" do let(:command_opts) { { :interrupt_on => :speech } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new 'option error', 'An interrupt-on value of speech is unsupported.' - command.response(0.1).should == error + command.response(0.1).should be == error end end end end end