Class: Specifier::Context
- Inherits:
-
Object
- Object
- Specifier::Context
- Defined in:
- lib/specifier/context.rb
Overview
Defines a context that can be deeply nested (evaluates from oldest to newest in ancestry).
Usage:
let "..." do
# ...
end
it "..." do
# ...
end
describe "..." do
end
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#description ⇒ Object
Returns the value of attribute description.
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #describe(description, &block) ⇒ Object
-
#initialize(description, &block) ⇒ Context
constructor
A new instance of Context.
- #it(description, &block) ⇒ Object
- #let(name, &block) ⇒ Object
- #run ⇒ Object
- #setup(example) ⇒ Object
Constructor Details
#initialize(description, &block) ⇒ Context
Returns a new instance of Context.
31 32 33 34 35 36 37 |
# File 'lib/specifier/context.rb', line 31 def initialize(description, &block) @description = description @block = block @children = [] @examples = [] @definitions = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
20 21 22 |
# File 'lib/specifier/context.rb', line 20 def children @children end |
#description ⇒ Object
Returns the value of attribute description.
21 22 23 |
# File 'lib/specifier/context.rb', line 21 def description @description end |
#parent ⇒ Object
Returns the value of attribute parent.
19 20 21 |
# File 'lib/specifier/context.rb', line 19 def parent @parent end |
Class Method Details
.setup(description, parent = nil, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/specifier/context.rb', line 23 def self.setup(description, parent = nil, &block) context = Context.new(description, &block) context.parent = parent parent.children << context if parent context.instance_eval(&block) context end |
Instance Method Details
#describe(description, &block) ⇒ Object
39 40 41 |
# File 'lib/specifier/context.rb', line 39 def describe(description, &block) self.class.setup(description, self, &block) end |
#it(description, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/specifier/context.rb', line 49 def it(description, &block) example = Example.new(description, &block) @examples << example example end |
#let(name, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/specifier/context.rb', line 43 def let(name, &block) definition = Definition.new(name, &block) @definitions << definition definition end |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/specifier/context.rb', line 55 def run Specifier.formatter.context(self) do @examples.each do |example| setup(example) result = example.run Specifier.formatter.record(example, result) end @children.each(&:run) end end |
#setup(example) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/specifier/context.rb', line 66 def setup(example) parent&.setup(example) @definitions.each do |definition| definition.define(example) end end |