1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
require 'spec_helper'
require 'timers/wait'
RSpec.describe Timers::Wait do
it "repeats until timeout expired" do
timeout = Timers::Wait.new(5)
count = 0
timeout.while_time_remaining do |remaining|
expect(remaining).to be_within(TIMER_QUANTUM).of (timeout.duration - count)
count += 1
sleep 1
end
expect(count).to eq(5)
end
it "yields results as soon as possible" do
timeout = Timers::Wait.new(5)
result = timeout.while_time_remaining do |remaining|
break :done
end
expect(result).to eq(:done)
end
end
|