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

hooks[R]

The before and after hooks.

label[R]

A description of the describe clause.

omits[R]

Omit criteria.

@return [Array<String,Proc>]

parent[R]

The parent context in which this describe resides.

scope[R]

DSL module for evaluating `describe` blocks.

skips[R]

Skip critera.

@return [Array<String,Proc>]

specs[R]

List of examples and sub-specifications.

subject[R]

A target class, if any.

tags[R]

Array and/or metadata Hash of tags.

Public Class Methods

new(settings={}, &block) click to toggle source

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

<<(spec) click to toggle source

Add `it` or sub-`describe` to group.

# File lib/spectroscope/context.rb, line 118
def <<(spec)
  @specs << spec
end
call() { || ... } click to toggle source

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
each(&block) click to toggle source

Iterate over each test and subcase.

# File lib/spectroscope/context.rb, line 125
def each(&block)
  specs.each(&block)
end
evaluate(&block) click to toggle source

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
inspect()
Alias for: to_s
it_scope() click to toggle source

Shared runtime scope for specs.

# File lib/spectroscope/context.rb, line 111
def it_scope
  @it_scope ||= Example::Scope.new(self)
end
run(test, &block) click to toggle source

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
size() click to toggle source

Number of specs plus subcases.

# File lib/spectroscope/context.rb, line 142
def size
  specs.size
end
skip=(reason) click to toggle source
# File lib/spectroscope/context.rb, line 173
def skip=(reason)
  @skip = reason
end
skip?() click to toggle source

Skip this group?

# File lib/spectroscope/context.rb, line 166
def skip?
  @skip
end
to_s() click to toggle source

Returns the subject/label as string.

# File lib/spectroscope/context.rb, line 159
def to_s
  label.to_s
end
Also aliased as: inspect
type() click to toggle source

Ruby Test supports `type` to describe the nature of the underlying test system.

# File lib/spectroscope/context.rb, line 150
def type
  'describe'
end