Sha256: 3ba8421256062a88f81ce2035d5da1a1be79d8aad61036ca2b87977d4c8df988
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'spec_helper' describe Timers do Q = Timers::Timer::QUANTUM it "sleeps until the next timer" do interval = 0.1 started_at = Time.now fired = false subject.after(interval) { fired = true } subject.wait fired.should be_true (Time.now - started_at).should be_within(Q).of interval end it "it calculates the interval until the next timer should fire" do interval = 0.1 subject.after(interval) subject.wait_interval.should be_within(Q).of interval end it "fires timers in the correct order" do result = [] subject.after(Q * 2) { result << :two } subject.after(Q * 3) { result << :three } subject.after(Q * 1) { result << :one } sleep Q * 4 subject.fire result.should == [:one, :two, :three] end describe "recurring timers" do it "should continue to fire the timers at each interval" do result = [] subject.every(Q * 3) { result << :foo } sleep Q * 3 subject.fire result.should == [:foo] sleep Q * 3 subject.fire subject.fire result.should == [:foo, :foo] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timers-0.0.0 | spec/timers_spec.rb |