Class: Polyrun::Quick::ExampleGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrun/quick/example_group.rb

Overview

One describe block (possibly nested). Holds it / test examples and hooks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent: nil) ⇒ ExampleGroup

Returns a new instance of ExampleGroup.



7
8
9
10
11
12
13
14
15
16
# File 'lib/polyrun/quick/example_group.rb', line 7

def initialize(name, parent: nil)
  @name = name.to_s
  @parent = parent
  @children = []
  @examples = []
  @before_hooks = []
  @after_hooks = []
  @lets = {}
  @let_bang_order = []
end

Instance Attribute Details

#after_hooksObject (readonly)

Returns the value of attribute after_hooks.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def after_hooks
  @after_hooks
end

#before_hooksObject (readonly)

Returns the value of attribute before_hooks.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def before_hooks
  @before_hooks
end

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def children
  @children
end

#examplesObject (readonly)

Returns the value of attribute examples.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def examples
  @examples
end

#let_bang_orderObject (readonly)

Returns the value of attribute let_bang_order.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def let_bang_order
  @let_bang_order
end

#letsObject (readonly)

Returns the value of attribute lets.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def lets
  @lets
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/polyrun/quick/example_group.rb', line 5

def parent
  @parent
end

Instance Method Details

#after(&block) ⇒ Object



41
42
43
# File 'lib/polyrun/quick/example_group.rb', line 41

def after(&block)
  @after_hooks << block
end

#before(&block) ⇒ Object



37
38
39
# File 'lib/polyrun/quick/example_group.rb', line 37

def before(&block)
  @before_hooks << block
end

#describe(name, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/polyrun/quick/example_group.rb', line 24

def describe(name, &block)
  child = ExampleGroup.new(name, parent: self)
  @children << child
  child.instance_eval(&block) if block
  child
end

#each_example_with_ancestors(ancestors = [], &visitor) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/polyrun/quick/example_group.rb', line 55

def each_example_with_ancestors(ancestors = [], &visitor)
  chain = ancestors + [self]
  @examples.each do |desc, block|
    visitor.call(chain, desc, block)
  end
  @children.each do |child|
    child.each_example_with_ancestors(chain, &visitor)
  end
end

#full_nameObject



18
19
20
21
22
# File 'lib/polyrun/quick/example_group.rb', line 18

def full_name
  return @name if parent.nil?

  "#{parent.full_name} #{@name}".strip
end

#it(description, &block) ⇒ Object Also known as: test



31
32
33
# File 'lib/polyrun/quick/example_group.rb', line 31

def it(description, &block)
  @examples << [description.to_s, block]
end

#let(name, &block) ⇒ Object



45
46
47
# File 'lib/polyrun/quick/example_group.rb', line 45

def let(name, &block)
  @lets[name.to_sym] = block
end

#let!(name, &block) ⇒ Object



49
50
51
52
53
# File 'lib/polyrun/quick/example_group.rb', line 49

def let!(name, &block)
  sym = name.to_sym
  @lets[sym] = block
  @let_bang_order << sym
end