Skip to content

Draft: Clarify testing guide for the code path with enabled FF

Igor Drozdov requested to merge docs-feature-flags-testings-guide into master

What does this MR do and why?

When a feature flag is introduced, it is recommended to test all the code affected by a feature flag, both when enabled and disabled to ensure the feature works properly.

The most common ways are:

  1. With an explicit context block with/without explicit FF enabling:
context 'when the feature flag is enabled' do
  before do
    stub_feature_flags(some_feature_flag: true)
  end

  it 'tests the behavior with the enabled feature flag' do
  end
end

context 'when the feature flag is disabled' do
  before do
    stub_feature_flags(some_feature_flag: false)
  end

  it 'tests the behavior with the disabled feature flag' do
  end
end

Pros: this explicit approach is more readable for someone who is unaware that feature flags are enabled by default in tests.

  1. With a context block only for the disabled FF scenario:
it 'tests the behavior with the enabled feature flag' do
end

context 'when the feature flag is disabled' do
  before do
    stub_feature_flags(some_feature_flag: false)
  end

  it 'tests the behavior with the disabled feature flag' do
  end
end

Pros:Cleaner diffs and blames because only the relevant code is touched when the feature flag is removed. Less noise for someone who is aware that feature flags are enabled by default in tests.

Edited by Igor Drozdov

Merge request reports