spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-2.5.2 vs spec/punchblock/translator/asterisk/component/output_spec.rb in punchblock-2.5.3
- old
+ new
@@ -31,18 +31,18 @@
end
subject { Output.new original_command, mock_call }
def expect_answered(value = true)
- mock_call.stub(:answered?).and_return(value)
+ allow(mock_call).to receive(:answered?).and_return(value)
end
def expect_mrcpsynth_with_options(options)
- mock_call.should_receive(:execute_agi_command).once.with do |*args|
- args[0].should be == 'EXEC MRCPSynth'
- 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 MRCPSynth')
+ expect(args[1]).to match options
+ }.and_return code: 200, result: 1
end
describe '#execute' do
before { original_command.request! }
@@ -50,11 +50,11 @@
let(:renderer) { 'foobar' }
it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'The renderer foobar is unsupported.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
context 'with a renderer of :swift' do
let(:renderer) { 'swift' }
@@ -78,99 +78,99 @@
end
before { expect_answered }
it "should execute Swift" do
- mock_call.should_receive(:execute_agi_command).once.with 'EXEC Swift', ssml_with_options
+ expect(mock_call).to receive(:execute_agi_command).once.with 'EXEC Swift', ssml_with_options
subject.execute
end
it 'should send a complete event when Swift completes' 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
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
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
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
+ expect(mock_call).to receive(:send_progress)
+ expect(mock_call).to 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
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options).and_return code: 200, result: 1
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.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('', '|1|1')).and_return code: 200, result: 1
+ expect(mock_call).to 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
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('', '|1|1')).and_return code: 200, result: 1
+ expect(mock_call).to 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 :voice" do
let(:command_opts) { { :interrupt_on => :voice } }
it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'An interrupt-on value of speech is unsupported.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(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.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options).and_return code: 200, result: 1
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.should_receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('Leonard^', '')).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Swift', ssml_with_options('Leonard^', '')).and_return code: 200, result: 1
subject.execute
end
end
end
@@ -187,11 +187,11 @@
end
end
let(:command_opts) { { render_documents: [{value: first_ssml_doc}, {value: second_ssml_doc}] } }
it "executes Swift with a concatenated version of the documents" do
- mock_call.should_receive(:execute_agi_command).once.with 'EXEC Swift', ssml_with_options
+ expect(mock_call).to receive(:execute_agi_command).once.with 'EXEC Swift', ssml_with_options
subject.execute
end
end
end
@@ -212,104 +212,104 @@
let :command_options do
{ :render_document => {:value => ssml_doc}, renderer: renderer }.merge(command_opts)
end
let(:synthstatus) { 'OK' }
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
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('"', '\"')}\"", ''].join(',')).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC MRCPSynth', ["\"#{ssml_doc.to_s.squish.gsub('"', '\"')}\"", ''].join(',')).and_return code: 200, result: 1
subject.execute
end
it 'should send a complete event when MRCPSynth completes' 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
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
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
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
+ expect(mock_call).to receive(:send_progress)
+ expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
end
end
context "when the SYNTHSTATUS variable is set to 'ERROR'" do
let(:synthstatus) { '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
describe 'document' do
context 'unset' do
let(:ssml_doc) { nil }
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
context 'with multiple documents' do
let(:command_opts) { { :render_documents => [{:value => ssml_doc}, {:value => ssml_doc}] } }
it "should execute MRCPSynth once with each document" do
param = ["\"#{ssml_doc.to_s.squish.gsub('"', '\"')}\"", ''].join(',')
- mock_call.should_receive(:execute_agi_command).once.with('EXEC MRCPSynth', param).and_return code: 200, result: 1
- mock_call.should_receive(:execute_agi_command).once.with('EXEC MRCPSynth', param).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC MRCPSynth', param).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC MRCPSynth', param).and_return code: 200, result: 1
subject.execute
end
it 'should not execute further output after a stop command' do
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.5
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.2
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
end
end
describe 'start-offset' do
@@ -324,11 +324,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.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 'start-paused' do
@@ -343,11 +343,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.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 'repeat-interval' do
@@ -362,11 +362,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.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 'repeat-times' do
@@ -382,40 +382,40 @@
let(:command_opts) { { :repeat_times => 2 } }
it "should render the specified number of times" do
2.times { expect_mrcpsynth_with_options(//) }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context 'to 0' do
let(:command_opts) { { :repeat_times => 0 } }
it "should render 10,000 the specified number of times" do
expect_answered
1000.times { expect_mrcpsynth_with_options(//) }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
end
it 'should not execute further output after a stop command' do
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
end
end
describe 'max-time' do
@@ -430,11 +430,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.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 'voice' do
@@ -483,24 +483,24 @@
context "set to :voice" do
let(:command_opts) { { :interrupt_on => :voice } }
it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'An interrupt-on value of speech is unsupported.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
end
end
[:asterisk, nil].each do |renderer|
context "with a renderer of #{renderer.inspect}" do
def expect_playback(filename = audio_filename)
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', filename).and_return code: 200
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', filename).and_return code: 200
end
def expect_playback_noanswer
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename + ',noanswer').and_return code: 200
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename + ',noanswer').and_return code: 200
end
let(:audio_filename) { 'tt-monkeys' }
let :ssml_doc do
@@ -518,19 +518,19 @@
let :original_command do
Punchblock::Component::Output.new command_options
end
let(:playbackstatus) { 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('PLAYBACKSTATUS').and_return playbackstatus }
+ before { allow(mock_call).to receive(:channel_var).with('PLAYBACKSTATUS').and_return playbackstatus }
describe 'ssml' do
context 'unset' do
let(:ssml_doc) { nil }
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
context 'with a single audio SSML node' do
let(:audio_filename) { 'tt-monkeys' }
@@ -548,11 +548,11 @@
def mock_call.answered?
true
end
expect_playback
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "when the audio filename is prefixed by file://" do
let(:audio_filename) { 'file://tt-monkeys' }
@@ -578,46 +578,56 @@
it 'should playback the audio file using Playback' do
expect_answered
expect_playback 'blue.tt-monkeys'
subject.execute
end
+
+ context "and no file extension" do
+ let(:audio_filename) { '/var/lib/gems/1.9.1/gems/myapp-1.0.0/prompts/greeting' }
+
+ it 'should playback the audio file using Playback' do
+ expect_answered
+ expect_playback '/var/lib/gems/1.9.1/gems/myapp-1.0.0/prompts/greeting'
+ subject.execute
+ end
+ end
end
end
context "when we get a RubyAMI Error" do
it "should send an error complete event" do
expect_answered
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
expect_answered
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
context "when the PLAYBACKSTATUS variable is set to 'FAILED'" do
let(:playbackstatus) { 'FAILED' }
it "should send an error complete event" do
expect_answered
- 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 playback error"
+ expect(complete_reason).to be_a Punchblock::Event::Complete::Error
+ expect(complete_reason.details).to eq("Terminated due to playback error")
end
end
end
context 'with a single text node without spaces' do
@@ -634,30 +644,30 @@
it 'should send a complete event when the file finishes playback' do
expect_answered
expect_playback
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "when we get a RubyAMI Error" do
it "should send an error complete event" do
expect_answered
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 "with early media playback" do
it "should play the file with Playback" do
expect_answered false
expect_playback_noanswer
- mock_call.should_receive(:send_progress)
+ expect(mock_call).to receive(:send_progress)
subject.execute
end
context "with interrupt_on set to something that is not nil" do
let(:audio_filename) { 'tt-monkeys' }
@@ -671,11 +681,11 @@
end
it "should return an error when the output is interruptible and it is early media" do
expect_answered false
error = ProtocolError.new.setup 'option error', 'Interrupt digits are not allowed with early media.'
subject.execute
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
end
end
@@ -700,16 +710,16 @@
it 'should send a complete event after the final file has finished playback' do
expect_answered
expect_playback [audio_filename1, audio_filename2].join('&')
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
subject.execute
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
end
context "with an SSML document containing elements other than <audio/>" do
let :ssml_doc do
@@ -719,53 +729,53 @@
end
it "should return an unrenderable document error" do
subject.execute
error = ProtocolError.new.setup 'unrenderable document error', 'The provided document could not be rendered. See http://adhearsion.com/docs/common_problems#unrenderable-document-error for details.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
context 'with multiple documents' do
let(:command_opts) { { render_documents: [{value: ssml_doc}, {value: ssml_doc}] } }
it "should render each document in turn using a Playback per document" do
expect_answered
2.times { expect_playback }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it 'should not execute further output after a stop command' do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
context "when the PLAYBACKSTATUS variable is set to 'FAILED'" do
let(:playbackstatus) { 'FAILED' }
it "should terminate playback and send an error complete event" do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).once.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 playback error"
+ expect(complete_reason).to be_a Punchblock::Event::Complete::Error
+ expect(complete_reason.details).to eq("Terminated due to playback error")
end
end
end
end
@@ -782,11 +792,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.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 'start-paused' do
@@ -802,11 +812,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.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 'repeat-interval' do
@@ -822,11 +832,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.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 'repeat-times' do
@@ -844,41 +854,41 @@
it "should render the specified number of times" do
expect_answered
2.times { expect_playback }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context 'to 0' do
let(:command_opts) { { :repeat_times => 0 } }
it "should render 10,000 the specified number of times" do
expect_answered
1000.times { expect_playback }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
end
it 'should not execute further output after a stop command' do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
end
end
describe 'max-time' do
@@ -894,11 +904,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.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 'voice' do
@@ -914,11 +924,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.setup 'option error', 'A voice 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 'interrupt_on' do
@@ -946,102 +956,102 @@
context "set to nil" do
let(:command_opts) { { :interrupt_on => nil } }
it "does not redirect the call" do
expect_answered
expect_playback
- mock_call.should_receive(:redirect_back).never
+ expect(mock_call).to receive(:redirect_back).never
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
context "set to :any" do
let(:command_opts) { { :interrupt_on => :any } }
before do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
- subject.should_receive(:send_finish).and_return nil
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
+ expect(subject).to receive(:send_finish).and_return nil
end
context "when a DTMF digit is received" do
it "sends the correct complete event" do
- mock_call.should_receive :redirect_back
+ expect(mock_call).to receive :redirect_back
subject.execute
- original_command.response(0.1).should be_a Ref
- original_command.should_not be_complete
+ expect(original_command.response(0.1)).to be_a Ref
+ expect(original_command).not_to be_complete
send_ami_events_for_dtmf 1
mock_call.process_ami_event ami_event
sleep 0.2
- original_command.should be_complete
- reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to be_complete
+ expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it "redirects the call back to async AGI" do
- mock_call.should_receive(:redirect_back).once
+ expect(mock_call).to receive(:redirect_back).once
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
end
context "set to :dtmf" do
let(:command_opts) { { :interrupt_on => :dtmf } }
before do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
- subject.should_receive(:send_finish).and_return nil
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
+ expect(subject).to receive(:send_finish).and_return nil
end
context "when a DTMF digit is received" do
it "sends the correct complete event" do
- mock_call.should_receive :redirect_back
+ expect(mock_call).to receive :redirect_back
subject.execute
- original_command.response(0.1).should be_a Ref
- original_command.should_not be_complete
+ expect(original_command.response(0.1)).to be_a Ref
+ expect(original_command).not_to be_complete
send_ami_events_for_dtmf 1
mock_call.process_ami_event ami_event
sleep 0.2
- original_command.should be_complete
- reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to be_complete
+ expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it "redirects the call back to async AGI" do
- mock_call.should_receive(:redirect_back).once
+ expect(mock_call).to receive(:redirect_back).once
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
end
context "set to :voice" do
let(:command_opts) { { :interrupt_on => :voice } }
it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'An interrupt-on value of speech is unsupported.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
end
end
end
context "with a renderer of :native_or_unimrcp" do
def expect_playback(filename = audio_filename)
- mock_call.should_receive(:execute_agi_command).ordered.once.with('EXEC Playback', filename).and_return code: 200
+ expect(mock_call).to receive(:execute_agi_command).ordered.once.with('EXEC Playback', filename).and_return code: 200
end
def expect_playback_noanswer
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename + ',noanswer').and_return code: 200
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename + ',noanswer').and_return code: 200
end
def expect_mrcpsynth(doc = ssml_doc)
- mock_call.should_receive(:execute_agi_command).ordered.once.with('EXEC MRCPSynth', ["\"#{doc.to_s.squish.gsub('"', '\"')}\"", ''].join(',')).and_return code: 200, result: 1
+ expect(mock_call).to receive(:execute_agi_command).ordered.once.with('EXEC MRCPSynth', ["\"#{doc.to_s.squish.gsub('"', '\"')}\"", ''].join(',')).and_return code: 200, result: 1
end
let(:audio_filename) { 'tt-monkeys' }
let :ssml_doc do
@@ -1061,19 +1071,19 @@
let :original_command do
Punchblock::Component::Output.new command_options
end
let(:playbackstatus) { 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('PLAYBACKSTATUS').and_return playbackstatus }
+ before { allow(mock_call).to receive(:channel_var).with('PLAYBACKSTATUS').and_return playbackstatus }
describe 'ssml' do
context 'unset' do
let(:ssml_doc) { nil }
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
context 'with a single audio SSML node' do
let(:audio_filename) { 'tt-monkeys' }
@@ -1097,11 +1107,11 @@
def mock_call.answered?
true
end
expect_playback
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "when the audio filename is prefixed by file://" do
let(:audio_filename) { 'file://tt-monkeys' }
@@ -1134,34 +1144,34 @@
context "when we get a RubyAMI Error" do
it "should send an error complete event" do
expect_answered
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
expect_answered
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
context "when the PLAYBACKSTATUS variable is set to 'FAILED'" do
let(:playbackstatus) { 'FAILED' }
let(:synthstatus) { 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
let :fallback_doc do
RubySpeech::SSML.draw language: 'pt-BR' do
voice name: 'frank' do
string "Hello world"
@@ -1172,11 +1182,11 @@
it "should attempt to render the children of the audio tag via MRCP and then send a complete event" do
expect_answered
expect_playback
expect_mrcpsynth fallback_doc
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "and the SYNTHSTATUS variable is set to 'ERROR'" do
let(:synthstatus) { 'ERROR' }
@@ -1184,12 +1194,12 @@
expect_answered
expect_playback
expect_mrcpsynth fallback_doc
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
end
@@ -1207,30 +1217,30 @@
it 'should send a complete event when the file finishes playback' do
expect_answered
expect_playback
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "when we get a RubyAMI Error" do
it "should send an error complete event" do
expect_answered
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 "with early media playback" do
it "should play the file with Playback" do
expect_answered false
expect_playback_noanswer
- mock_call.should_receive(:send_progress)
+ expect(mock_call).to receive(:send_progress)
subject.execute
end
context "with interrupt_on set to something that is not nil" do
let(:audio_filename) { 'tt-monkeys' }
@@ -1244,11 +1254,11 @@
end
it "should return an error when the output is interruptible and it is early media" do
expect_answered false
error = ProtocolError.new.setup 'option error', 'Interrupt digits are not allowed with early media.'
subject.execute
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
end
end
@@ -1285,41 +1295,41 @@
expect_answered
expect_playback audio_filename1
expect_playback audio_filename2
expect_playback audio_filename3
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
subject.execute
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
it 'should not execute further output after a stop command' do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
context "when the PLAYBACKSTATUS variable is set to 'FAILED'" do
let(:synthstatus) { 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('PLAYBACKSTATUS').and_return 'SUCCESS', 'FAILED', 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
+ before { allow(mock_call).to receive(:channel_var).with('PLAYBACKSTATUS').and_return 'SUCCESS', 'FAILED', 'SUCCESS' }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
let :fallback_doc do
RubySpeech::SSML.draw do
string "Fallback 2"
end
@@ -1330,11 +1340,11 @@
expect_playback audio_filename1
expect_playback audio_filename2
expect_mrcpsynth fallback_doc
expect_playback audio_filename3
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "and the SYNTHSTATUS variable is set to 'ERROR'" do
let(:synthstatus) { 'ERROR' }
@@ -1343,12 +1353,12 @@
expect_playback audio_filename1
expect_playback audio_filename2
expect_mrcpsynth fallback_doc
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
end
@@ -1359,17 +1369,17 @@
string "Foo Bar"
end
end
end
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return 'SUCCESS' }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return 'SUCCESS' }
it "should attempt to render the document via MRCP and then send a complete event" do
expect_answered
expect_mrcpsynth ssml_doc
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
end
context "with mixed TTS and audio tags" do
let :ssml_doc do
@@ -1399,20 +1409,20 @@
string "Doo Dah"
end
end
end
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return 'SUCCESS' }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return 'SUCCESS' }
it "should attempt to render the document via MRCP and then send a complete event" do
expect_answered
expect_mrcpsynth first_doc
expect_playback 'tt-monkeys'
expect_mrcpsynth second_doc
expect_playback 'tt-weasels'
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
end
context 'with multiple documents' do
let :second_ssml_doc do
@@ -1437,36 +1447,36 @@
expect_answered
expect_playback
expect_playback 'two'
expect_playback 'three'
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it 'should not execute further output after a stop command' do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
context "when the PLAYBACKSTATUS variable is set to 'FAILED'" do
let(:synthstatus) { 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('PLAYBACKSTATUS').and_return 'SUCCESS', 'FAILED', 'SUCCESS' }
- before { mock_call.stub(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
+ before { allow(mock_call).to receive(:channel_var).with('PLAYBACKSTATUS').and_return 'SUCCESS', 'FAILED', 'SUCCESS' }
+ before { allow(mock_call).to receive(:channel_var).with('SYNTHSTATUS').and_return synthstatus }
let :fallback_doc do
RubySpeech::SSML.draw do
string "Bazzz"
end
@@ -1477,11 +1487,11 @@
expect_playback
expect_playback 'two'
expect_mrcpsynth fallback_doc
expect_playback 'three'
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context "and the SYNTHSTATUS variable is set to 'ERROR'" do
let(:synthstatus) { 'ERROR' }
@@ -1490,12 +1500,12 @@
expect_playback
expect_playback 'two'
expect_mrcpsynth fallback_doc
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
end
end
@@ -1513,11 +1523,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.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 'start-paused' do
@@ -1533,11 +1543,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.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 'repeat-interval' do
@@ -1553,11 +1563,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.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 'repeat-times' do
@@ -1575,41 +1585,41 @@
it "should render the specified number of times" do
expect_answered
2.times { expect_playback }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
context 'to 0' do
let(:command_opts) { { :repeat_times => 0 } }
it "should render 10,000 the specified number of times" do
expect_answered
1000.times { expect_playback }
subject.execute
- original_command.complete_event(0.1).reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command.complete_event(0.1).reason).to be_a Punchblock::Component::Output::Complete::Finish
end
end
it 'should not execute further output after a stop command' do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.ordered.and_return do
+ expect(mock_call).to receive(:execute_agi_command).once.ordered do
sleep 0.2
end
latch = CountDownLatch.new 1
- original_command.should_receive(:add_event).once.with do |e|
- e.reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to receive(:add_event).once.with { |e|
+ expect(e.reason).to be_a Punchblock::Component::Output::Complete::Finish
latch.countdown!
- end
+ }
Celluloid::Future.new { subject.execute }
sleep 0.1
- mock_call.should_receive(:redirect_back).ordered
+ expect(mock_call).to receive(:redirect_back).ordered
stop_command = Punchblock::Component::Stop.new
stop_command.request!
subject.execute_command stop_command
- latch.wait(2).should be_true
+ expect(latch.wait(2)).to be_true
end
end
end
describe 'max-time' do
@@ -1625,11 +1635,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.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 'voice' do
@@ -1645,11 +1655,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.setup 'option error', 'A voice 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 'interrupt_on' do
@@ -1677,85 +1687,85 @@
context "set to nil" do
let(:command_opts) { { :interrupt_on => nil } }
it "does not redirect the call" do
expect_answered
expect_playback
- mock_call.should_receive(:redirect_back).never
+ expect(mock_call).to receive(:redirect_back).never
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
context "set to :any" do
let(:command_opts) { { :interrupt_on => :any } }
before do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
- subject.should_receive(:send_finish).and_return nil
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
+ expect(subject).to receive(:send_finish).and_return nil
end
context "when a DTMF digit is received" do
it "sends the correct complete event" do
- mock_call.should_receive :redirect_back
+ expect(mock_call).to receive :redirect_back
subject.execute
- original_command.response(0.1).should be_a Ref
- original_command.should_not be_complete
+ expect(original_command.response(0.1)).to be_a Ref
+ expect(original_command).not_to be_complete
send_ami_events_for_dtmf 1
mock_call.process_ami_event ami_event
sleep 0.2
- original_command.should be_complete
- reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to be_complete
+ expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it "redirects the call back to async AGI" do
- mock_call.should_receive(:redirect_back).once
+ expect(mock_call).to receive(:redirect_back).once
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
end
context "set to :dtmf" do
let(:command_opts) { { :interrupt_on => :dtmf } }
before do
expect_answered
- mock_call.should_receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
- subject.should_receive(:send_finish).and_return nil
+ expect(mock_call).to receive(:execute_agi_command).once.with('EXEC Playback', audio_filename)
+ expect(subject).to receive(:send_finish).and_return nil
end
context "when a DTMF digit is received" do
it "sends the correct complete event" do
- mock_call.should_receive :redirect_back
+ expect(mock_call).to receive :redirect_back
subject.execute
- original_command.response(0.1).should be_a Ref
- original_command.should_not be_complete
+ expect(original_command.response(0.1)).to be_a Ref
+ expect(original_command).not_to be_complete
send_ami_events_for_dtmf 1
mock_call.process_ami_event ami_event
sleep 0.2
- original_command.should be_complete
- reason.should be_a Punchblock::Component::Output::Complete::Finish
+ expect(original_command).to be_complete
+ expect(reason).to be_a Punchblock::Component::Output::Complete::Finish
end
it "redirects the call back to async AGI" do
- mock_call.should_receive(:redirect_back).once
+ expect(mock_call).to receive(:redirect_back).once
subject.execute
- original_command.response(0.1).should be_a Ref
+ expect(original_command.response(0.1)).to be_a Ref
send_ami_events_for_dtmf 1
end
end
end
context "set to :voice" do
let(:command_opts) { { :interrupt_on => :voice } }
it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'An interrupt-on value of speech is unsupported.'
- original_command.response(0.1).should be == error
+ expect(original_command.response(0.1)).to eq(error)
end
end
end
end
end
@@ -1765,11 +1775,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 }
@@ -1787,25 +1797,25 @@
original_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