Class: Tiramisu::Unit
- Inherits:
-
Object
- Object
- Tiramisu::Unit
- Defined in:
- lib/tiramisu/unit.rb
Class Method Summary collapse
-
.context(label, &block) ⇒ Object
define a context inside current spec/context.
- .hooks ⇒ Object
- .inherited(base) ⇒ Object
- .run(test) ⇒ Object
-
.skip(reason = nil) ⇒ Object
skipping a whole spec/context.
- .spec ⇒ Object
-
.test(label, &block) ⇒ Object
(also: it, should)
define a test.
- .tests ⇒ Object
Instance Method Summary collapse
- #__run__(test, before, around, after) ⇒ Object
-
#skip(reason = nil) ⇒ Object
stop executing current test and mark it as skipped.
Class Method Details
.context(label, &block) ⇒ Object
define a context inside current spec/context.
74 75 76 77 |
# File 'lib/tiramisu/unit.rb', line 74 def context label, &block return unless block Tiramisu.define_and_register_a_context(label, block, self) end |
.hooks ⇒ Object
161 162 163 |
# File 'lib/tiramisu/unit.rb', line 161 def hooks @__tiramisu_hooks__ ||= {} end |
.inherited(base) ⇒ Object
61 62 63 |
# File 'lib/tiramisu/unit.rb', line 61 def inherited base base.instance_variable_set(:@__tiramisu_hooks__, Marshal.load(Marshal.dump(hooks))) end |
.run(test) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/tiramisu/unit.rb', line 178 def run test tests[test] || raise(StandardError, 'Undefined test %s at "%s"' % [test.inspect, __identity__]) catch :__tiramisu_status__ do allocate.__run__(tests[test], hooks[:before], hooks[:around], hooks[:after]) end end |
.skip(reason = nil) ⇒ Object
skipping a whole spec/context
174 175 176 |
# File 'lib/tiramisu/unit.rb', line 174 def skip reason = nil throw(:__tiramisu_skip__, Tiramisu::Skip.new(reason, caller[0])) end |
.spec ⇒ Object
65 66 67 |
# File 'lib/tiramisu/unit.rb', line 65 def spec raise(NotImplementedError, 'Nested specs not supported. Please use a context instead') end |
.test(label, &block) ⇒ Object Also known as: it, should
define a test
84 85 86 87 88 |
# File 'lib/tiramisu/unit.rb', line 84 def test label, &block return unless block tests[label] = Tiramisu.identity_string(:test, label, block) define_method(tests[label], &block) end |
.tests ⇒ Object
92 93 94 |
# File 'lib/tiramisu/unit.rb', line 92 def tests @__tiramisu_tests__ ||= {} end |
Instance Method Details
#__run__(test, before, around, after) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tiramisu/unit.rb', line 34 def __run__ test, before, around, after __send__(before) if before if around __send__(around, proc {__send__(test)}) else __send__(test) end __send__(after) if after __assertions__.each(&:__validate_expectations__) __objects__.each_key {|o| Tiramisu::Expectation.restore_object_status(o[:returned])} :__tiramisu_passed__ rescue Exception => e throw(:__tiramisu_status__, e) end |