spec/flipper/adapters/sync/interval_synchronizer_spec.rb in flipper-0.22.2 vs spec/flipper/adapters/sync/interval_synchronizer_spec.rb in flipper-0.23.0
- old
+ new
@@ -1,34 +1,33 @@
-require "helper"
require "flipper/adapters/sync/interval_synchronizer"
RSpec.describe Flipper::Adapters::Sync::IntervalSynchronizer do
let(:events) { [] }
- let(:synchronizer) { -> { events << described_class.now } }
+ let(:synchronizer) { -> { events << now } }
let(:interval) { 10 }
+ let(:now) { subject.send(:now) }
subject { described_class.new(synchronizer, interval: interval) }
it 'synchronizes on first call' do
expect(events.size).to be(0)
subject.call
expect(events.size).to be(1)
end
it "only invokes wrapped synchronizer every interval seconds" do
- now = described_class.now
subject.call
events.clear
# move time to one millisecond less than last sync + interval
1.upto(interval) do |i|
- allow(described_class).to receive(:now).and_return(now + i - 1)
+ allow(subject).to receive(:now).and_return(now + i - 1)
subject.call
end
expect(events.size).to be(0)
# move time to last sync + interval in milliseconds
- allow(described_class).to receive(:now).and_return(now + interval)
+ allow(subject).to receive(:now).and_return(now + interval)
subject.call
expect(events.size).to be(1)
end
end