diff options
Diffstat (limited to 'qa/spec/runtime')
-rw-r--r-- | qa/spec/runtime/env_spec.rb | 21 | ||||
-rw-r--r-- | qa/spec/runtime/feature_spec.rb | 73 | ||||
-rw-r--r-- | qa/spec/runtime/logger_spec.rb | 2 |
3 files changed, 72 insertions, 24 deletions
diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index 22603497019..a41d7385c41 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -47,13 +47,6 @@ RSpec.describe QA::Runtime::Env do default: false end - describe '.debug?' do - it_behaves_like 'boolean method', - method: :debug?, - env_key: 'QA_DEBUG', - default: false - end - describe '.webdriver_headless?' do it_behaves_like 'boolean method', method: :webdriver_headless?, @@ -264,20 +257,6 @@ RSpec.describe QA::Runtime::Env do end end - describe '.log_destination' do - it 'returns $stdout if QA_LOG_PATH is not defined' do - stub_env('QA_LOG_PATH', nil) - - expect(described_class.log_destination).to eq($stdout) - end - - it 'returns the path if QA_LOG_PATH is defined' do - stub_env('QA_LOG_PATH', 'path/to_file') - - expect(described_class.log_destination).to eq('path/to_file') - end - end - describe '.can_test?' do it_behaves_like 'boolean method with parameter', method: :can_test?, diff --git a/qa/spec/runtime/feature_spec.rb b/qa/spec/runtime/feature_spec.rb index 88f5cd5be93..72ba915d99b 100644 --- a/qa/spec/runtime/feature_spec.rb +++ b/qa/spec/runtime/feature_spec.rb @@ -61,7 +61,7 @@ RSpec.describe QA::Runtime::Feature do .to receive(:get) .and_return(Struct.new(:code, :body).new(200, %Q([{ "name": "a_flag", "state": "conditional", "gates": #{gates} }]))) - expect(described_class.enabled?(feature_flag, scope => actor)).to be_truthy + expect(described_class.enabled?(feature_flag, scope => actor)).to be true end end end @@ -172,7 +172,7 @@ RSpec.describe QA::Runtime::Feature do .to receive(:get) .and_return(Struct.new(:code, :body).new(200, '[{ "name": "a_flag", "state": "on" }]')) - expect(described_class.enabled?(feature_flag)).to be_truthy + expect(described_class.enabled?(feature_flag)).to be true end it 'raises an error when the scope is unknown' do @@ -224,6 +224,75 @@ RSpec.describe QA::Runtime::Feature do let(:gates) { %q([{"key": "groups", "value": ["foo"]}]) } end end + + context 'when a feature flag is not found via the API and there is no definition file' do + before do + allow(QA::Runtime::API::Request) + .to receive(:new) + .with(api_client, "/features") + .and_return(request) + allow(described_class) + .to receive(:get) + .and_return(Struct.new(:code, :body).new(200, '[]')) + allow(Dir).to receive(:glob).and_return([]) + end + + it 'raises an error' do + expect { described_class.enabled?(feature_flag) } + .to raise_error(QA::Runtime::Feature::UnknownFeatureFlagError) + end + end + + context 'with definition files' do + context 'when no features are found via the API' do + before do + allow(QA::Runtime::API::Request) + .to receive(:new) + .with(api_client, "/features") + .and_return(request) + allow(described_class) + .to receive(:get) + .and_return(Struct.new(:code, :body).new(200, '[]')) + allow(Dir).to receive(:glob).and_return(['file_path']) + allow(File).to receive(:read).and_return(definition) + end + + context 'with a default enabled defintion' do + let(:definition) { 'default_enabled: true' } + + it 'returns a default enabled flag' do + expect(described_class.enabled?(feature_flag)).to be true + end + end + + context 'with a default disabled defintion' do + let(:definition) { 'default_enabled: false' } + + it 'returns a default disabled flag' do + expect(described_class.enabled?(feature_flag)).to be false + end + end + end + + context 'when the feature is found via the API' do + before do + allow(QA::Runtime::API::Request) + .to receive(:new) + .with(api_client, "/features") + .and_return(request) + allow(described_class) + .to receive(:get) + .and_return(Struct.new(:code, :body).new(200, '[{ "name": "a_flag", "state": "on" }]')) + end + + it 'returns the value from the API not the definition file' do + expect(Dir).not_to receive(:glob) + expect(File).not_to receive(:read) + + expect(described_class.enabled?(feature_flag)).to be true + end + end + end end end diff --git a/qa/spec/runtime/logger_spec.rb b/qa/spec/runtime/logger_spec.rb index f0fcfa0564e..652037a7041 100644 --- a/qa/spec/runtime/logger_spec.rb +++ b/qa/spec/runtime/logger_spec.rb @@ -2,6 +2,6 @@ RSpec.describe QA::Runtime::Logger do it 'returns logger instance' do - expect(described_class.logger).to be_an_instance_of(::Logger) + expect(described_class.logger).to be_an_instance_of(ActiveSupport::Logger) end end |