Class: OSpec::ExampleGroup

Inherits:
Object show all
Defined in:
lib/ospec/example_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desc, parent) ⇒ ExampleGroup

Returns a new instance of ExampleGroup.



18
19
20
21
22
23
24
25
# File 'lib/ospec/example_group.rb', line 18

def initialize desc, parent
  @desc     = desc.to_s
  @parent   = parent
  @examples = []

  @before_hooks = []
  @after_hooks  = []
end

Class Method Details

.create(desc, block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/ospec/example_group.rb', line 9

def self.create desc, block
  group = self.new desc, @stack.last
  @example_groups << group

  @stack << group
  group.instance_eval &block
  @stack.pop
end

.example_groupsObject



4
5
6
# File 'lib/ospec/example_group.rb', line 4

def self.example_groups
  @example_groups
end

Instance Method Details

#after(type = :each, &block) ⇒ Object



39
40
41
42
# File 'lib/ospec/example_group.rb', line 39

def after type = :each, &block
  raise "unsupported after type: #{type}" unless type == :each
  @after_hooks << block
end

#after_hooksObject



48
49
50
# File 'lib/ospec/example_group.rb', line 48

def after_hooks
  @parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
end

#before(type = :each, &block) ⇒ Object



34
35
36
37
# File 'lib/ospec/example_group.rb', line 34

def before type = :each, &block
  raise "unsupported before type: #{type}" unless type == :each
  @before_hooks << block
end

#before_hooksObject



44
45
46
# File 'lib/ospec/example_group.rb', line 44

def before_hooks
  @parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
end

#descriptionObject



58
59
60
# File 'lib/ospec/example_group.rb', line 58

def description
  @parent ? "#{@parent.description} #{@desc}" : @desc
end

#it(desc, &block) ⇒ Object



27
28
29
# File 'lib/ospec/example_group.rb', line 27

def it desc, &block
  @examples << Example.new(self, desc, block)
end

#it_behaves_like(*objs) ⇒ Object



31
32
# File 'lib/ospec/example_group.rb', line 31

def it_behaves_like(*objs)
end

#run(runner) ⇒ Object



52
53
54
55
56
# File 'lib/ospec/example_group.rb', line 52

def run runner
  runner.example_group_started self
  @examples.each { |example| example.run runner }
  runner.example_group_finished self
end