Class: Spectroscope::Context
- Inherits:
-
Object
- Object
- Spectroscope::Context
- Defined in:
- lib/spectroscope/context.rb
Overview
This is the BDD form of a test case. It encapsulates a collection of examples.
This is the describe in your specs.
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
The before and after hooks.
-
#label ⇒ Object
readonly
A description of the describe clause.
-
#omits ⇒ Array<String,Proc>
readonly
Omit criteria.
-
#parent ⇒ Object
readonly
The parent context in which this describe resides.
-
#scope ⇒ Object
readonly
DSL module for evaluating
describeblocks. -
#skips ⇒ Array<String,Proc>
readonly
Skip critera.
-
#specs ⇒ Object
readonly
List of examples and sub-specifications.
-
#subject ⇒ Object
readonly
A target class, if any.
-
#tags ⇒ Object
readonly
Array and/or metadata Hash of tags.
Instance Method Summary collapse
-
#<<(spec) ⇒ Object
Add
itor sub-describeto group. -
#call ⇒ Object
Run before-all and after-all advice around yeilding to test runss.
-
#each(&block) ⇒ Object
Iterate over each test and subcase.
-
#evaluate(&block) ⇒ Object
Evalute a block of code in the context of the Context’s scope.
-
#initialize(settings = {}, &block) ⇒ Context
constructor
A test case
targetis a class or module. - #inspect ⇒ Object
-
#it_scope ⇒ Object
Shared runtime scope for specs.
-
#run(test, &block) ⇒ Object
Run test in the parent of this case.
-
#size ⇒ Object
Number of specs plus subcases.
- #skip=(reason) ⇒ Object
-
#skip? ⇒ Boolean
Skip this group?.
-
#to_s ⇒ Object
Returns the subject/label as string.
-
#type ⇒ Object
Ruby Test supports
typeto describe the nature of the underlying test system.
Constructor Details
#initialize(settings = {}, &block) ⇒ Context
A test case target is a class or module.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/spectroscope/context.rb', line 62 def initialize(settings={}, &block) @parent = settings[:parent] @subject = settings[:subject] @label = settings[:label] @tags = settings[:tags] #@skips = settings[:skips] #@hooks = settings[:hooks] if @parent @hooks = parent.hooks.clone @skips = parent.skips.clone @omits = parent.omits.clone else @hooks = Hooks.new @skips = [] @omits = [] end @specs = [] @scope = Scope.new(self) evaluate(&block) end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
The before and after hooks.
38 39 40 |
# File 'lib/spectroscope/context.rb', line 38 def hooks @hooks end |
#label ⇒ Object (readonly)
A description of the describe clause.
18 19 20 |
# File 'lib/spectroscope/context.rb', line 18 def label @label end |
#omits ⇒ Array<String,Proc> (readonly)
Omit criteria.
52 53 54 |
# File 'lib/spectroscope/context.rb', line 52 def omits @omits end |
#parent ⇒ Object (readonly)
The parent context in which this describe resides.
13 14 15 |
# File 'lib/spectroscope/context.rb', line 13 def parent @parent end |
#scope ⇒ Object (readonly)
DSL module for evaluating describe blocks.
57 58 59 |
# File 'lib/spectroscope/context.rb', line 57 def scope @scope end |
#skips ⇒ Array<String,Proc> (readonly)
Skip critera.
45 46 47 |
# File 'lib/spectroscope/context.rb', line 45 def skips @skips end |
#specs ⇒ Object (readonly)
List of examples and sub-specifications.
33 34 35 |
# File 'lib/spectroscope/context.rb', line 33 def specs @specs end |
#subject ⇒ Object (readonly)
A target class, if any.
23 24 25 |
# File 'lib/spectroscope/context.rb', line 23 def subject @subject end |
#tags ⇒ Object (readonly)
Array and/or metadata Hash of tags.
28 29 30 |
# File 'lib/spectroscope/context.rb', line 28 def @tags end |
Instance Method Details
#<<(spec) ⇒ Object
Add it or sub-describe to group.
118 119 120 |
# File 'lib/spectroscope/context.rb', line 118 def <<(spec) @specs << spec end |
#call ⇒ Object
Run before-all and after-all advice around yeilding to test runss.
133 134 135 136 137 |
# File 'lib/spectroscope/context.rb', line 133 def call hooks.run(self, :before, :all, it_scope) yield hooks.run(self, :after, :all, it_scope) end |
#each(&block) ⇒ Object
Iterate over each test and subcase.
125 126 127 |
# File 'lib/spectroscope/context.rb', line 125 def each(&block) specs.each(&block) end |
#evaluate(&block) ⇒ Object
Evalute a block of code in the context of the Context’s scope. When finished it iterates over omits and skips, removing and marks examples to be skipped respectively.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/spectroscope/context.rb', line 92 def evaluate(&block) @scope.module_eval(&block) specs.delete_if do |spec| omits.any?{ |reason, block| block.call(spec) } end specs.each do |spec| skips.each do |reason, block| if spec.match?(match) spec.skip = reason end end end end |
#inspect ⇒ Object
154 |
# File 'lib/spectroscope/context.rb', line 154 alias :inspect :to_s |
#it_scope ⇒ Object
Shared runtime scope for specs.
111 112 113 |
# File 'lib/spectroscope/context.rb', line 111 def it_scope @it_scope ||= Example::Scope.new(self) end |
#run(test, &block) ⇒ Object
Run test in the parent of this case.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/spectroscope/context.rb', line 183 def run(test, &block) #hooks[:before].each do |match, block| # next if Symbol == match # if test.match?(match) # scope.instance_exec(test, &block) #block.call(unit) # end #end block.call #hooks[:after].each do |match, block| # next if Symbol == match # if test.match?(match) # scope.instance_exec(test, &block) #block.call(unit) # end #end end |
#size ⇒ Object
Number of specs plus subcases.
142 143 144 |
# File 'lib/spectroscope/context.rb', line 142 def size specs.size end |
#skip=(reason) ⇒ Object
173 174 175 |
# File 'lib/spectroscope/context.rb', line 173 def skip=(reason) @skip = reason end |
#skip? ⇒ Boolean
Skip this group?
166 167 168 |
# File 'lib/spectroscope/context.rb', line 166 def skip? @skip end |
#to_s ⇒ Object
Returns the subject/label as string.
159 160 161 |
# File 'lib/spectroscope/context.rb', line 159 def to_s label.to_s end |
#type ⇒ Object
Ruby Test supports type to describe the nature of the underlying test system.
150 151 152 |
# File 'lib/spectroscope/context.rb', line 150 def type 'describe' end |