module RSpec::EM::FakeClock

Public Class Methods

add_periodic_timer(seconds, proc = nil, &block) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 92
def self.add_periodic_timer(seconds, proc = nil, &block)
  timer(block || proc, seconds, true)
end
add_timer(seconds, proc = nil, &block) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 88
def self.add_timer(seconds, proc = nil, &block)
  timer(block || proc, seconds, false)
end
cancel_timer(timeout) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 96
def self.cancel_timer(timeout)
  clear_timeout(timeout)
end
clear_timeout(timeout) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 100
def self.clear_timeout(timeout)
  @schedule.delete(timeout)
end
now() click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 51
def self.now
  @call_time
end
reset() click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 55
def self.reset
  @current_time = Time.now
  @call_time    = @current_time
  @schedule     = Schedule.new
end
run(timeout) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 69
def self.run(timeout)
  @call_time = timeout.time
  timeout.block.call
  
  if timeout.repeat
    timeout.time += timeout.interval
    @schedule = Schedule.new(@schedule)
  else
    clear_timeout(timeout)
  end
end
tick(seconds) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 61
def self.tick(seconds)
  @current_time += seconds
  while timeout = @schedule.next_scheduled_at(@current_time)
    run(timeout)
  end
  @call_time = @current_time
end
timer(block, seconds, repeat) click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 81
def self.timer(block, seconds, repeat)
  timeout = Timeout.new(block, seconds, repeat)
  timeout.time = @call_time + seconds
  @schedule.add(timeout)
  timeout
end

Public Instance Methods

clock() click to toggle source
# File lib/rspec/eventmachine/fake_clock.rb, line 4
def clock
  API
end