Sha256: 30d6949b105ce712b04967cb3e1077a86b9993daebe9215f26d4f27ee082c83a

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

module Matest
  class NoExceptionRaised < RuntimeError; end
  class UnexpectedExceptionRaised < RuntimeError; end

  def capture_exception(exception_class=nil, &block)
    expected_exception = exception_class || BasicObject
    begin
      block.call
      if exception_class
        raise Matest::NoExceptionRaised.new("Expected '#{exception_class.inspect}' from the block, but none was raised.")
      else
        raise Matest::NoExceptionRaised.new("Expected an Exception from the block, but none was raised.")
      end
      false
    rescue Matest::NoExceptionRaised => e
      raise e
    rescue expected_exception => e
      e
    rescue BasicObject => e
      raise e
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matest-1.5.4 lib/matest/capture_exception.rb