Skip to content
代码片段 群组 项目
提交 ef9a63b6 编辑于 作者: Kamil Trzciński's avatar Kamil Trzciński
浏览文件

Simplify `bin/feature-flag` script

Do not ask for type if it is only one.
上级 e113c30f
No related branches found
No related tags found
无相关合并请求
...@@ -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 @@ ...@@ -115,24 +115,45 @@
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
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册