Sha256: b329a4e98abe1341c22f7d1587015ef233514cdd4fe735b4400963343f6da472
Contents?: true
Size: 667 Bytes
Versions: 1
Compression:
Stored size: 667 Bytes
Contents
# frozen_string_literal: true module Gumball describe Dispenser do def now Time.now.to_i end it "lives for a bit, and then refreshes" do ttl = 5 data = described_class.new(ttl) { now }.on_change { |_, nv| @about = {new_value: nv, now: now} } data.item # this "primes" it n = now 5.times { expect(data.item).to be <= n } expect(@about).to be nil sleep ttl - 1 5.times { expect(data.item).to be <= n } expect(@about).to be nil sleep 2 5.times { expect(data.item).to be > n } expect(@about[:new_value]).to eq data.item expect(@about[:now]).to be > n end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gumball-0.0.1 | spec/dispenser_spec.rb |