Exception: AE::Assertion

Inherits:
Exception show all
Defined in:
lib/ae/assertion.rb

Overview

The Assertion class is simply a subclass of Exception that is used by AE as the default error raised when an assertion fails.

"The reserve of modern assertions is sometimes pushed to extremes,
 in which the fear of being contradicted leads the writer to strip
 himself of almost all sense and meaning."
                           -- Sir Winston Churchill (1874 - 1965)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Exception

#negative?, raised?, #set_assertion, #set_negative

Constructor Details

#initialize(message = nil, options = {}) ⇒ Assertion

New assertion (failure).

Parameters:

  • message (String) (defaults to: nil)

    the failure message

  • options (Hash) (defaults to: {})

    options such as :backtrace



27
28
29
30
31
32
# File 'lib/ae/assertion.rb', line 27

def initialize(message=nil, options={})
  super(message)
  backtrace = options[:backtrace]
  set_backtrace(backtrace) if backtrace
  set_assertion(true)
end

Class Method Details

.countsObject

Deprecated.

This will be removed in favor of ‘AE::Assertor.counts`.



18
19
20
# File 'lib/ae/assertion.rb', line 18

def self.counts
  AE::Assertor.counts
end

Instance Method Details

#assertion?Boolean

Technically any object that affirmatively responds to #assertion? can be taken to be an Assertion. This makes it easier for various libraries to work together without having to depend upon a common Assertion base class.

Returns:

  • (Boolean)


38
39
40
# File 'lib/ae/assertion.rb', line 38

def assertion?
  true
end

#to_sString

Parents error message prefixed with “(assertion)”.

Returns:

  • (String)

    error message



45
46
47
# File 'lib/ae/assertion.rb', line 45

def to_s
  '(assertion) ' + super
end