Class: Spectroscope::Example
- Inherits:
-
Object
- Object
- Spectroscope::Example
- Defined in:
- lib/spectroscope/example.rb
Overview
Example behavior.
This is the ‘it` in your specs.
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Before and after advice.
-
#label ⇒ Object
readonly
Description of example.
-
#parent ⇒ Object
readonly
The parent testcase to which this test belongs.
-
#procedure ⇒ Object
readonly
Test procedure, in which test assertions should be made.
-
#tags ⇒ Object
readonly
List of identifying tags attached to example.
Instance Method Summary collapse
-
#call ⇒ Object
Execute example.
-
#initialize(options = {}, &procedure) ⇒ Example
constructor
Defines a specification procedure.
-
#keys ⇒ Object
(also: #metadata)
A map of Symbol => Object, which is taken from the end of ‘tags`.
-
#match?(match) ⇒ Boolean
If
match
is a Regexp or String, match against label. -
#scope ⇒ Object
The shared It::Scope from the parent.
-
#skip=(reason) ⇒ Object
Set
true
to skip, or String to skip with reason. -
#skip? ⇒ Boolean
Skip this spec?.
- #tested=(boolean) ⇒ Object
- #tested? ⇒ Boolean
-
#to_proc ⇒ Proc
Example can be converted to a Proc object.
-
#to_s ⇒ String
Return label string.
-
#topic ⇒ Object
Ruby Test looks for ‘topic` as the desciption of the subject.
-
#type ⇒ Object
RubyTest supports ‘type` to describe the way in which the underlying framework represents tests.
Constructor Details
#initialize(options = {}, &procedure) ⇒ Example
Defines a specification procedure.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spectroscope/example.rb', line 12 def initialize(={}, &procedure) @parent = [:parent] @label = [:label] @hooks = [:hooks] @skip = [:skip] @tags = [:tags] @keys = [:keys] @topic = [:topic] @procedure = procedure || lambda{ raise NotImplementedError } # pending @tested = false end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
Before and after advice.
36 37 38 |
# File 'lib/spectroscope/example.rb', line 36 def hooks @hooks end |
#label ⇒ Object (readonly)
Description of example.
41 42 43 |
# File 'lib/spectroscope/example.rb', line 41 def label @label end |
#parent ⇒ Object (readonly)
The parent testcase to which this test belongs.
31 32 33 |
# File 'lib/spectroscope/example.rb', line 31 def parent @parent end |
#procedure ⇒ Object (readonly)
Test procedure, in which test assertions should be made.
66 67 68 |
# File 'lib/spectroscope/example.rb', line 66 def procedure @procedure end |
#tags ⇒ Object (readonly)
List of identifying tags attached to example. These should be a list of Symbols, with an optional Symbol=>Object tail element.
47 48 49 |
# File 'lib/spectroscope/example.rb', line 47 def @tags end |
Instance Method Details
#call ⇒ Object
Execute example.
156 157 158 159 160 161 162 |
# File 'lib/spectroscope/example.rb', line 156 def call parent.run(self) do hooks.run(self, :before, :each, scope) #if hooks scope.instance_exec(&procedure) # TODO: can it take any argument(s) ? hooks.run(self, :after, :each, scope) #if hooks end end |
#keys ⇒ Object Also known as: metadata
A map of Symbol => Object, which is taken from the end of ‘tags`. Unlike tags, keys allow key-value relationships, rather than just symbolic names.
54 55 56 |
# File 'lib/spectroscope/example.rb', line 54 def keys Hash === .last ? .last : {} end |
#match?(match) ⇒ Boolean
If match
is a Regexp or String, match against label. If match
is a Hash, match against keys. If match
is a Symbol, match against tags.
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/spectroscope/example.rb', line 142 def match?(match) case match when Regexp, String match === label when Hash match.any?{ |k,m| m === keys[k] } else .include?(match.to_sym) end end |
#scope ⇒ Object
The shared It::Scope from the parent.
123 124 125 |
# File 'lib/spectroscope/example.rb', line 123 def scope @scope ||= Scope.new(parent) end |
#skip=(reason) ⇒ Object
Set true
to skip, or String to skip with reason.
86 87 88 |
# File 'lib/spectroscope/example.rb', line 86 def skip=(reason) @skip = reason end |
#skip? ⇒ Boolean
Skip this spec?
79 80 81 |
# File 'lib/spectroscope/example.rb', line 79 def skip? @skip end |
#tested=(boolean) ⇒ Object
100 101 102 |
# File 'lib/spectroscope/example.rb', line 100 def tested=(boolean) @tested = !!boolean end |
#tested? ⇒ Boolean
93 94 95 |
# File 'lib/spectroscope/example.rb', line 93 def tested? @tested end |
#to_proc ⇒ Proc
Example can be converted to a Proc object.
169 170 171 |
# File 'lib/spectroscope/example.rb', line 169 def to_proc lambda{ call } end |
#to_s ⇒ String
Return label string.
109 110 111 |
# File 'lib/spectroscope/example.rb', line 109 def to_s label.to_s end |
#topic ⇒ Object
Ruby Test looks for ‘topic` as the desciption of the subject.
116 117 118 |
# File 'lib/spectroscope/example.rb', line 116 def topic @topic.to_s end |
#type ⇒ Object
RubyTest supports ‘type` to describe the way in which the underlying framework represents tests.
72 73 74 |
# File 'lib/spectroscope/example.rb', line 72 def type 'it' end |