class ThrowAssay

Assertion for catching specific throws.

Public Class Methods

assert_message(symbol) click to toggle source
# File lib/assay/throw_assay.rb, line 84
def self.assert_message(symbol)
  s = symbol.inspect
  "throw #{s}"
end
fail?(symbol=nil) { || ... } click to toggle source

Passes if the block does not throw given symbol.

ThrowAssay.fail? :done do
  throw :chimp
end

If no symbol is given then passes if nothing is thrown. But note that in ‘#refute!`, the symbol must be `nil` rather than not given.

# File lib/assay/throw_assay.rb, line 56
def self.fail?(symbol=nil) #:yield:
  if symbol
    pass = false
    catch(symbol) do
      begin
        yield
      rescue ArgumentError => err     # 1.9 exception
        #msg += ", not #{err.message.split(/ /).last}"
      rescue NameError => err         # 1.8 exception
        #msg += ", not #{err.name.inspect}"
      end
      pass = true
    end
  else
    pass = false
    begin
      yield
      pass = true
    rescue ArgumentError => error
      pass = true if /\Auncaught throw (.+)\z/ !~ error.message
    end
  end
  pass
end
pass?(symbol=nil) { || ... } click to toggle source

Passes if the block throws given symbol.

ThrowAssay.pass? :done do
  throw :done
end

If no symbol is given than passes if any is thrown. But note that in ‘#assert!`, the symbol must be `nil` rather than not given.

# File lib/assay/throw_assay.rb, line 22
def self.pass?(symbol=nil) #:yield:
  pass = true
  if symbol
    catch(symbol) do
      begin
        yield
      rescue ArgumentError => err     # 1.9 exception
        #msg += ", not #{err.message.split(/ /).last}"
      rescue NameError => err         # 1.8 exception
        #msg += ", not #{err.name.inspect}"
      end
      pass = false
    end
  else
    begin
      yield
      pass = false
    rescue ArgumentError => error
      pass = false if /\Auncaught throw (.+)\z/ !~ error.message
    end
  end
  pass
end