Module: Yadriggy::Assert
- Defined in:
- lib/yadriggy/assert.rb
Overview
Power assert by Yadriggy
Defined Under Namespace
Classes: AssertFailure, Reason
Class Method Summary collapse
-
.assert(&block) ⇒ Object
Checks the given assertion is correct and prints the result if the assertion fails.
-
.assertion(reason, block) ⇒ Object
Checks the given assertion is correct.
Class Method Details
.assert(&block) ⇒ Object
Checks the given assertion is correct and prints the result if the assertion fails.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yadriggy/assert.rb', line 13 def self.assert(&block) reason = Reason.new begin res = assertion(reason, block) puts_reason(reason) unless res return res rescue AssertFailure => evar puts_reason(evar.reason, evar) raise evar.cause end end |
.assertion(reason, block) ⇒ Object
Checks the given assertion is correct.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yadriggy/assert.rb', line 41 def self.assertion(reason, block) return if block.nil? ast = Yadriggy::reify(block) begin results = {} reason.setup(ast.tree.body, results) run_ast(ast.tree.body, block.binding, results)[1] rescue => evar raise AssertFailure.new(reason, evar., evar) end end |