From 9bdaf645f0038ecd22c152253be4f2f3c146f178 Mon Sep 17 00:00:00 2001 From: Luca Pradovera Date: Tue, 12 Nov 2013 10:23:22 +0100 Subject: [PATCH] Added test coverage for #stop_all_components --- spec/adhearsion/call_controller_spec.rb | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/adhearsion/call_controller_spec.rb b/spec/adhearsion/call_controller_spec.rb index 2cd0e09f2..3bf87a77a 100644 --- a/spec/adhearsion/call_controller_spec.rb +++ b/spec/adhearsion/call_controller_spec.rb @@ -289,6 +289,64 @@ def run end end + describe '#stop_all_components' do + let(:stop_controller) do + Class.new CallController do + attr_accessor :output1, :output2 + + def prep_output + @output1 = play! 'file://foo.wav' + @output2 = play! 'file://bar.wav' + end + + def run + stop_all_components + end + end + end + + subject { stop_controller.new call } + + before do + call.wrapped_object.stub(:write_and_await_response).and_return do |command| + command.request! + command.execute! + end + call.stub register_controller: nil + Events.should_receive(:trigger).with(:exception, Exception).never + subject.prep_output + end + + context "but not yet received a complete event" do + it "should terminate the components" do + subject.output1.should_receive(:stop!).once + subject.output2.should_receive(:stop!).once + + subject.exec + end + + context "and some fail to terminate" do + before { subject.output1.should_receive(:stop!).and_raise(Punchblock::Component::InvalidActionError) } + + it "should terminate the others" do + subject.output2.should_receive(:stop!).once + subject.exec + end + end + end + + context "when some have completed" do + before { subject.output1.trigger_event_handler Punchblock::Event::Complete.new } + + it "should not terminate the completed components" do + subject.output1.should_receive(:stop!).never + subject.output2.should_receive(:stop!).once + + subject.exec + end + end + end + describe "#write_and_await_response" do let(:message) { Punchblock::Command::Accept.new }