spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.2.1 vs spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.3.0
- old
+ new
@@ -67,10 +67,18 @@
it 'places the fallback in the SSML doc' do
expect_ssml_output ssml
subject.play_audio(audio_file, :fallback => fallback).should be true
end
end
+
+ context "with a media engine" do
+ let(:media_engine) { :native }
+ it "should use the specified media engine in the component" do
+ expect_ssml_output ssml, renderer: media_engine
+ subject.play_audio(audio_file, renderer: media_engine).should be true
+ end
+ end
end
describe "#play_audio!" do
let(:audio_file) { "/sounds/boo.wav" }
@@ -98,10 +106,18 @@
it 'places the fallback in the SSML doc' do
expect_async_ssml_output ssml
subject.play_audio!(audio_file, :fallback => fallback).should be_a Punchblock::Component::Output
end
end
+
+ context "with a media engine" do
+ let(:media_engine) { :native }
+ it "should use the specified media engine in the SSML" do
+ expect_async_ssml_output ssml, renderer: media_engine
+ subject.play_audio!(audio_file, renderer: media_engine).should be_a Punchblock::Component::Output
+ end
+ end
end
describe "#play_numeric" do
let :ssml do
RubySpeech::SSML.draw do
@@ -317,10 +333,13 @@
end
end
end
describe '#play' do
+ let(:extra_options) do
+ { renderer: :native }
+ end
describe "with a single string" do
let(:audio_file) { "/foo/bar.wav" }
let :ssml do
file = audio_file
RubySpeech::SSML.draw { audio :src => file }
@@ -328,10 +347,15 @@
it 'plays the audio file' do
expect_ssml_output ssml
subject.play(audio_file).should be true
end
+
+ it 'plays the audio file with the specified extra options if present' do
+ expect_ssml_output ssml, extra_options
+ subject.play(audio_file, extra_options).should be true
+ end
end
describe "with multiple arguments" do
let(:args) { ["/foo/bar.wav", 1, Time.now] }
let :ssml do
@@ -347,10 +371,16 @@
it 'plays all arguments in one document' do
expect_ssml_output ssml
subject.play(*args).should be true
end
+
+ it 'plays all arguments in one document with the extra options if present' do
+ expect_ssml_output ssml, extra_options
+ args << extra_options
+ subject.play(*args).should be true
+ end
end
describe "with a collection of arguments" do
let(:args) { ["/foo/bar.wav", 1, Time.now] }
let :ssml do
@@ -461,10 +491,13 @@
end
end
end
describe '#play!' do
+ let(:extra_options) do
+ { renderer: :native }
+ end
describe "with a single string" do
let(:audio_file) { "/foo/bar.wav" }
let :ssml do
file = audio_file
RubySpeech::SSML.draw { audio :src => file }
@@ -472,10 +505,15 @@
it 'plays the audio file' do
expect_async_ssml_output ssml
subject.play!(audio_file).should be_a Punchblock::Component::Output
end
+
+ it 'plays the audio file with the specified extra options if present' do
+ expect_async_ssml_output ssml, extra_options
+ subject.play!(audio_file, extra_options)
+ end
end
describe "with multiple arguments" do
let(:args) { ["/foo/bar.wav", 1, Time.now] }
let :ssml do
@@ -491,10 +529,16 @@
it 'plays all arguments in one document' do
expect_async_ssml_output ssml
subject.play!(*args).should be_a Punchblock::Component::Output
end
+
+ it 'plays all arguments in one document with the extra options if present' do
+ expect_async_ssml_output ssml, extra_options
+ args << extra_options
+ subject.play!(*args)
+ end
end
describe "with a number" do
let(:argument) { 123 }
@@ -589,10 +633,11 @@
describe "#interruptible_play" do
let(:output1) { "one two" }
let(:output2) { "three four" }
let(:non_existing) { "http://adhearsion.com/nonexistingfile.mp3" }
+ let(:extra_options) { {renderer: :native } }
it "plays two outputs in succession" do
subject.should_receive(:stream_file).twice
digit = subject.interruptible_play output1, output2
digit.should be_nil
@@ -602,10 +647,17 @@
subject.should_receive(:stream_file).once.and_return(2)
digit = subject.interruptible_play output1, output2
digit.should be == 2
end
+ it "passes options on to #stream_file" do
+ subject.should_receive(:stream_file).once.with(output1, '0123456789#*', extra_options)
+ subject.should_receive(:stream_file).once.with(output2, '0123456789#*', extra_options)
+ digit = subject.interruptible_play output1, output2, extra_options
+ digit.should be_nil
+ end
+
it 'raises an exception when output is unsuccessful' do
subject.should_receive(:stream_file).once.and_raise Output::PlaybackError, "Output failed"
expect { subject.interruptible_play non_existing }.to raise_error(Output::PlaybackError)
end
end
@@ -666,9 +718,22 @@
expect_component_complete_event
flexmock(Punchblock::Component::Output).new_instances.should_receive(:stop!)
expect_component_execution output_component
subject.stream_file(prompt, allowed_digits).should be == '5'
+ end
+
+ context "with output options passed in" do
+ let(:extra_options) { {renderer: :native } }
+ it "plays the correct output with options" do
+ def controller.write_and_await_response(input_component)
+ # it is actually a no-op here
+ end
+
+ expect_component_complete_event
+ expect_component_execution Punchblock::Component::Output.new({:ssml => ssml.to_s}.merge(extra_options))
+ subject.stream_file prompt, allowed_digits, extra_options
+ end
end
end
describe "#say" do
describe "with a RubySpeech document" do