Sha256: 0b23a277fd9067f9b227ad850a16297a2aa61312d9a9b5899d640d6fd47e9036

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

RSpec.describe Flipper::Adapters::Strict do
  let(:flipper) { Flipper.new(subject) }
  let(:feature) { flipper[:unknown] }

  it_should_behave_like 'a flipper adapter' do
    subject { described_class.new(Flipper::Adapters::Memory.new, :noop) }
  end

  [true, :raise].each do |handler|
    context "handler = #{handler}" do
      subject { described_class.new(Flipper::Adapters::Memory.new, handler) }

      context "#get" do
        it "raises an error for unknown feature" do
          expect { subject.get(feature) }.to raise_error(Flipper::Adapters::Strict::NotFound)
        end
      end

      context "#get_multi" do
        it "raises an error for unknown feature" do
          expect { subject.get_multi([feature]) }.to raise_error(Flipper::Adapters::Strict::NotFound)
        end
      end
    end
  end

  context "handler = :warn" do
    subject { described_class.new(Flipper::Adapters::Memory.new, :warn) }

    context "#get" do
      it "raises an error for unknown feature" do
        expect(capture_output { subject.get(feature) }).to match(/Could not find feature "unknown"/)
      end
    end

    context "#get_multi" do
      it "raises an error for unknown feature" do
        expect(capture_output { subject.get_multi([feature]) }).to match(/Could not find feature "unknown"/)
      end
    end
  end

  context "handler = Block" do
    let(:unknown_features) { [] }
    subject do
      described_class.new(Flipper::Adapters::Memory.new) { |feature| unknown_features << feature.key}
    end


    context "#get" do
      it "raises an error for unknown feature" do
        subject.get(feature)
        expect(unknown_features).to eq(["unknown"])
      end
    end

    context "#get_multi" do
      it "raises an error for unknown feature" do
        subject.get_multi([flipper[:foo], flipper[:bar]])
        expect(unknown_features).to eq(["foo", "bar"])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flipper-1.3.2 spec/flipper/adapters/strict_spec.rb
flipper-1.3.1 spec/flipper/adapters/strict_spec.rb