summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2019-05-17 18:36:53 +0000
committerAchilleas Pipinellis <axil@gitlab.com>2019-05-17 18:36:53 +0000
commit6f585581b21a2802f3f46ac4e846da3e0c571f7e (patch)
tree57487e36bc39a5d0f0d120d772ef2b48aad19fe5
parent8739c0095c999e8d2e49a7f96aef7ef6ec73ebe6 (diff)
parentdb7dabea674d30c170ab22b43efd86a5d91ccdfc (diff)
downloadgitlab-ce-6f585581b21a2802f3f46ac4e846da3e0c571f7e.tar.gz
Merge branch 'add-testing-feature-flags-docs' into 'master'
Add how to disable feature flags in testing guide See merge request gitlab-org/gitlab-ce!27248
-rw-r--r--doc/development/feature_flags.md8
-rw-r--r--doc/development/testing_guide/best_practices.md30
2 files changed, 34 insertions, 4 deletions
diff --git a/doc/development/feature_flags.md b/doc/development/feature_flags.md
index 3271f9a7fb3..82b09cc0224 100644
--- a/doc/development/feature_flags.md
+++ b/doc/development/feature_flags.md
@@ -108,11 +108,11 @@ so we make sure behavior under feature flag doesn't go untested in some non-spec
contexts.
Whenever a feature flag is present, make sure to test _both_ states of the
-feature flag. You can stub a feature flag as follows:
+feature flag.
-```ruby
-stub_feature_flags(my_feature_flag: false)
-```
+See the
+[testing guide](testing_guide/best_practices.html#feature-flags-in-tests)
+for information and examples on how to stub feature flags in tests.
## Enabling a feature flag (in development)
diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md
index e41148360f2..63ec9755462 100644
--- a/doc/development/testing_guide/best_practices.md
+++ b/doc/development/testing_guide/best_practices.md
@@ -240,6 +240,36 @@ it 'is overdue' do
end
```
+### Feature flags in tests
+
+All feature flags are stubbed to be enabled by default in our Ruby-based
+tests.
+
+To disable a feature flag in a test, use the `stub_feature_flags`
+helper. For example, to globally disable the `ci_live_trace` feature
+flag in a test:
+
+```ruby
+stub_feature_flags(ci_live_trace: false)
+
+Feature.enabled?(:ci_live_trace) # => false
+```
+
+If you wish to set up a test where a feature flag is disabled for some
+actors and not others, you can specify this in options passed to the
+helper. For example, to disable the `ci_live_trace` feature flag for a
+specifc project:
+
+```ruby
+project1, project2 = build_list(:project, 2)
+
+# Feature will only be disabled for project1
+stub_feature_flags(ci_live_trace: { enabled: false, thing: project1 })
+
+Feature.enabled?(:ci_live_trace, project1) # => false
+Feature.enabled?(:ci_live_trace, project2) # => true
+```
+
### Pristine test environments
The code exercised by a single GitLab test may access and modify many items of