class Spectroscope::Example

Example behavior.

This is the `it` in your specs.

Attributes

hooks[R]

Before and after advice.

label[R]

Description of example.

parent[R]

The parent testcase to which this test belongs.

procedure[R]

Test procedure, in which test assertions should be made.

tags[R]

List of identifying tags attached to example. These should be a list of Symbols, with an optional Symbol=>Object tail element.

Public Class Methods

new(options={}, &procedure) click to toggle source

Defines a specification procedure.

# File lib/spectroscope/example.rb, line 12
def initialize(options={}, &procedure)
  @parent = options[:parent]
  @label  = options[:label]
  @hooks  = options[:hooks]
  @skip   = options[:skip]
  @tags   = options[:tags]
  @keys   = options[:keys]
  @topic  = options[:topic]

  @procedure = procedure || lambda{ raise NotImplementedError } # pending

  @tested = false
end

Public Instance Methods

call() click to toggle source

Execute example.

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

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.

# File lib/spectroscope/example.rb, line 54
def keys
  Hash === tags.last ? tags.last : {}
end
Also aliased as: metadata
match?(match) click to toggle source

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.

# 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
    tags.include?(match.to_sym)
  end
end
metadata()

In RSpec data keys are called metadata.

Alias for: keys
scope() click to toggle source

The shared It::Scope from the parent.

# File lib/spectroscope/example.rb, line 123
def scope
  @scope ||= Scope.new(parent)
end
skip=(reason) click to toggle source

Set true to skip, or String to skip with reason.

# File lib/spectroscope/example.rb, line 86
def skip=(reason)
  @skip = reason
end
skip?() click to toggle source

Skip this spec?

# File lib/spectroscope/example.rb, line 79
def skip?
  @skip
end
tested=(boolean) click to toggle source
# File lib/spectroscope/example.rb, line 100
def tested=(boolean)
  @tested = !!boolean
end
tested?() click to toggle source
# File lib/spectroscope/example.rb, line 93
def tested?
  @tested
end
to_proc() click to toggle source

Example can be converted to a Proc object.

@return [Proc]

# File lib/spectroscope/example.rb, line 169
def to_proc
  lambda{ call }
end
to_s() click to toggle source

Return label string.

@return [String]

# File lib/spectroscope/example.rb, line 109
def to_s
  label.to_s
end
topic() click to toggle source

Ruby Test looks for `topic` as the desciption of the subject.

# File lib/spectroscope/example.rb, line 116
def topic
  @topic.to_s
end
type() click to toggle source

RubyTest supports `type` to describe the way in which the underlying framework represents tests.

# File lib/spectroscope/example.rb, line 72
def type
  'it'
end