Sha256: 1f3e4c65be3f6e71fc4ba80bcbd6bca345f230c43c1c599b9a7048af215b44b6

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 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

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

    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

  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(silence { 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(silence { 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

3 entries across 3 versions & 1 rubygems

Version Path
flipper-1.1.2 spec/flipper/adapters/strict_spec.rb
flipper-1.1.1 spec/flipper/adapters/strict_spec.rb
flipper-1.1.0 spec/flipper/adapters/strict_spec.rb