Sha256: ee94a992c9dc4052bb916ef8a796eade8f605541ea3947e2bab74a48b2f93589

Contents?: true

Size: 1.89 KB

Versions: 19

Compression:

Stored size: 1.89 KB

Contents

require 'helper'

RSpec.describe Flipper::FeatureCheckContext do
  let(:feature_name) { :new_profiles }
  let(:values) { Flipper::GateValues.new({}) }
  let(:thing) { Flipper::Actor.new('5') }
  let(:options) do
    {
      feature_name: feature_name,
      values: values,
      thing: thing,
    }
  end

  it 'initializes just fine' do
    instance = described_class.new(options)
    expect(instance.feature_name).to eq(feature_name)
    expect(instance.values).to eq(values)
    expect(instance.thing).to eq(thing)
  end

  it 'requires feature_name' do
    options.delete(:feature_name)
    expect do
      described_class.new(options)
    end.to raise_error(KeyError)
  end

  it 'requires values' do
    options.delete(:values)
    expect do
      described_class.new(options)
    end.to raise_error(KeyError)
  end

  it 'requires thing' do
    options.delete(:thing)
    expect do
      described_class.new(options)
    end.to raise_error(KeyError)
  end

  it 'knows actors_value' do
    args = options.merge(values: Flipper::GateValues.new(actors: Set['User:1']))
    expect(described_class.new(args).actors_value).to eq(Set['User:1'])
  end

  it 'knows groups_value' do
    args = options.merge(values: Flipper::GateValues.new(groups: Set['admins']))
    expect(described_class.new(args).groups_value).to eq(Set['admins'])
  end

  it 'knows boolean_value' do
    instance = described_class.new(options.merge(values: Flipper::GateValues.new(boolean: true)))
    expect(instance.boolean_value).to eq(true)
  end

  it 'knows percentage_of_actors_value' do
    args = options.merge(values: Flipper::GateValues.new(percentage_of_actors: 14))
    expect(described_class.new(args).percentage_of_actors_value).to eq(14)
  end

  it 'knows percentage_of_time_value' do
    args = options.merge(values: Flipper::GateValues.new(percentage_of_time: 41))
    expect(described_class.new(args).percentage_of_time_value).to eq(41)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
flipper-0.16.2 spec/flipper/feature_check_context_spec.rb
flipper-0.16.1 spec/flipper/feature_check_context_spec.rb
flipper-0.16.0 spec/flipper/feature_check_context_spec.rb
flipper-0.15.0 spec/flipper/feature_check_context_spec.rb
flipper-0.14.0 spec/flipper/feature_check_context_spec.rb
flipper-0.13.0 spec/flipper/feature_check_context_spec.rb
flipper-0.13.0.beta1 spec/flipper/feature_check_context_spec.rb
flipper-0.12.2 spec/flipper/feature_check_context_spec.rb
flipper-0.12.1 spec/flipper/feature_check_context_spec.rb
flipper-0.12.0 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.rc1 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta9 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta8 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta7 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta6 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta5 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta4 spec/flipper/feature_check_context_spec.rb
flipper-0.11.0.beta3 spec/flipper/feature_check_context_spec.rb