Class: Bacon::FiberedContext

Inherits:
Context
  • Object
show all
Defined in:
lib/em-spec/bacon.rb

Constant Summary collapse

SpecTimeoutExceededError =
Class.new(RuntimeError)

Instance Method Summary collapse

Instance Method Details

#cancel_timerObject



57
58
59
# File 'lib/em-spec/bacon.rb', line 57

def cancel_timer
  EM.cancel_timer($_em_timer) if $_em_timer
end

#default_timeout(timeout) ⇒ Object



53
54
55
# File 'lib/em-spec/bacon.rb', line 53

def default_timeout(timeout)
  $_em_default_time_to_finish = timeout
end

#describe(*args, &block) ⇒ Object



78
79
80
81
82
83
# File 'lib/em-spec/bacon.rb', line 78

def describe(*args, &block)
  context = Bacon::FiberedContext.new(args.join(' '), &block)
  @before.each { |b| context.before(&b) }
  @after.each { |b| context.after(&b) }
  context.run
end

#done(succeed = true) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/em-spec/bacon.rb', line 85

def done(succeed = true)
  cancel_timer
  EM.next_tick{
    if succeed 
      :done.should == :done
    else
      should.flunk
    end
    $em_spec_fiber.resume if $em_spec_fiber
  }
end

#it(*args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/em-spec/bacon.rb', line 66

def it *args
  super{
    if block_given?
      if $_em_default_time_to_finish
        timeout($_em_default_time_to_finish)
      end
      yield
      Fiber.yield
    end
  }
end

#timeout(time_to_run) ⇒ Object



61
62
63
64
# File 'lib/em-spec/bacon.rb', line 61

def timeout(time_to_run)
  cancel_timer
  $_em_timer = EM.add_timer(time_to_run) { done(false) }
end