summaryrefslogtreecommitdiff
path: root/spec/support/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers')
-rw-r--r--spec/support/helpers/stub_experiments.rb2
-rw-r--r--spec/support/helpers/stubbed_feature.rb22
2 files changed, 24 insertions, 0 deletions
diff --git a/spec/support/helpers/stub_experiments.rb b/spec/support/helpers/stub_experiments.rb
index 8995b8f5f7b..408d16a7c08 100644
--- a/spec/support/helpers/stub_experiments.rb
+++ b/spec/support/helpers/stub_experiments.rb
@@ -11,6 +11,7 @@ module StubExperiments
allow(Gitlab::Experimentation).to receive(:active?).and_call_original
experiments.each do |experiment_key, enabled|
+ Feature.persist_used!("#{experiment_key}#{feature_flag_suffix}")
allow(Gitlab::Experimentation).to receive(:active?).with(experiment_key) { enabled }
end
end
@@ -25,6 +26,7 @@ module StubExperiments
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).and_call_original
experiments.each do |experiment_key, enabled|
+ Feature.persist_used!("#{experiment_key}#{feature_flag_suffix}")
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).with(experiment_key, anything) { enabled }
end
end
diff --git a/spec/support/helpers/stubbed_feature.rb b/spec/support/helpers/stubbed_feature.rb
index 4113a28182b..67ceb7d9b35 100644
--- a/spec/support/helpers/stubbed_feature.rb
+++ b/spec/support/helpers/stubbed_feature.rb
@@ -4,6 +4,14 @@
module StubbedFeature
extend ActiveSupport::Concern
+ prepended do
+ cattr_reader(:persist_used) do
+ # persist feature flags in CI
+ # nil: indicates that we do not want to persist used feature flags
+ Gitlab::Utils.to_boolean(ENV['CI']) ? {} : nil
+ end
+ end
+
class_methods do
# Turn stubbed feature flags on or off.
def stub=(stub)
@@ -33,6 +41,8 @@ module StubbedFeature
feature_flag = super
return feature_flag unless stub?
+ persist_used!(args.first)
+
# If feature flag is not persisted we mark the feature flag as enabled
# We do `m.call` as we want to validate the execution of method arguments
# and a feature flag state if it is not persisted
@@ -42,5 +52,17 @@ module StubbedFeature
feature_flag
end
+
+ # This method creates a temporary file in `tmp/feature_flags`
+ # if feature flag was touched during execution
+ def persist_used!(name)
+ return unless persist_used
+ return if persist_used[name]
+
+ persist_used[name] = true
+ FileUtils.touch(
+ Rails.root.join('tmp', 'feature_flags', name.to_s + ".used")
+ )
+ end
end
end