module AE::Check

The Ok mixin is a reusable assertion helper that makes it easy to construct parameterized assertions with an elegant syntax.

Constants

TABLE

Built-in check procedures.

Public Class Methods

define(name, &block) click to toggle source

Define a univerally available ok/no check.

AE::Check.define(:palindrome) do |x|
  x.reverse == x
end
# File lib/ae/check.rb, line 82
def self.define(name, &block)
  table[name] = Check::Proc.new(name, &block)
end
table() click to toggle source
# File lib/ae/check.rb, line 72
def self.table
  @table ||= TABLE.dup
end

Public Instance Methods

__check__() click to toggle source

Returns the current check.

# File lib/ae/check.rb, line 139
def __check__
  @__check__ || check_table[:equality]
end
check(name=nil, &block) click to toggle source

Define an ok/no check procedure. A one-off procedure is defined with a block.

check do |x, y|
  x == y
end

ok 1,1
no 1,2

The check method can also be used to define reusable checks.

check(:palindrome) do |x|
  x.reverse == x
end

This will also cause the current check to be set. Later in the code, the check procedure can be restored by just passing the symbolic name.

check :palindrome

ok 'abracarba'
no 'foolishness'
# File lib/ae/check.rb, line 116
def check(name=nil, &block)
  if name
    if block
      check_table[name] = Check::Proc.new(:name=>name, &block)
    end
    @__check__ = check_table[name]
  else
    #raise ArgumentError if block.arity == 0
    @__check__ = Check::Proc.new(&block)
  end
end
check_table() click to toggle source
# File lib/ae/check.rb, line 87
def check_table
  Check.table
end
no(*args) click to toggle source
# File lib/ae/check.rb, line 134
def no(*args)
  __check__.no!(*args)
end
ok(*args) click to toggle source
# File lib/ae/check.rb, line 129
def ok(*args)
  __check__.ok!(*args)
end