summaryrefslogtreecommitdiff
path: root/spec/lib/feature
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/feature')
-rw-r--r--spec/lib/feature/definition_spec.rb63
1 files changed, 61 insertions, 2 deletions
diff --git a/spec/lib/feature/definition_spec.rb b/spec/lib/feature/definition_spec.rb
index fa0207d829a..21120012927 100644
--- a/spec/lib/feature/definition_spec.rb
+++ b/spec/lib/feature/definition_spec.rb
@@ -64,6 +64,11 @@ RSpec.describe Feature::Definition do
expect { definition.valid_usage!(type_in_code: :development, default_enabled_in_code: false) }
.to raise_error(/The `default_enabled:` of `feature_flag` is not equal to config/)
end
+
+ it 'allows passing `default_enabled: :yaml`' do
+ expect { definition.valid_usage!(type_in_code: :development, default_enabled_in_code: :yaml) }
+ .not_to raise_error
+ end
end
end
@@ -75,7 +80,7 @@ RSpec.describe Feature::Definition do
describe '.load_from_file' do
it 'properly loads a definition from file' do
- expect(File).to receive(:read).with(path) { yaml_content }
+ expect_file_read(path, content: yaml_content)
expect(described_class.send(:load_from_file, path).attributes)
.to eq(definition.attributes)
@@ -93,7 +98,7 @@ RSpec.describe Feature::Definition do
context 'for invalid definition' do
it 'raises exception' do
- expect(File).to receive(:read).with(path) { '{}' }
+ expect_file_read(path, content: '{}')
expect do
described_class.send(:load_from_file, path)
@@ -209,4 +214,58 @@ RSpec.describe Feature::Definition do
end
end
end
+
+ describe '.defaul_enabled?' do
+ subject { described_class.default_enabled?(key) }
+
+ context 'when feature flag exist' do
+ let(:key) { definition.key }
+
+ before do
+ allow(described_class).to receive(:definitions) do
+ { definition.key => definition }
+ end
+ end
+
+ context 'when default_enabled is true' do
+ it 'returns the value from the definition' do
+ expect(subject).to eq(true)
+ end
+ end
+
+ context 'when default_enabled is false' do
+ let(:attributes) do
+ { name: 'feature_flag',
+ type: 'development',
+ default_enabled: false }
+ end
+
+ it 'returns the value from the definition' do
+ expect(subject).to eq(false)
+ end
+ end
+ end
+
+ context 'when feature flag does not exist' do
+ let(:key) { :unknown_feature_flag }
+
+ context 'when on dev or test environment' do
+ it 'raises an error' do
+ expect { subject }.to raise_error(
+ Feature::InvalidFeatureFlagError,
+ "The feature flag YAML definition for 'unknown_feature_flag' does not exist")
+ end
+ end
+
+ context 'when on production environment' do
+ before do
+ allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(false)
+ end
+
+ it 'returns false' do
+ expect(subject).to eq(false)
+ end
+ end
+ end
+ end
end