Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support_specs/helpers/stub_feature_flags_spec.rb')
-rw-r--r--spec/support_specs/helpers/stub_feature_flags_spec.rb72
1 files changed, 37 insertions, 35 deletions
diff --git a/spec/support_specs/helpers/stub_feature_flags_spec.rb b/spec/support_specs/helpers/stub_feature_flags_spec.rb
index b6e230075f2..e90a7f68a90 100644
--- a/spec/support_specs/helpers/stub_feature_flags_spec.rb
+++ b/spec/support_specs/helpers/stub_feature_flags_spec.rb
@@ -3,16 +3,7 @@
require 'spec_helper'
describe StubFeatureFlags do
- before do
- # reset stub introduced by `stub_feature_flags`
- allow(Feature).to receive(:enabled?).and_call_original
- end
-
- context 'if not stubbed' do
- it 'features are disabled by default' do
- expect(Feature.enabled?(:test_feature)).to eq(false)
- end
- end
+ let(:feature_name) { :test_feature }
describe '#stub_feature_flags' do
using RSpec::Parameterized::TableSyntax
@@ -30,7 +21,7 @@ describe StubFeatureFlags do
with_them do
before do
- stub_feature_flags(feature_name => feature_actors)
+ stub_feature_flags(feature_name => actor(feature_actors))
end
it { expect(Feature.enabled?(feature_name)).to eq(expected_result) }
@@ -62,15 +53,15 @@ describe StubFeatureFlags do
with_them do
before do
- stub_feature_flags(feature_name => feature_actors)
+ stub_feature_flags(feature_name => actor(feature_actors))
end
- it { expect(Feature.enabled?(feature_name, tested_actor)).to eq(expected_result) }
- it { expect(Feature.disabled?(feature_name, tested_actor)).not_to eq(expected_result) }
+ it { expect(Feature.enabled?(feature_name, actor(tested_actor))).to eq(expected_result) }
+ it { expect(Feature.disabled?(feature_name, actor(tested_actor))).not_to eq(expected_result) }
context 'default_enabled does not impact feature state' do
- it { expect(Feature.enabled?(feature_name, tested_actor, default_enabled: true)).to eq(expected_result) }
- it { expect(Feature.disabled?(feature_name, tested_actor, default_enabled: true)).not_to eq(expected_result) }
+ it { expect(Feature.enabled?(feature_name, actor(tested_actor), default_enabled: true)).to eq(expected_result) }
+ it { expect(Feature.disabled?(feature_name, actor(tested_actor), default_enabled: true)).not_to eq(expected_result) }
end
end
end
@@ -82,7 +73,7 @@ describe StubFeatureFlags do
end
with_them do
- subject { stub_feature_flags(feature_name => feature_actors) }
+ subject { stub_feature_flags(feature_name => actor(feature_actors)) }
it { expect { subject }.to raise_error(ArgumentError, /accepts only/) }
end
@@ -90,11 +81,11 @@ describe StubFeatureFlags do
context 'does not raise error' do
where(:feature_actors) do
- [true, false, nil, :symbol, double, User.new]
+ [true, false, nil, stub_feature_flag_gate(100), User.new]
end
with_them do
- subject { stub_feature_flags(feature_name => feature_actors) }
+ subject { stub_feature_flags(feature_name => actor(feature_actors)) }
it { expect { subject }.not_to raise_error }
end
@@ -103,28 +94,39 @@ describe StubFeatureFlags do
it 'subsquent run changes state' do
# enable FF only on A
- stub_feature_flags(test_feature: %i[A])
- expect(Feature.enabled?(:test_feature)).to eq(false)
- expect(Feature.enabled?(:test_feature, :A)).to eq(true)
- expect(Feature.enabled?(:test_feature, :B)).to eq(false)
+ stub_feature_flags({ feature_name => actor(%i[A]) })
+ expect(Feature.enabled?(feature_name)).to eq(false)
+ expect(Feature.enabled?(feature_name, actor(:A))).to eq(true)
+ expect(Feature.enabled?(feature_name, actor(:B))).to eq(false)
# enable FF only on B
- stub_feature_flags(test_feature: %i[B])
- expect(Feature.enabled?(:test_feature)).to eq(false)
- expect(Feature.enabled?(:test_feature, :A)).to eq(false)
- expect(Feature.enabled?(:test_feature, :B)).to eq(true)
+ stub_feature_flags({ feature_name => actor(%i[B]) })
+ expect(Feature.enabled?(feature_name)).to eq(false)
+ expect(Feature.enabled?(feature_name, actor(:A))).to eq(false)
+ expect(Feature.enabled?(feature_name, actor(:B))).to eq(true)
# enable FF on all
- stub_feature_flags(test_feature: true)
- expect(Feature.enabled?(:test_feature)).to eq(true)
- expect(Feature.enabled?(:test_feature, :A)).to eq(true)
- expect(Feature.enabled?(:test_feature, :B)).to eq(true)
+ stub_feature_flags({ feature_name => true })
+ expect(Feature.enabled?(feature_name)).to eq(true)
+ expect(Feature.enabled?(feature_name, actor(:A))).to eq(true)
+ expect(Feature.enabled?(feature_name, actor(:B))).to eq(true)
# disable FF on all
- stub_feature_flags(test_feature: false)
- expect(Feature.enabled?(:test_feature)).to eq(false)
- expect(Feature.enabled?(:test_feature, :A)).to eq(false)
- expect(Feature.enabled?(:test_feature, :B)).to eq(false)
+ stub_feature_flags({ feature_name => false })
+ expect(Feature.enabled?(feature_name)).to eq(false)
+ expect(Feature.enabled?(feature_name, actor(:A))).to eq(false)
+ expect(Feature.enabled?(feature_name, actor(:B))).to eq(false)
+ end
+ end
+
+ def actor(actor)
+ case actor
+ when Array
+ actor.map(&method(:actor))
+ when Symbol # convert to flipper compatible object
+ stub_feature_flag_gate(actor)
+ else
+ actor
end
end
end