spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.1.3 vs spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.2.0
- old
+ new
@@ -5,16 +5,16 @@
module Adhearsion
class CallController
describe Output do
include CallControllerTestHelpers
- def expect_ssml_output(ssml)
- expect_component_execution Punchblock::Component::Output.new(:ssml => ssml)
+ def expect_ssml_output(ssml, options = {})
+ expect_component_execution Punchblock::Component::Output.new(options.merge(:ssml => ssml))
end
- def expect_async_ssml_output(ssml)
- expect_message_waiting_for_response Punchblock::Component::Output.new(:ssml => ssml)
+ def expect_async_ssml_output(ssml, options = {})
+ expect_message_waiting_for_response Punchblock::Component::Output.new(options.merge(:ssml => ssml))
end
describe "#player" do
it "should return a Player component targetted at the current controller" do
player = controller.player
@@ -348,10 +348,29 @@
expect_ssml_output ssml
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
+ file = args[0]
+ n = args[1].to_s
+ t = args[2].to_s
+ RubySpeech::SSML.draw do
+ audio :src => file
+ say_as(:interpret_as => 'cardinal') { n }
+ say_as(:interpret_as => 'time') { t }
+ end
+ end
+
+ it 'plays all arguments in one document' do
+ expect_ssml_output ssml
+ subject.play(args).should be true
+ end
+ end
+
describe "with a number" do
let(:argument) { 123 }
let(:ssml) do
number = argument.to_s
@@ -411,11 +430,11 @@
expect_ssml_output ssml
subject.play(date).should be true
end
end
- describe "with an array containing a Date/DateTime/Time object and a hash" do
+ describe "with an hash containing a Date/DateTime/Time object and format options" do
let(:date) { Date.parse '2011-01-23' }
let(:format) { "d-m-y" }
let(:strftime) { "%d-%m%Y" }
let :ssml do
@@ -617,46 +636,35 @@
let(:input_component) {
Punchblock::Component::Input.new :mode => :dtmf,
:grammar => { :value => grammar.to_s }
}
+ def expect_component_complete_event
+ complete_event = Punchblock::Event::Complete.new
+ flexmock(complete_event).should_receive(:reason => flexmock(:utterance => 'dtmf-5'))
+ flexmock(Punchblock::Component::Input).new_instances do |input|
+ input.should_receive(:complete?).and_return(false)
+ input.should_receive(:complete_event).and_return(complete_event)
+ end
+ end
+
#test does pass and method works, but not sure if the empty method is a good idea
it "plays the correct output" do
def controller.write_and_await_response(input_component)
# it is actually a no-op here
end
- def expect_component_complete_event
- complete_event = Punchblock::Event::Complete.new
- flexmock(complete_event).should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
- flexmock(Punchblock::Component::Input).new_instances do |input|
- input.should_receive(:complete?).and_return(false)
- input.should_receive(:complete_event).and_return(complete_event)
- end
- end
-
expect_component_complete_event
expect_component_execution Punchblock::Component::Output.new(:ssml => ssml.to_s)
subject.stream_file prompt, allowed_digits
end
it "returns a single digit amongst the allowed when pressed" do
- flexmock(Punchblock::Event::Complete).new_instances.should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
-
def controller.write_and_await_response(input_component)
input_component.trigger_event_handler Punchblock::Event::Complete.new
end
- def expect_component_complete_event
- complete_event = Punchblock::Event::Complete.new
- flexmock(complete_event).should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
- flexmock(Punchblock::Component::Input).new_instances do |input|
- input.should_receive(:complete?).and_return(false)
- input.should_receive(:complete_event).and_return(complete_event)
- end
- end
-
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
@@ -678,10 +686,23 @@
expect_ssml_output ssml
subject.say(str).should be_a Punchblock::Component::Output
end
end
+ describe "with a default voice set" do
+ before { Adhearsion.config.punchblock.default_voice = 'foo' }
+
+ it 'sets the voice on the output component' do
+ str = "Hello world"
+ ssml = RubySpeech::SSML.draw { string str }
+ expect_ssml_output ssml, voice: 'foo'
+ subject.say(str)
+ end
+
+ after { Adhearsion.config.punchblock.default_voice = nil }
+ end
+
describe "converts the argument to a string" do
it 'calls output with a string' do
argument = 123
ssml = RubySpeech::SSML.draw { string '123' }
expect_ssml_output ssml
@@ -710,9 +731,22 @@
str = "Hello world"
ssml = RubySpeech::SSML.draw { string str }
expect_async_ssml_output ssml
subject.say!(str).should be_a Punchblock::Component::Output
end
+ end
+
+ describe "with a default voice set" do
+ before { Adhearsion.config.punchblock.default_voice = 'foo' }
+
+ it 'sets the voice on the output component' do
+ str = "Hello world"
+ ssml = RubySpeech::SSML.draw { string str }
+ expect_async_ssml_output ssml, voice: 'foo'
+ subject.say!(str)
+ end
+
+ after { Adhearsion.config.punchblock.default_voice = nil }
end
describe "converts the argument to a string" do
it 'calls output with a string' do
argument = 123