1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
module Kernel
# TODO: Should `#expect` method be part of standard?
# Executate a block asserting that a type of error will be raised.
#
# Presently this is not part of brass by default, as whether it should
# be is under debate. So this file must be required separately:
#
# require 'brass/expect'
#
def expect(error_class) #:yield:
begin
yield
assert(false, error_class, "#{error_class} expected but none thrown")
rescue error_class
assert(true)
rescue Exception => err
assert(false, error_class, "#{error_class} expected but #{err.class} was thrown")
end
end
end
|