spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.0.0.beta1 vs spec/adhearsion/call_controller/output_spec.rb in adhearsion-2.0.0.rc1

- old
+ new

@@ -1,5 +1,7 @@ +# encoding: utf-8 + require 'spec_helper' module Adhearsion class CallController describe Output do @@ -265,40 +267,46 @@ subject.play!(prompt, second_prompt) end it "raises an exception if play fails" do subject.should_receive(:play).once.and_return false - expect { subject.play!(non_existing) }.to raise_error(Adhearsion::PlaybackError) + expect { subject.play!(non_existing) }.to raise_error(Output::PlaybackError) end end describe "#speak" do + it "should be an alias for #say" do + subject.method(:speak).should be == subject.method(:say) + end + end + + describe "#say" do describe "with a RubySpeech document" do it 'plays the correct SSML' do doc = RubySpeech::SSML.draw { string "Hello world" } subject.should_receive(:play_ssml).once.with(doc, {}).and_return true subject.should_receive(:output).never - subject.speak(doc).should be true + subject.say(doc).should be true end end describe "with a string" do it 'outputs the correct text' do string = "Hello world" subject.should_receive(:play_ssml).once.with(string, {}) subject.should_receive(:output).once.with(:text, string, {}).and_return true - subject.speak(string).should be true + subject.say(string).should be true end end describe "converts the argument to a string" do it 'calls output with a string' do expected_string = "123" argument = 123 subject.should_receive(:play_ssml).once.with(argument, {}) subject.should_receive(:output).once.with(:text, expected_string, {}).and_return true - subject.speak(argument) + subject.say(argument) end end end describe "#ssml_for" do @@ -309,11 +317,11 @@ string 'Please stand by' end end it 'returns SSML for a text argument' do - subject.ssml_for(prompt).should == ssml + subject.ssml_for(prompt).should be == ssml end it 'returns the same SSML passed in if it is SSML' do subject.ssml_for(ssml) == ssml end @@ -324,12 +332,18 @@ http_path = "http://adhearsion.com/sounds/hello.mp3" subject.detect_type(http_path).should be :audio end it "detects a file path" do - http_path = "/usr/shared/sounds/hello.mp3" - subject.detect_type(http_path).should be :audio + file_path = "file:///usr/shared/sounds/hello.mp3" + subject.detect_type(file_path).should be :audio + + absolute_path = "/usr/shared/sounds/hello.mp3" + subject.detect_type(absolute_path).should be :audio + + relative_path = "foo/bar" + subject.detect_type(relative_path).should_not be :audio end it "detects a Date object" do today = Date.today subject.detect_type(today).should be :time @@ -422,11 +436,11 @@ end expect_component_complete_event flexmock(Punchblock::Component::Output).new_instances.should_receive(:stop!) subject.should_receive(:execute_component_and_await_completion).once.with(output_component) - subject.stream_file(prompt, allowed_digits).should == '5' + subject.stream_file(prompt, allowed_digits).should be == '5' end end # describe #stream_file describe "#interruptible_play!" do @@ -443,12 +457,12 @@ subject.should_receive(:stream_file).once.and_return(2) subject.interruptible_play! output1, output2 end it 'raises an exception when output is unsuccessful' do - subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed" - expect { subject.interruptible_play!(non_existing) }.to raise_error(Adhearsion::PlaybackError) + 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 # describe interruptible_play! describe "#interruptible_play" do let(:output1) { "one two" } @@ -464,11 +478,11 @@ subject.should_receive(:interruptible_play!).once.and_return(2) subject.interruptible_play output1, output2 end it "should not raise an exception when output is unsuccessful" do - subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed" - lambda { subject.interruptible_play non_existing }.should_not raise_error(Adhearsion::PlaybackError) + subject.should_receive(:stream_file).once.and_raise Output::PlaybackError, "Output failed" + lambda { subject.interruptible_play non_existing }.should_not raise_error(Output::PlaybackError) end end # describe interruptible_play end end