Class: Citron::TestProc
- Inherits:
-
Object
- Object
- Citron::TestProc
- Defined in:
- lib/citron/test_proc.rb
Overview
Test procedure –what you would call a honest to goodness unit test.
Instance Attribute Summary collapse
-
#context ⇒ Object
(also: #parent)
readonly
The parent testcase to which this test belongs.
-
#label ⇒ Object
readonly
Description of test.
-
#procedure ⇒ Object
readonly
Test procedure, in which test assertions should be made.
-
#tags ⇒ Object
readonly
Symbol list of tags.
Instance Method Summary collapse
-
#call ⇒ Object
Run this test in context.
-
#for(scope) ⇒ Object
Return copy with ‘@scope` set.
-
#initialize(options = {}, &procedure) ⇒ TestProc
constructor
New unit test procedure.
-
#match?(match) ⇒ Boolean
Match test’s label and/or tags.
-
#skip=(reason) ⇒ Object
Set whether this test should be skipped of not.
-
#skip? ⇒ Boolean, String
Whether to skip this test.
-
#source_location ⇒ Object
Location of test definition.
- #tested=(boolean) ⇒ Object
- #tested? ⇒ Boolean
-
#to_s ⇒ String
Test description.
Constructor Details
#initialize(options = {}, &procedure) ⇒ TestProc
New unit test procedure.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/citron/test_proc.rb', line 9 def initialize(={}, &procedure) @context = [:context] @label = [:label] @tags = [:tags] @skip = [:skip] @file = [:file] @line = [:line] @procedure = procedure @tested = false end |
Instance Attribute Details
#context ⇒ Object (readonly) Also known as: parent
The parent testcase to which this test belongs.
26 27 28 |
# File 'lib/citron/test_proc.rb', line 26 def context @context end |
#label ⇒ Object (readonly)
Description of test.
36 37 38 |
# File 'lib/citron/test_proc.rb', line 36 def label @label end |
#procedure ⇒ Object (readonly)
Test procedure, in which test assertions should be made.
47 48 49 |
# File 'lib/citron/test_proc.rb', line 47 def procedure @procedure end |
#tags ⇒ Object (readonly)
Symbol list of tags. Trailing element may be Hash of ‘symbol => object`.
42 43 44 |
# File 'lib/citron/test_proc.rb', line 42 def @tags end |
Instance Method Details
#call ⇒ Object
Run this test in context.
145 146 147 148 149 |
# File 'lib/citron/test_proc.rb', line 145 def call @scope.setup @scope.instance_eval(&procedure) @scope.teardown end |
#for(scope) ⇒ Object
Return copy with ‘@scope` set.
154 155 156 157 |
# File 'lib/citron/test_proc.rb', line 154 def for(scope) @scope = scope self.dup end |
#match?(match) ⇒ Boolean
Match test’s label and/or tags.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/citron/test_proc.rb', line 129 def match?(match) case match when Symbol .include?(match) when Hash if Hash === .last .last.any?{ |k,v| match[k] == v } end else match === label end end |
#skip=(reason) ⇒ Object
Set whether this test should be skipped of not.
69 70 71 |
# File 'lib/citron/test_proc.rb', line 69 def skip=(reason) @skip = reason end |
#skip? ⇒ Boolean, String
Whether to skip this test.
61 |
# File 'lib/citron/test_proc.rb', line 61 def skip? ; @skip ; end |
#source_location ⇒ Object
Location of test definition.
117 118 119 |
# File 'lib/citron/test_proc.rb', line 117 def source_location [file, line] end |
#tested=(boolean) ⇒ Object
Is this necessary?
83 84 85 |
# File 'lib/citron/test_proc.rb', line 83 def tested=(boolean) @tested = !!boolean end |
#tested? ⇒ Boolean
Is this necessary?
76 77 78 |
# File 'lib/citron/test_proc.rb', line 76 def tested? @tested end |
#to_s ⇒ String
Test description.
92 93 94 |
# File 'lib/citron/test_proc.rb', line 92 def to_s label.to_s end |