Sha256: f5147ec56256d13e6343e383e171812e2df4ba2b83d6dd911ad170c464805496

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"

describe FeatureGuard do
  let(:feature) { :some_feature_name }

  describe 'enabling and disabling a feature' do
    it 'turns the feature on and off in succession' do
      expect {
        FeatureGuard.enable feature
      }.to change {
        FeatureGuard.enabled? feature
      }.from(false).to(true)

      expect {
        FeatureGuard.disable feature
      }.to change {
        FeatureGuard.enabled? feature
      }.from(true).to(false)
    end
  end

  describe 'ramping a feature up and down' do
    let(:user_id) { 5435 }

    it 'allows a percentage of calls to use the feature' do
      expect {
        FeatureGuard.set_ramp feature, 100.0
      }.to change {
        FeatureGuard.allow? feature, user_id
      }.from(false).to(true)

      expect {
        FeatureGuard.set_ramp feature, 0.0
      }.to change {
        FeatureGuard.allow? feature, user_id
      }.from(true).to(false)
    end
  end

  describe '.enabled?' do
    subject { FeatureGuard.enabled? feature }

    context 'for a non-existent flag' do
      it { should be_false }
    end

    context 'when the Redis client blows up or is non-existent' do
      before { FeatureGuard.stub(redis: nil) }

      it { should be_false }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
feature_guard-0.1.2 spec/feature_guard_spec.rb
feature_guard-0.1.1 spec/feature_guard_spec.rb
feature_guard-0.1.0 spec/feature_guard_spec.rb