Sha256: de30952114a6ec174e69a61de6e301f81043c2f4e62d275f9cc5fc7e7d805490

Contents?: true

Size: 719 Bytes

Versions: 3

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true
#
# This file is part of the "timers" project and released under the MIT license.
#
# Copyright, 2018, by Samuel Williams. All rights reserved.
#

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timers-4.3.0 spec/timers/wait_spec.rb
timers-4.2.1 spec/timers/wait_spec.rb
timers-4.2.0 spec/timers/wait_spec.rb