Class: EventedSpec::SpecHelper::CoolioExample

Inherits:
EventedExample show all
Defined in:
lib/evented-spec/evented_example/coolio_example.rb

Overview

Evented example which is run inside of cool.io loop. See EventedExample details and method descriptions.

Constant Summary

Constants inherited from EventedExample

EventedExample::DEFAULT_OPTIONS

Instance Method Summary collapse

Methods inherited from EventedExample

#finish_example, #initialize, #run_hooks

Constructor Details

This class inherits a constructor from EventedSpec::SpecHelper::EventedExample

Instance Method Details

#delayed(delay = nil, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/evented-spec/evented_example/coolio_example.rb', line 54

def delayed(delay = nil, &block)
  timer = Coolio::TimerWatcher.new(delay.to_f, false)
  instance = self
  timer.on_timer do
    instance.instance_eval(&block)
  end
  timer.attach(default_loop)
  timer
end

#done(delay = nil, &block) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/evented-spec/evented_example/coolio_example.rb', line 38

def done(delay = nil, &block)
  @spec_timer.detach
  delayed(delay) do
    yield if block_given?
    finish_loop
  end
end

#finish_loopObject

Stops the loop and finalizes the example



47
48
49
50
51
# File 'lib/evented-spec/evented_example/coolio_example.rb', line 47

def finish_loop
  run_hooks :coolio_after
  default_loop.stop
  finish_example
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/evented-spec/evented_example/coolio_example.rb', line 14

def run
  reset
  delayed(0) do
    begin
      run_hooks :coolio_before
      @example_group_instance.instance_eval(&@block)
    rescue Exception => e
      @spec_exception ||= e
      done
    end
  end
  timeout(@opts[:spec_timeout]) if @opts[:spec_timeout]
  Coolio::DSL.run
end

#timeout(time = 1) ⇒ Object



30
31
32
33
34
35
# File 'lib/evented-spec/evented_example/coolio_example.rb', line 30

def timeout(time = 1)
  @spec_timer = delayed(time) do
    @spec_exception ||= SpecTimeoutExceededError.new("timed out")
    done
  end
end