spec/adhearsion/call_spec.rb in adhearsion-2.0.0.rc1 vs spec/adhearsion/call_spec.rb in adhearsion-2.0.0.rc2
- old
+ new
@@ -1,9 +1,15 @@
# encoding: utf-8
require 'spec_helper'
+class BrokenController < Adhearsion::CallController
+ def run
+ raise "Blat!"
+ end
+end
+
module Adhearsion
describe Call do
let(:mock_client) { flexmock('Client').tap(&:should_ignore_missing) }
let(:call_id) { rand }
@@ -115,10 +121,32 @@
response.should_receive(:call).once.with(event)
subject.on_end { |event| response.call event }
subject << event
end
end
+
+ context "when raising an exception" do
+ it "does not kill the call actor" do
+ subject.register_event_handler { |e| raise 'foo' }
+ lambda { subject << :foo }.should_not raise_error
+ sleep 1
+ subject.should be_alive
+ end
+
+ it 'passes the exception through the Events system' do
+ latch = CountDownLatch.new 1
+ Adhearsion::Events.exception do |e, l|
+ e.should be_a RuntimeError
+ l.should be subject.logger
+ latch.countdown!
+ end
+ subject.register_event_handler { |e| raise 'foo' }
+ lambda { subject << :foo }.should_not raise_error
+ latch.wait(3).should be true
+ Adhearsion::Events.clear_handlers :exception
+ end
+ end
end
describe "#<<" do
describe "with a Punchblock End" do
let :end_event do
@@ -602,9 +630,21 @@
it "should add the controller thread to the important threads" do
flexmock(CallController).should_receive(:exec)
controller_thread = subject.execute_controller mock_controller, latch
Adhearsion::Process.important_threads.should include controller_thread
+ end
+
+ it "should pass the exception to the events system" do
+ latch = CountDownLatch.new 1
+ Adhearsion::Events.exception do |e, l|
+ e.should be_a RuntimeError
+ l.should be subject.logger
+ latch.countdown!
+ end
+ subject.execute_controller BrokenController.new(subject), latch
+ latch.wait(3).should be true
+ Adhearsion::Events.clear_handlers :exception
end
end
describe "#register_controller" do
it "should add the controller to a list on the call" do