Sha256: 4a18e7cf9c310119468769c44291a78cd10d7308615486bc52f93151509f6b2e

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 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.
#

RSpec.describe Timers::Group do
	it "should fire several times" do
		result = []

		subject.every(0.7) { result << :a }
		subject.every(2.3) { result << :b }
		subject.every(1.3) { result << :c }
		subject.every(2.4) { result << :d }

		Timers::Wait.for(2.5) do |remaining|
			subject.wait if subject.wait_interval < remaining
		end

		expect(result).to be == [:a, :c, :a, :a, :b, :d]
	end

	it "should fire immediately and then several times later" do
		result = []

		subject.every(0.7) { result << :a }
		subject.every(2.3) { result << :b }
		subject.now_and_every(1.3) { result << :c }
		subject.now_and_every(2.4) { result << :d }

		Timers::Wait.for(2.5) do |remaining|
			subject.wait if subject.wait_interval < remaining
		end

		expect(result).to be == [:c, :d, :a, :c, :a, :a, :b, :d]
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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