spec/timers_spec.rb in timers-0.0.0 vs spec/timers_spec.rb in timers-1.0.0.pre

- old
+ new

@@ -1,23 +1,24 @@ require 'spec_helper' describe Timers do - Q = Timers::Timer::QUANTUM + # Level of accuracy enforced by the tests (50ms) + Q = 0.05 it "sleeps until the next timer" do - interval = 0.1 + interval = Q * 2 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 + 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 @@ -34,20 +35,19 @@ result.should == [:one, :two, :three] end describe "recurring timers" do - it "should continue to fire the timers at each interval" do + it "continues to fire the timers at each interval" do result = [] - subject.every(Q * 3) { result << :foo } + subject.every(Q * 2) { result << :foo } sleep Q * 3 subject.fire result.should == [:foo] - sleep Q * 3 - subject.fire + sleep Q * 5 subject.fire result.should == [:foo, :foo] end end end