Module: Kernel
- Defined in:
- lib/tiramisu/core_ext.rb
Instance Method Summary collapse
-
#assert(*labels, &block) ⇒ Object
when used out of tests it defines a assertion helper.
-
#fail(*reason) ⇒ Object
stop executing any code and report a failure.
-
#spec(label = (noargs=true; nil), &block) ⇒ Object
when called with a no-nil no-false argument it defines, register and returns a spec.
Instance Method Details
#assert(*labels, &block) ⇒ Object
when used out of tests it defines a assertion helper. the block should return a no-false no-nil value for assertion to pass. the block will receive tested object as first argument and any arguments passed to assertion as consequent ones. it will also receive the passed block.
86 87 88 89 90 |
# File 'lib/tiramisu/core_ext.rb', line 86 def assert *labels, &block labels.any? || raise(ArgumentError, 'Wrong number of arguments, 0 for 1+') block || raise(ArgumentError, 'missing block') labels.each {|label| Tiramisu.assertions[label.to_sym] = block} end |
#fail(*reason) ⇒ Object
stop executing any code and report a failure
99 100 101 102 |
# File 'lib/tiramisu/core_ext.rb', line 99 def fail *reason reason.empty? && raise(ArgumentError, 'Wrong number or arguments, 0 for 1+') Tiramisu.fail(reason.flatten, caller[0]) end |
#spec(label = (noargs=true; nil), &block) ⇒ Object
a Unit Module is a regular Ruby Module that when included will execute the Unit’s block on base
when called with a no-nil no-false argument it defines, register and returns a spec. when called with a nil or false argument it defines and returns a spec but does not register it. when called without arguments it defines a global setup that will run on each new created spec/context.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tiramisu/core_ext.rb', line 32 def spec label = (noargs=true; nil), &block block || raise(ArgumentError, 'missing block') if noargs # no arguments given, defining a global setup and returning Tiramisu::GLOBAL_SETUPS.include?(block) || Tiramisu::GLOBAL_SETUPS.push(block) return end if label # a no-nil no-false argument given, defining a regular spec Tiramisu.define_and_register_a_spec(label, block) end # defining a shared spec that wont run itself # but can be included in another specs/contexts Tiramisu.define_unit_module(block) end |