Exception: Assertion

Inherits:
Exception
  • Object
show all
Extended by:
Assay::Assertable
Defined in:
lib/assay/assertion.rb

Overview

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

Constant Summary collapse

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.

13

Class Method Summary collapse

Methods included from Assay::Assertable

[], assert!, assert_message, assertive_name, assertor, fail?, operator, pass?, refute!, refute_message

Class Method Details

.by_name(name = nil) ⇒ Object

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



76
77
78
79
# 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) ⇒ Object

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



67
68
69
70
# 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) ⇒ Object

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



50
51
52
53
54
# File 'lib/assay/assertion.rb', line 50

def self.inherited(base)
  @@by_operator = nil
  @@by_name     = nil
  subclasses << base
end

.register(op, name = nil) ⇒ Object

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.



32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

.subclassesObject

List of all subclasses of Assertion.



59
60
61
# File 'lib/assay/assertion.rb', line 59

def self.subclasses
  @@subclasses ||= []
end