diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 18:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 18:09:24 +0300 |
commit | 6cbb93596d65dff377372f4b50da932dcf6dc514 (patch) | |
tree | c381ee98bd0fb444665f11c452b8e8f0e8e7731a /spec/experiments/application_experiment_spec.rb | |
parent | ce9b8ee20d039da5f93e37d0ab3905813f3dd7bc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/experiments/application_experiment_spec.rb')
-rw-r--r-- | spec/experiments/application_experiment_spec.rb | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 5c5f563a803..6b4a3ece59e 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -3,14 +3,16 @@ require 'spec_helper' RSpec.describe ApplicationExperiment, :experiment do - subject { described_class.new(:stub) } + subject { described_class.new('namespaced/stub') } - let(:feature_definition) { { name: 'stub', type: 'experiment', group: 'group::adoption', default_enabled: false } } + let(:feature_definition) do + { name: 'namespaced_stub', type: 'experiment', group: 'group::adoption', default_enabled: false } + end around do |example| - Feature::Definition.definitions[:stub] = Feature::Definition.new('stub.yml', feature_definition) + Feature::Definition.definitions[:namespaced_stub] = Feature::Definition.new('namespaced_stub.yml', feature_definition) example.run - Feature::Definition.definitions.delete(:stub) + Feature::Definition.definitions.delete(:namespaced_stub) end before do @@ -18,9 +20,9 @@ RSpec.describe ApplicationExperiment, :experiment do end it "naively assumes a 1x1 relationship to feature flags for tests" do - expect(Feature).to receive(:persist_used!).with('stub') + expect(Feature).to receive(:persist_used!).with('namespaced_stub') - described_class.new(:stub) + described_class.new('namespaced/stub') end describe "enabled" do @@ -37,7 +39,7 @@ RSpec.describe ApplicationExperiment, :experiment do end it "isn't enabled if the feature definition doesn't exist" do - expect(Feature::Definition).to receive(:get).with('stub').and_return(nil) + expect(Feature::Definition).to receive(:get).with('namespaced_stub').and_return(nil) expect(subject).not_to be_enabled end @@ -49,7 +51,7 @@ RSpec.describe ApplicationExperiment, :experiment do end it "isn't enabled if the feature flag state is :off" do - expect(Feature).to receive(:get).with('stub').and_return(double(state: :off)) + expect(Feature).to receive(:get).with('namespaced_stub').and_return(double(state: :off)) expect(subject).not_to be_enabled end @@ -66,9 +68,9 @@ RSpec.describe ApplicationExperiment, :experiment do expect(Gon.global).to receive(:push).with( { experiment: { - 'stub' => { # string key because it can be namespaced - experiment: 'stub', - key: 'e8f65fd8d973f9985dc7ea3cf1614ae1', + 'namespaced/stub' => { # string key because it can be namespaced + experiment: 'namespaced/stub', + key: '86208ac54ca798e11f127e8b23ec396a', variant: 'control' } } @@ -95,7 +97,7 @@ RSpec.describe ApplicationExperiment, :experiment do ]) expect_snowplow_event( - category: 'stub', + category: 'namespaced/stub', action: 'action', property: '_property_', context: [ @@ -105,7 +107,7 @@ RSpec.describe ApplicationExperiment, :experiment do }, { schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', - data: { experiment: 'stub', key: 'e8f65fd8d973f9985dc7ea3cf1614ae1', variant: 'control' } + data: { experiment: 'namespaced/stub', key: '86208ac54ca798e11f127e8b23ec396a', variant: 'control' } } ] ) @@ -114,13 +116,13 @@ RSpec.describe ApplicationExperiment, :experiment do describe "variant resolution" do it "uses the default value as specified in the yaml" do - expect(Feature).to receive(:enabled?).with('stub', subject, type: :experiment, default_enabled: :yaml) + expect(Feature).to receive(:enabled?).with('namespaced_stub', subject, type: :experiment, default_enabled: :yaml) expect(subject.variant.name).to eq('control') end it "returns nil when not rolled out" do - stub_feature_flags(stub: false) + stub_feature_flags(namespaced_stub: false) expect(subject.variant.name).to eq('control') end @@ -161,7 +163,7 @@ RSpec.describe ApplicationExperiment, :experiment do # every control variant assigned, we'd inflate the cache size and # wouldn't be able to roll out to subjects that we'd already assigned to # the control. - stub_feature_flags(stub: false) # simulate being not rolled out + stub_feature_flags(namespaced_stub: false) # simulate being not rolled out expect(subject.variant.name).to eq('control') # if we ask, it should be control |