Sha256: e72541eba70f0f3d5be0a16056e2ce3be6de8186e5b1f3f381ab1dc2e5f3037a

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'example_helper'
require 'chatterbox/exception_notification'
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. rails init]))

ActionController::Routing::Routes.draw { |map| map.connect ':controller/:action/:id' }

class WidgetException < RuntimeError; end
class WidgetsController < ActionController::Base
  include Chatterbox::RailsCatcher

  def rescue_action e
    rescue_action_in_public e
  end
  
  def rescue_action_in_public_without_chatterbox e
    raise e
  end
  
  def index
    raise_exception
    render :text => "hi"
  end
  
  def raise_exception
    raise WidgetException, "Bad dog!"
  end
end

describe WidgetsController do
  
  describe "controller haxing" do
    it "chains the chatterbox method to rescue_action_in_public" do
      exception = RuntimeError.new
      @controller.expects(:rescue_action_in_public_without_chatterbox).with(exception)
      @controller.stubs(:extract_exception_details)
      @controller.rescue_action_in_public(exception)
    end
  
    it "should have the catcher included in ApplicationController" do
      WidgetsController.ancestors.should include(Chatterbox::RailsCatcher)
    end
    
    it "should hide aliased methods so they are not exposed as actions" do
      WidgetsController.hidden_actions.should include("rescue_action_in_public_with_chatterbox")
      WidgetsController.hidden_actions.should include("rescue_action_in_public_without_chatterbox")
    end
  end
  
  describe "exception handling" do
    it "should raise on index" do
      lambda {
        get :index
      }.should raise_error(WidgetException, "Bad dog!")
    end
    
    it "should send exception notice as hash" do
      Chatterbox.expects(:handle_notice).with(instance_of(Hash))
      get :index rescue nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chatterbox-0.5.1 examples/lib/chatterbox/rails_catcher_example.rb
chatterbox-0.5.0 examples/lib/chatterbox/rails_catcher_example.rb