Sha256: 3ffeb14d66482f2a1bba193940147cdfba8a6f4b55e340c4d5e45cc377debc4c

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require 'abstract_unit'

class WraithAttack < StandardError
end

class NuclearExplosion < StandardError
end

class MadRonon < StandardError
  attr_accessor :message
  
  def initialize(message)
    @message = message
    super()
  end
end

class Stargate
  attr_accessor :result

  include ActiveSupport::Rescuable

  rescue_from WraithAttack, :with => :sos

  rescue_from NuclearExplosion do
    @result = 'alldead'
  end
  
  rescue_from MadRonon do |e|
    @result = e.message
  end

  def dispatch(method)
    send(method)
  rescue Exception => e
    rescue_with_handler(e)
  end

  def attack
    raise WraithAttack
  end

  def nuke
    raise NuclearExplosion
  end

  def ronanize
    raise MadRonon.new("dex")
  end

  def sos
    @result = 'killed'
  end
end

class RescueableTest < Test::Unit::TestCase
  def setup
    @stargate = Stargate.new
  end

  def test_rescue_from_with_method
    @stargate.dispatch :attack
    assert_equal 'killed', @stargate.result
  end
  
  def test_rescue_from_with_block
    @stargate.dispatch :nuke
    assert_equal 'alldead', @stargate.result
  end
  
  def test_rescue_from_with_block_with_args
    @stargate.dispatch :ronanize
    assert_equal 'dex', @stargate.result
  end  
end

Version data entries

4 entries across 3 versions & 3 rubygems

Version Path
radiant-0.9.0.rc2 vendor/rails/activesupport/test/rescuable_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activesupport/test/rescuable_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/activesupport/test/rescuable_test.rb
recliner-0.0.1 vendor/activesupport/test/rescuable_test.rb