Module: AE::Check
- Included in:
- World
- Defined in:
- lib/ae/check.rb
Overview
The Ok mixin is a reusable assertion helper that makes it easy to construct parameterized assertions with an elegant syntax.
Defined Under Namespace
Classes: Proc
Constant Summary collapse
- TABLE =
Built-in check procedures.
{ :equality => Check::Proc.new(:message=>"should be equal"){|h| h.any?{|a,b| b==a}}, :case_equality => Check::Proc.new(:message=>"should be equal"){|h| h.any?{|a,b| b===a}} }
Class Method Summary collapse
-
.define(name, &block) ⇒ Object
Define a univerally available ok/no check.
- .table ⇒ Object
Instance Method Summary collapse
-
#__check__ ⇒ Object
Returns the current check.
-
#check(name = nil, &block) ⇒ Object
Define an ok/no check procedure.
- #check_table ⇒ Object
- #no(*args) ⇒ Object
- #ok(*args) ⇒ Object
Class Method Details
Instance Method Details
#__check__ ⇒ Object
Returns the current check.
139 140 141 |
# File 'lib/ae/check.rb', line 139 def __check__ @__check__ || check_table[:equality] end |
#check(name = nil, &block) ⇒ Object
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'
116 117 118 119 120 121 122 123 124 125 126 |
# 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 |
#no(*args) ⇒ Object
134 135 136 |
# File 'lib/ae/check.rb', line 134 def no(*args) __check__.no!(*args) end |
#ok(*args) ⇒ Object
129 130 131 |
# File 'lib/ae/check.rb', line 129 def ok(*args) __check__.ok!(*args) end |