class RescueAssay

Assert that a kind of exception class is rescued from the execution of a block.

Public Class Methods

assert_message(*exceptions) click to toggle source
# File lib/assay/rescue_assay.rb, line 44
def self.assert_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "raise #{exp}" #, but was #{err} instead."
end
fail?(*exceptions) { || ... } click to toggle source

Check negated assertion.

# File lib/assay/rescue_assay.rb, line 28
def self.fail?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    true
  rescue Exception => e
    !exceptions.any? do |x|
      x === e
    end
  end
end
pass?(*exceptions) { || ... } click to toggle source

Check assertion.

# File lib/assay/rescue_assay.rb, line 13
def self.pass?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    false
  rescue Exception => e
    exceptions.any? do |x|
      x === e
    end
  end
end
refute_message(*exceptions) click to toggle source
# File lib/assay/rescue_assay.rb, line 50
def self.refute_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "! raise #{exp}" #, but was #{err} instead."
end