class Spectroscope::Context
This is the BDD form of a test case. It encapsulates a collection of examples.
This is the `describe` in your specs.
Attributes
The before and after hooks.
A description of the describe clause.
Omit criteria.
@return [Array<String,Proc>]
The parent context in which this describe resides.
DSL
module for evaluating `describe` blocks.
Skip critera.
@return [Array<String,Proc>]
List of examples and sub-specifications.
A target class, if any.
Public Class Methods
A test case target
is a class or module.
# 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
Public Instance Methods
Add `it` or sub-`describe` to group.
# File lib/spectroscope/context.rb, line 118 def <<(spec) @specs << spec end
Run before-all and after-all advice around yeilding to test runss.
# 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
Iterate over each test and subcase.
# File lib/spectroscope/context.rb, line 125 def each(&block) specs.each(&block) end
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.
# 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
Shared runtime scope for specs.
# File lib/spectroscope/context.rb, line 111 def it_scope @it_scope ||= Example::Scope.new(self) end
Run test in the parent of this case.
@param [TestProc] test
The test unit to run.
# 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
Number of specs plus subcases.
# File lib/spectroscope/context.rb, line 142 def size specs.size end
# File lib/spectroscope/context.rb, line 173 def skip=(reason) @skip = reason end
Skip this group?
# File lib/spectroscope/context.rb, line 166 def skip? @skip end
Returns the subject/label as string.
# File lib/spectroscope/context.rb, line 159 def to_s label.to_s end
Ruby Test supports `type` to describe the nature of the underlying test system.
# File lib/spectroscope/context.rb, line 150 def type 'describe' end