Class: OSpec::Example

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, desc, block) ⇒ Example

Returns a new instance of Example.



5
6
7
8
9
# File 'lib/ospec/example.rb', line 5

def initialize(group, desc, block)
  @example_group = group
  @description   = desc
  @__block__     = block
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/ospec/example.rb', line 3

def description
  @description
end

#example_groupObject (readonly)

Returns the value of attribute example_group.



3
4
5
# File 'lib/ospec/example.rb', line 3

def example_group
  @example_group
end

#exceptionObject (readonly)

Returns the value of attribute exception.



3
4
5
# File 'lib/ospec/example.rb', line 3

def exception
  @exception
end

Instance Method Details

#run(runner) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ospec/example.rb', line 23

def run runner
  begin
    runner.example_started self
    run_before_hooks
    instance_eval &@__block__
  rescue => e
    @exception = e
  ensure
    begin
      run_after_hooks
    rescue => e
      @exception = e
    end
  end

  if @exception
    runner.example_failed self
  else
    runner.example_passed self
  end
end

#run_after_hooksObject



17
18
19
20
21
# File 'lib/ospec/example.rb', line 17

def run_after_hooks
  @example_group.after_hooks.each do |after|
    instance_eval &after
  end
end

#run_before_hooksObject



11
12
13
14
15
# File 'lib/ospec/example.rb', line 11

def run_before_hooks
  @example_group.before_hooks.each do |before|
    instance_eval &before
  end
end