class Assertion

Base class for all Assay classes. This class defines all the logic for assertions as exception classes as well as test assertion matchers.

Constants

SIZE_LIMIT

When displaying errors, use this as a rule of thumb for determining when the inspected object will be too big for a single line message.

Public Class Methods

by_name(name=nil) click to toggle source

If operator is not given, returns a hash table of assertion classes indexed by assertive name.

# File lib/assay/assertion.rb, line 76
def self.by_name(name=nil)
  return name_index.dup unless name
  name_index[name.to_sym]
end
by_operator(operator=nil) click to toggle source

If operator is not given, returns a hash table of assertion classes indexed by operator.

# File lib/assay/assertion.rb, line 67
def self.by_operator(operator=nil)
  return operator_index.dup unless operator
  operator_index[operator.to_sym]
end
inherited(base) click to toggle source

When Assertion is inherited, a list of all Assertion subclasses is kept. This can be used to assertions frameworks with dynamic implementations.

# File lib/assay/assertion.rb, line 50
def self.inherited(base)
  @@by_operator = nil
  @@by_name     = nil
  subclasses << base
end
new(msg=nil) click to toggle source

Setup new Assertion object.

Calls superclass method
# File lib/assay/assertion.rb, line 94
def initialize(msg=nil) #, *criteria, &block)
  super(msg)

  #@criteria  = criteria
  #@block     = block
  #@not       = false

  @assertion = true

  #options = (Hash === criteria.last ? criteria.pop : {})
  #set_backtrace(options[:backtrace]) if options[:backtrace]
  #set_negative(options[:negated])    if options[:negated]
end
register(op, name=nil) click to toggle source

Each new subclass must call the register method. This is not an option! The method must be called in order to add the class to the Assertion name and operator indicies, so they might be looked-up efficiently by other libraries.

# File lib/assay/assertion.rb, line 32
def self.register(op, name=nil)
  case op.to_s
  when /\W/
    @operator = op.to_sym
    @assertive_name = name.to_sym if name
  else
    @operator = (op.to_s + '?').to_sym
    @assertive_name = op.to_sym
  end

  operator_index[operator]   = self
  name_index[assertive_name] = self
end
subclasses() click to toggle source

List of all subclasses of Assertion.

# File lib/assay/assertion.rb, line 59
def self.subclasses
  @@subclasses ||= []
end

Private Class Methods

name_index() click to toggle source
# File lib/assay/assertion.rb, line 87
def self.name_index
  @@name_index ||= {}
end
operator_index() click to toggle source
# File lib/assay/assertion.rb, line 83
def self.operator_index
  @@operator_index ||= {}
end