contrast / exceptional

exceptional / spec / exceptional_rescue_from_spec.rb
100644 41 lines (33 sloc) 1.224 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require File.dirname(__FILE__) + '/spec_helper'
require 'action_controller'
require File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integration', 'rails')
 
class MyException < Exception; end
class SpecialException < Exception; end
class RescueFromController < ActionController::Base
  rescue_from MyException, :with => :my_handler
  
  def my_handler
    return 'test'
  end
  
  def my_action
    raise MyException
  end
  
end
 
describe "Exceptional with rescue_from() support" do
  before(:each) do
    @controller = RescueFromController.new
  end
 
  it "should not call Exceptional" do
    @controller.should_receive(:rescue_action_without_exceptional).and_return(true)
    if Gem::Requirement.create(">=2.2.0").satisfied_by?(Gem.loaded_specs['rails'].version)
      Exceptional.should_not_receive(:handle)
    else
      Exceptional.should_receive(:handle)
    end
    @controller.send(:rescue_action, MyException.new("test")).should == true
  end
  
  it "should call Exceptional" do
    Exceptional.should_receive(:handle)
    @controller.should_receive(:rescue_action_without_exceptional).and_return(true)
    @controller.send(:rescue_action, SpecialException.new("test")).should == true
  end
  
end