class Spectroscope::Example
Example
behavior.
This is the `it` in your specs.
Attributes
Before and after advice.
Description of example.
The parent testcase to which this test belongs.
Test procedure, in which test assertions should be made.
Public Class Methods
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
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
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
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
The shared It::Scope from the parent.
# File lib/spectroscope/example.rb, line 123 def scope @scope ||= Scope.new(parent) end
Set true
to skip, or String to skip with reason.
# File lib/spectroscope/example.rb, line 86 def skip=(reason) @skip = reason end
Skip this spec?
# File lib/spectroscope/example.rb, line 79 def skip? @skip end
# File lib/spectroscope/example.rb, line 100 def tested=(boolean) @tested = !!boolean end
# File lib/spectroscope/example.rb, line 93 def tested? @tested end
Example
can be converted to a Proc object.
@return [Proc]
# File lib/spectroscope/example.rb, line 169 def to_proc lambda{ call } end
Return label string.
@return [String]
# File lib/spectroscope/example.rb, line 109 def to_s label.to_s end
Ruby Test looks for `topic` as the desciption of the subject.
# File lib/spectroscope/example.rb, line 116 def topic @topic.to_s end
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