Sha256: 1d102ce69a591c83f1157b4f6f6f9380125ff7d84a573fead0e6ad151efd2d46

Contents?: true

Size: 1.55 KB

Versions: 38

Compression:

Stored size: 1.55 KB

Contents

require 'helper'

RSpec.describe Flipper::Gates::Group do
  let(:feature_name) { :search }

  subject do
    described_class.new
  end

  def context(set)
    Flipper::FeatureCheckContext.new(
      feature_name: feature_name,
      values: Flipper::GateValues.new(groups: set),
      thing: Flipper::Types::Actor.new(Flipper::Actor.new('5'))
    )
  end

  describe '#open?' do
    context 'with a group in adapter, but not registered' do
      before do
        Flipper.register(:staff) { |_thing| true }
      end

      it 'ignores group' do
        thing = Flipper::Actor.new('5')
        expect(subject.open?(context(Set[:newbs, :staff]))).to be(true)
      end
    end

    context 'thing that does not respond to method in group block' do
      before do
        Flipper.register(:stinkers, &:stinker?)
      end

      it 'raises error' do
        expect do
          subject.open?(context(Set[:stinkers]))
        end.to raise_error(NoMethodError)
      end
    end
  end

  describe '#wrap' do
    it 'returns group instance for symbol' do
      group = Flipper.register(:admins) {}
      expect(subject.wrap(:admins)).to eq(group)
    end

    it 'returns group instance for group instance' do
      group = Flipper.register(:admins) {}
      expect(subject.wrap(group)).to eq(group)
    end
  end

  describe '#protects?' do
    it 'returns true for group' do
      group = Flipper.register(:admins) {}
      expect(subject.protects?(group)).to be(true)
    end

    it 'returns true for symbol' do
      expect(subject.protects?(:admins)).to be(true)
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
flipper-0.22.2 spec/flipper/gates/group_spec.rb
flipper-0.22.1 spec/flipper/gates/group_spec.rb
flipper-0.22.0 spec/flipper/gates/group_spec.rb
flipper-0.21.0 spec/flipper/gates/group_spec.rb
flipper-0.21.0.rc2 spec/flipper/gates/group_spec.rb
flipper-0.21.0.rc1 spec/flipper/gates/group_spec.rb
flipper-0.20.4 spec/flipper/gates/group_spec.rb
flipper-0.20.3 spec/flipper/gates/group_spec.rb
flipper-0.20.2 spec/flipper/gates/group_spec.rb
flipper-0.20.1 spec/flipper/gates/group_spec.rb
flipper-0.20.0 spec/flipper/gates/group_spec.rb
flipper-0.20.0.beta3 spec/flipper/gates/group_spec.rb
flipper-0.20.0.beta2 spec/flipper/gates/group_spec.rb
flipper-0.20.0.beta1 spec/flipper/gates/group_spec.rb
flipper-0.19.1 spec/flipper/gates/group_spec.rb
flipper-0.19.0 spec/flipper/gates/group_spec.rb
flipper-0.18.0 spec/flipper/gates/group_spec.rb
flipper-0.17.2 spec/flipper/gates/group_spec.rb
flipper-0.17.1 spec/flipper/gates/group_spec.rb
flipper-0.16.2 spec/flipper/gates/group_spec.rb