Sha256: 6e7599f5cb38a5082e2126d700dcfb8070c2f064c15d227d3e8210207c096790

Contents?: true

Size: 660 Bytes

Versions: 15

Compression:

Stored size: 660 Bytes

Contents

module Matest
  class NoExceptionRaised < RuntimeError; end
  class UnexpectedExceptionRaised < RuntimeError; end
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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
matest-1.7.4 lib/matest/capture_exception.rb
matest-1.7.3 lib/matest/capture_exception.rb
matest-1.7.2 lib/matest/capture_exception.rb
matest-1.7.1 lib/matest/capture_exception.rb
matest-1.7.0 lib/matest/capture_exception.rb
matest-1.6.9 lib/matest/capture_exception.rb
matest-1.6.6 lib/matest/capture_exception.rb
matest-1.6.5 lib/matest/capture_exception.rb
matest-1.6.4 lib/matest/capture_exception.rb
matest-1.6.3 lib/matest/capture_exception.rb
matest-1.6.2 lib/matest/capture_exception.rb
matest-1.6.1 lib/matest/capture_exception.rb
matest-1.6.0 lib/matest/capture_exception.rb
matest-1.5.6 lib/matest/capture_exception.rb
matest-1.5.5 lib/matest/capture_exception.rb