Commit 1dabbb15 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'simplify-bin-feature-flag' into 'master'

Simplify `bin/feature-flag`

See merge request gitlab-org/gitlab!37718
parents 2a91735c ef9a63b6
...@@ -118,6 +118,9 @@ class FeatureFlagOptionParser ...@@ -118,6 +118,9 @@ class FeatureFlagOptionParser
end end
def read_type def read_type
# if there's only one type, do not ask, return
return TYPES.first.first if TYPES.one?
$stdout.puts ">> Please specify the type of your feature flag:" $stdout.puts ">> Please specify the type of your feature flag:"
$stdout.puts $stdout.puts
TYPES.each do |type, data| TYPES.each do |type, data|
......
...@@ -115,24 +115,45 @@ RSpec.describe 'bin/feature-flag' do ...@@ -115,24 +115,45 @@ RSpec.describe 'bin/feature-flag' do
describe '.read_type' do describe '.read_type' do
let(:type) { 'development' } let(:type) { 'development' }
it 'reads type from $stdin' do context 'when there is only a single type defined' do
expect($stdin).to receive(:gets).and_return(type) before do
expect do stub_const('FeatureFlagOptionParser::TYPES',
development: { description: 'short' }
)
end
it 'returns that type' do
expect(described_class.read_type).to eq(:development) expect(described_class.read_type).to eq(:development)
end.to output(/specify the type/).to_stdout end
end end
context 'invalid type given' do context 'when there are many types defined' do
let(:type) { 'invalid' } before do
stub_const('FeatureFlagOptionParser::TYPES',
development: { description: 'short' },
licensed: { description: 'licensed' }
)
end
it 'shows error message and retries' do it 'reads type from $stdin' do
expect($stdin).to receive(:gets).and_return(type) expect($stdin).to receive(:gets).and_return(type)
expect($stdin).to receive(:gets).and_raise('EOF')
expect do expect do
expect { described_class.read_type }.to raise_error(/EOF/) expect(described_class.read_type).to eq(:development)
end.to output(/specify the type/).to_stdout end.to output(/specify the type/).to_stdout
.and output(/Invalid type specified/).to_stderr end
context 'when invalid type is given' do
let(:type) { 'invalid' }
it 'shows error message and retries' do
expect($stdin).to receive(:gets).and_return(type)
expect($stdin).to receive(:gets).and_raise('EOF')
expect do
expect { described_class.read_type }.to raise_error(/EOF/)
end.to output(/specify the type/).to_stdout
.and output(/Invalid type specified/).to_stderr
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment