Permalink
Browse files

Always raise errors when should_send_to_api? is false

  • Loading branch information...
1 parent f783f7c commit 33cba390ffa315bf717eb8af6f33b735e49a38a1 @jjb jjb committed Apr 29, 2012
Showing with 43 additions and 8 deletions.
  1. +8 −0 lib/exceptional/catcher.rb
  2. +3 −0 spec/dj_integration_spec.rb
  3. +32 −8 spec/exceptional/catcher_spec.rb
@@ -5,20 +5,28 @@ def handle_with_controller(exception, controller=nil, request=nil)
if Config.should_send_to_api?
data = ControllerExceptionData.new(exception, controller, request)
Remote.error(data)
+ else
+ raise exception
end
end
+ # unspeced
def handle_with_rack(exception, environment, request)
if Config.should_send_to_api?
data = RackExceptionData.new(exception, environment, request)
Remote.error(data)
+ else
+ raise exception
end
end
+ # unspeced
def handle(exception, name=nil)
if Config.should_send_to_api?
data = ExceptionData.new(exception, name)
Remote.error(data)
+ else
+ raise exception
end
end
end
@@ -21,6 +21,9 @@ class Worker
describe 'Delayed Job integration' do
before :each do
+ Exceptional::Config.stub!(:should_send_to_api?).and_return(true)
+ Exceptional.stub(:handle)
+
module Delayed
class Worker
def handle_failed_job(job, exception); end
@@ -1,13 +1,37 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Exceptional::Catcher do
- it "should create exception_data object and send json to the api" do
- Exceptional::Config.should_receive(:should_send_to_api?).and_return(true)
- exception = mock('exception')
- controller = mock('controller')
- request = mock('request')
- Exceptional::ControllerExceptionData.should_receive(:new).with(exception,controller,request).and_return(data = mock('exception_data'))
- Exceptional::Remote.should_receive(:error).with(data)
- Exceptional::Catcher.handle_with_controller(exception,controller,request)
+ describe "when Exceptional reporting is on" do
+ before do
+ Exceptional::Config.stub(:should_send_to_api?).and_return(true)
+ end
+ it "handle_with_controller should create exception_data object and send json to the api" do
+ exception = mock('exception')
+ controller = mock('controller')
+ request = mock('request')
+ Exceptional::ControllerExceptionData.should_receive(:new).with(exception,controller,request).and_return(data = mock('exception_data'))
+ Exceptional::Remote.should_receive(:error).with(data)
+ Exceptional::Catcher.handle_with_controller(exception,controller,request)
+ end
+ # it "handle_with_rack should create exception_data object and send json to the api"
+ # it "handle should create exception_data object and send json to the api"
+ end
+
+ describe "when Exceptional reporting is off" do
+ before do
+ Exceptional::Config.stub(:should_send_to_api?).and_return(false)
+ end
+ it "handle_with_controller should reraise the exception and not report it" do
+ exception = mock('exception')
+ controller = mock('controller')
+ request = mock('request')
+ Exceptional::ControllerExceptionData.should_not_receive(:new)
+ Exceptional::Remote.should_not_receive(:error)
+ expect{
+ Exceptional::Catcher.handle_with_controller(exception,controller,request)
+ }.to raise_error
+ end
+ # it "handle_with_rack should reraise the exception and not report it"
+ # it "handle should reraise the exception and not report it"
end
end

0 comments on commit 33cba39

Please sign in to comment.