Module: AE::Assert

Included in:
Object
Defined in:
lib/ae/assert.rb

Overview

The Assert module is simple a conatiner module for the core extension methods: #assert, #expect, etc.

This module is included directory into the Object class.

Instance Method Summary collapse

Instance Method Details

#assert(*args, &block) ⇒ Assertor

Assert a operational relationship.

4.assert == 3

If only a single test argument is given then #assert simply validates that it evalutate to true. An optional message argument can be given in this case which will be used instead of the deafult message.

assert(4==3, "not the same thing")

In block form, #assert ensures the block evalutes truthfully, i.e. not as nil or false.

assert{ 4==3 }

Returns:



28
29
30
# File 'lib/ae/assert.rb', line 28

def assert(*args, &block)
  Assertor.new(self, :backtrace=>caller).assert(*args, &block)
end

#assert=(cmp) ⇒ Assertor

Same as ‘object.assert == other’.

Returns:



35
36
37
# File 'lib/ae/assert.rb', line 35

def assert=(cmp)
  Assertor.new(self, :backtrace=>caller).assert == cmp
end

#flunk(message = nil, backtrace = nil) ⇒ Object

Directly raise an Assertion failure.

Parameters:

  • message (String) (defaults to: nil)

    Error message.

  • backtrace (String) (defaults to: nil)

    Backtrace, used to pass up an error from lower in the stack.

Raises:

  • (Assertion)

    Assertion error with given ‘message`.



75
76
77
78
# File 'lib/ae/assert.rb', line 75

def flunk(message=nil, backtrace=nil)
  #Assertor.new(self, :backtrace=>caller).assert(false, message)
  Assertor.assert(false, message, backtrace || caller)
end

#refute(*args, &block) ⇒ Assertor Also known as: assert!

Opposite of assert.

4.refute == 4  #=> Assertion Error

Returns:



44
45
46
# File 'lib/ae/assert.rb', line 44

def refute(*args, &block)
  Assertor.new(self, :backtrace=>caller).not.assert(*args, &block)
end

#refute=(cmp) ⇒ Assertor

Same as ‘object.refute == other’.

Returns:



51
52
53
# File 'lib/ae/assert.rb', line 51

def refute=(cmp)
  Assertor.new(self, :backtrace=>caller).not.assert == cmp
end