spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-1.9.3 vs spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-1.9.4
- old
+ new
@@ -29,11 +29,11 @@
end
subject { Output.new original_command, mock_call }
def expect_answered(value = true)
- mock_call.should_receive(:answered?).at_least(:once).and_return(value)
+ mock_call.stub(:answered?).and_return(value)
end
describe '#execute' do
before { original_command.request! }
@@ -68,10 +68,12 @@
def ssml_with_options(prefix = '', postfix = '')
base_doc = ssml_doc.to_s.squish.gsub(/["\\]/) { |m| "\\#{m}" }
prefix + base_doc + postfix
end
+ before { expect_answered }
+
it "should execute Swift" do
mock_call.should_receive(:execute_agi_command).once.with 'EXEC Swift', ssml_with_options
subject.execute
end
@@ -90,10 +92,20 @@
complete_reason.should be_a Punchblock::Event::Complete::Error
complete_reason.details.should == "Terminated due to AMI error 'FooBar'"
end
end
+ context "when the call is not answered" do
+ before { expect_answered false }
+
+ it "should send progress" do
+ mock_call.should_receive(:send_progress)
+ mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1
+ subject.execute
+ end
+ 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.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options).and_return code: 200, result: 1
@@ -102,20 +114,18 @@
end
context "set to :any" do
let(:command_opts) { { :interrupt_on => :any } }
it "should add the interrupt options to the argument" do
- expect_answered
mock_call.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('', '|1|1')).and_return code: 200, result: 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
- expect_answered
mock_call.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('', '|1|1')).and_return code: 200, result: 1
subject.execute
end
end
@@ -172,10 +182,12 @@
args[0].should be == 'EXEC MRCPSynth'
args[2].should match options
end.and_return code: 200, result: 1
end
+ before { expect_answered }
+
it "should execute MRCPSynth" do
mock_call.should_receive(:execute_agi_command).once.with('EXEC MRCPSynth', ssml_doc.to_s.squish.gsub(/["\\]/) { |m| "\\#{m}" }, '').and_return code: 200, result: 1
subject.execute
end
@@ -210,10 +222,20 @@
complete_reason.should be_a Punchblock::Event::Complete::Error
complete_reason.details.should == "Terminated due to AMI error 'FooBar'"
end
end
+ context "when the call is not answered" do
+ before { expect_answered false }
+
+ it "should send progress" do
+ mock_call.should_receive(:send_progress)
+ mock_call.should_receive(:execute_agi_command).and_return code: 200, result: 1
+ subject.execute
+ end
+ end
+
describe 'ssml' do
context 'unset' do
let(:command_opts) { { :ssml => nil } }
it "should return an error and not execute any actions" do
subject.execute
@@ -346,19 +368,17 @@
end
context "set to :any" do
let(:command_opts) { { :interrupt_on => :any } }
it "should pass the i option to MRCPSynth" do
- expect_answered
expect_mrcpsynth_with_options(/i=any/)
subject.execute
end
end
context "set to :dtmf" do
let(:command_opts) { { :interrupt_on => :dtmf } }
it "should pass the i option to MRCPSynth" do
- expect_answered
expect_mrcpsynth_with_options(/i=any/)
subject.execute
end
end