debian-mirror-gitlab/spec/support/helpers/stub_experiments.rb

32 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module StubExperiments
# Stub Experiment with `key: true/false`
#
2021-02-22 17:27:13 +05:30
# @param [Hash] experiment where key is feature name and value is boolean whether active or not.
2019-12-21 20:55:43 +05:30
#
# Examples
2021-02-22 17:27:13 +05:30
# - `stub_experiment(signup_flow: false)` ... Disables `signup_flow` experiment.
2019-12-21 20:55:43 +05:30
def stub_experiment(experiments)
2021-02-22 17:27:13 +05:30
allow(Gitlab::Experimentation).to receive(:active?).and_call_original
2020-04-22 19:07:51 +05:30
2019-12-21 20:55:43 +05:30
experiments.each do |experiment_key, enabled|
2021-02-22 17:27:13 +05:30
allow(Gitlab::Experimentation).to receive(:active?).with(experiment_key) { enabled }
2019-12-26 22:10:19 +05:30
end
end
# Stub Experiment for user with `key: true/false`
#
# @param [Hash] experiment where key is feature name and value is boolean whether enabled or not.
#
# Examples
2021-02-22 17:27:13 +05:30
# - `stub_experiment_for_subject(signup_flow: false)` ... Disable `signup_flow` experiment for user.
def stub_experiment_for_subject(experiments)
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).and_call_original
2020-04-22 19:07:51 +05:30
2019-12-26 22:10:19 +05:30
experiments.each do |experiment_key, enabled|
2021-02-22 17:27:13 +05:30
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).with(experiment_key, anything) { enabled }
2019-12-21 20:55:43 +05:30
end
end
end