spec/punchblock/translator/asterisk/component/mrcp_prompt_spec.rb in punchblock-2.5.2 vs spec/punchblock/translator/asterisk/component/mrcp_prompt_spec.rb in punchblock-2.5.3

- old
+ new

@@ -86,32 +86,32 @@ { 'RECOG_STATUS' => recog_status, 'RECOG_COMPLETION_CAUSE' => recog_completion_cause, 'RECOG_RESULT' => recog_result }.each do |var, val| - mock_call.stub(:channel_var).with(var).and_return val + allow(mock_call).to receive(:channel_var).with(var).and_return val end end context 'with an invalid recognizer' do let(:input_command_opts) { { recognizer: 'foobar' } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'The recognizer foobar is unsupported.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end [:asterisk].each do |recognizer| context "with a recognizer #{recognizer.inspect}" do let(:input_command_opts) { { recognizer: recognizer } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', "The recognizer #{recognizer} is unsupported." - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end def expect_mrcpsynth_with_options(options) @@ -121,44 +121,44 @@ def expect_synthandrecog_with_options(options) expect_app_with_options 'SynthAndRecog', options end def expect_app_with_options(app, options) - mock_call.should_receive(:execute_agi_command).once.with do |*args| - args[0].should be == "EXEC #{app}" - args[1].should match options - end.and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).once.with { |*args| + expect(args[0]).to eq("EXEC #{app}") + expect(args[1]).to match options + }.and_return code: 200, result: 1 end describe 'Output#document' do context 'with multiple inline documents' do let(:output_command_options) { { render_documents: [{value: ssml_doc}, {value: ssml_doc}] } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'Only one document is allowed.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end context 'with multiple documents by URI' do let(:output_command_options) { { render_documents: [{url: 'http://example.com/doc1.ssml'}, {url: 'http://example.com/doc2.ssml'}] } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'Only one document is allowed.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end context 'unset' do let(:output_command_options) { {} } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'An SSML document is required.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#renderer' do @@ -166,13 +166,13 @@ context renderer.to_s do let(:output_command_opts) { { renderer: renderer } } it "should return a ref and execute SynthAndRecog" do param = [ssml_doc.to_doc, grammar.to_doc].map { |o| "\"#{o.to_s.squish.gsub('"', '\"')}\"" }.push('uer=1&b=1').join(',') - mock_call.should_receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 subject.execute - original_command.response(0.1).should be_a Ref + expect(original_command.response(0.1)).to be_a Ref end context "when SynthAndRecog completes" do context "with a match" do let :expected_nlsml do @@ -185,69 +185,80 @@ end it 'should send a match complete event' do expected_complete_reason = Punchblock::Component::Input::Complete::Match.new nlsml: expected_nlsml - mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1 subject.execute - original_command.complete_event(0.1).reason.should == expected_complete_reason + expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason) end end context "with a nomatch cause" do let(:recog_completion_cause) { '001' } it 'should send a nomatch complete event' do expected_complete_reason = Punchblock::Component::Input::Complete::NoMatch.new - mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1 subject.execute - original_command.complete_event(0.1).reason.should == expected_complete_reason + expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason) end end context "with a noinput cause" do let(:recog_completion_cause) { '002' } it 'should send a nomatch complete event' do expected_complete_reason = Punchblock::Component::Input::Complete::NoInput.new - mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1 subject.execute - original_command.complete_event(0.1).reason.should == expected_complete_reason + expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason) end end + context "when the RECOG_STATUS variable is set to 'INTERRUPTED' after a successful recognition" do + let(:recog_status) { 'INTERRUPTED' } + + it "should send an error complete event" do + expected_complete_reason = Punchblock::Component::Input::Complete::NoMatch.new + expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1 + subject.execute + expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason) + end + end + context "when the RECOG_STATUS variable is set to 'ERROR'" do let(:recog_status) { 'ERROR' } it "should send an error complete event" do - mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1 subject.execute complete_reason = original_command.complete_event(0.1).reason - complete_reason.should be_a Punchblock::Event::Complete::Error - complete_reason.details.should == "Terminated due to UniMRCP error" + expect(complete_reason).to be_a Punchblock::Event::Complete::Error + expect(complete_reason.details).to eq("Terminated due to UniMRCP error") end end end context "when we get a RubyAMI Error" do it "should send an error complete event" do error = RubyAMI::Error.new.tap { |e| e.message = 'FooBar' } - mock_call.should_receive(:execute_agi_command).and_raise error + expect(mock_call).to receive(:execute_agi_command).and_raise error subject.execute complete_reason = original_command.complete_event(0.1).reason - complete_reason.should be_a Punchblock::Event::Complete::Error - complete_reason.details.should == "Terminated due to AMI error 'FooBar'" + expect(complete_reason).to be_a Punchblock::Event::Complete::Error + expect(complete_reason.details).to eq("Terminated due to AMI error 'FooBar'") end end context "when the channel is gone" do it "should send an error complete event" do error = ChannelGoneError.new 'FooBar' - mock_call.should_receive(:execute_agi_command).and_raise error + expect(mock_call).to receive(:execute_agi_command).and_raise error subject.execute complete_reason = original_command.complete_event(0.1).reason - complete_reason.should be_a Punchblock::Event::Complete::Hangup + expect(complete_reason).to be_a Punchblock::Event::Complete::Hangup end end end end @@ -256,11 +267,11 @@ let(:output_command_opts) { { renderer: renderer } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', "The renderer #{renderer} is unsupported." - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end end @@ -325,11 +336,11 @@ context 'set' do let(:output_command_opts) { { start_offset: 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A start_offset value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#start-paused' do @@ -344,11 +355,11 @@ context 'true' do let(:output_command_opts) { { start_paused: true } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A start_paused value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#repeat-interval' do @@ -363,11 +374,11 @@ context 'set' do let(:output_command_opts) { { repeat_interval: 10 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A repeat_interval value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#repeat-times' do @@ -382,11 +393,11 @@ context 'set' do let(:output_command_opts) { { repeat_times: 2 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A repeat_times value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#max-time' do @@ -401,11 +412,11 @@ context 'set' do let(:output_command_opts) { { max_time: 30 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A max_time value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#interrupt_on' do @@ -420,45 +431,45 @@ context 'set' do let(:output_command_opts) { { interrupt_on: :dtmf } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A interrupt_on value is unsupported on Asterisk.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Output#grammar' do context 'with multiple inline grammars' do let(:input_command_options) { { grammars: [{value: voice_grammar}, {value: dtmf_grammar}] } } it "should return a ref and execute SynthAndRecog" do param = [ssml_doc.to_doc, [voice_grammar.to_doc.to_s, dtmf_grammar.to_doc.to_s].join(',')].map { |o| "\"#{o.to_s.squish.gsub('"', '\"')}\"" }.push('uer=1&b=1').join(',') - mock_call.should_receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 subject.execute - original_command.response(0.1).should be_a Ref + expect(original_command.response(0.1)).to be_a Ref end end context 'with multiple grammars by URI' do let(:input_command_options) { { grammars: [{url: 'http://example.com/grammar1.grxml'}, {url: 'http://example.com/grammar2.grxml'}] } } it "should return a ref and execute SynthAndRecog" do param = [ssml_doc.to_doc, ['http://example.com/grammar1.grxml', 'http://example.com/grammar2.grxml'].join(',')].map { |o| "\"#{o.to_s.squish.gsub('"', '\"')}\"" }.push('uer=1&b=1').join(',') - mock_call.should_receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 + expect(mock_call).to receive(:execute_agi_command).once.with('EXEC SynthAndRecog', param).and_return code: 200, result: 1 subject.execute - original_command.response(0.1).should be_a Ref + expect(original_command.response(0.1)).to be_a Ref end end context 'unset' do let(:input_command_options) { {} } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'A grammar is required.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Input#initial-timeout' do @@ -493,11 +504,11 @@ let(:input_command_opts) { { initial_timeout: -1000 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'An initial-timeout value must be -1 or a positive integer.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Input#inter-digit-timeout' do @@ -532,11 +543,11 @@ let(:input_command_opts) { { inter_digit_timeout: -1000 } } it "should return an error and not execute any actions" do subject.execute error = ProtocolError.new.setup 'option error', 'An inter-digit-timeout value must be -1 or a positive integer.' - original_command.response(0.1).should be == error + expect(original_command.response(0.1)).to eq(error) end end end describe 'Input#mode' do @@ -640,11 +651,11 @@ let(:command) { Punchblock::Component::Output::Pause.new } before { command.request! } it "returns a ProtocolError response" do subject.execute_command command - command.response(0.1).should be_a ProtocolError + expect(command.response(0.1)).to be_a ProtocolError end end context "with a Stop command" do let(:command) { Punchblock::Component::Stop.new } @@ -661,25 +672,25 @@ command.request! original_command.execute! end it "sets the command response to true" do - mock_call.should_receive(:redirect_back) + expect(mock_call).to receive(:redirect_back) subject.execute_command command - command.response(0.1).should be == true + expect(command.response(0.1)).to eq(true) end it "sends the correct complete event" do - mock_call.should_receive(:redirect_back) + expect(mock_call).to receive(:redirect_back) subject.execute_command command - original_command.should_not be_complete + expect(original_command).not_to be_complete mock_call.process_ami_event ami_event - reason.should be_a Punchblock::Event::Complete::Stop - original_command.should be_complete + expect(reason).to be_a Punchblock::Event::Complete::Stop + expect(original_command).to be_complete end it "redirects the call by unjoining it" do - mock_call.should_receive(:redirect_back) + expect(mock_call).to receive(:redirect_back) subject.execute_command command end end end