Sha256: 932d86ef9df0c0cdf371e51066daf61618ec63cb97fb76da30bfdddadc93b909

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

require 'helper'

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

  subject {
    described_class.new
  }

  def context(bool)
    Flipper::FeatureCheckContext.new(
      feature_name: feature_name,
      values: Flipper::GateValues.new({boolean: bool}),
      thing: Flipper::Types::Actor.new(Struct.new(:flipper_id).new(1)),
    )
  end

  describe "#enabled?" do
    context "for true value" do
      it "returns true" do
        expect(subject.enabled?(true)).to eq(true)
      end
    end

    context "for false value" do
      it "returns false" do
        expect(subject.enabled?(false)).to eq(false)
      end
    end
  end

  describe "#open?" do
    context "for true value" do
      it "returns true" do
        expect(subject.open?(context(true))).to be(true)
      end
    end

    context "for false value" do
      it "returns false" do
        expect(subject.open?(context(false))).to be(false)
      end
    end
  end

  describe "#protects?" do
    it "returns true for boolean type" do
      expect(subject.protects?(Flipper::Types::Boolean.new(true))).to be(true)
    end

    it "returns true for true" do
      expect(subject.protects?(true)).to be(true)
    end

    it "returns true for false" do
      expect(subject.protects?(false)).to be(true)
    end
  end

  describe "#wrap" do
    it "returns boolean type for boolean type" do
      expect(subject.wrap(Flipper::Types::Boolean.new(true))).to be_instance_of(Flipper::Types::Boolean)
    end

    it "returns boolean type for true" do
      expect(subject.wrap(true)).to be_instance_of(Flipper::Types::Boolean)
      expect(subject.wrap(true).value).to be(true)
    end

    it "returns boolean type for true" do
      expect(subject.wrap(false)).to be_instance_of(Flipper::Types::Boolean)
      expect(subject.wrap(false).value).to be(false)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.10.2 spec/flipper/gates/boolean_spec.rb
flipper-0.10.1 spec/flipper/gates/boolean_spec.rb
flipper-0.10.0 spec/flipper/gates/boolean_spec.rb