Sha256: 5402c7a76028583666f5d0409940a791f09e6f3d30e37cdd0c26da89a8026f14

Contents?: true

Size: 1.27 KB

Versions: 20

Compression:

Stored size: 1.27 KB

Contents

require "flipper/poller"

RSpec.describe Flipper::Poller do
  let(:remote_adapter) { Flipper::Adapters::Memory.new }
  let(:remote) { Flipper.new(remote_adapter) }
  let(:local) { Flipper.new(subject.adapter) }

  subject do
    described_class.new(
      remote_adapter: remote_adapter,
      start_automatically: false,
      interval: Float::INFINITY
    )
  end

  before do
    allow(subject).to receive(:loop).and_yield # Make loop just call once
    allow(subject).to receive(:sleep)          # Disable sleep
    allow(Thread).to receive(:new).and_yield   # Disable separate thread
  end

  describe "#adapter" do
    it "always returns same memory adapter instance" do
      expect(subject.adapter).to be_a(Flipper::Adapters::Memory)
      expect(subject.adapter.object_id).to eq(subject.adapter.object_id)
    end
  end

  describe "#sync" do
    it "syncs remote adapter to local adapter" do
      remote.enable :polling

      expect(local.enabled?(:polling)).to be(false)
      subject.sync
      expect(local.enabled?(:polling)).to be(true)
    end
  end

  describe "#start" do
    it "starts the poller thread" do
      expect(Thread).to receive(:new).and_yield
      expect(subject).to receive(:loop).and_yield
      expect(subject).to receive(:sync)
      subject.start
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
flipper-1.3.2 spec/flipper/poller_spec.rb
flipper-1.3.1 spec/flipper/poller_spec.rb
flipper-1.3.0 spec/flipper/poller_spec.rb
flipper-1.3.0.pre spec/flipper/poller_spec.rb
flipper-1.2.2 spec/flipper/poller_spec.rb
flipper-1.2.1 spec/flipper/poller_spec.rb
flipper-1.2.0 spec/flipper/poller_spec.rb
flipper-1.1.2 spec/flipper/poller_spec.rb
flipper-1.1.1 spec/flipper/poller_spec.rb
flipper-1.1.0 spec/flipper/poller_spec.rb
flipper-1.0.0 spec/flipper/poller_spec.rb
flipper-1.0.0.pre spec/flipper/poller_spec.rb
flipper-0.28.3 spec/flipper/poller_spec.rb
flipper-0.28.2 spec/flipper/poller_spec.rb
flipper-0.28.1 spec/flipper/poller_spec.rb
flipper-0.28.0 spec/flipper/poller_spec.rb
flipper-0.27.1 spec/flipper/poller_spec.rb
flipper-0.27.0 spec/flipper/poller_spec.rb
flipper-0.26.2 spec/flipper/poller_spec.rb
flipper-0.26.1 spec/flipper/poller_spec.rb