Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ef9a63b6
Commit
ef9a63b6
authored
Jul 23, 2020
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify `bin/feature-flag` script
Do not ask for type if it is only one.
parent
e113c30f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
11 deletions
+35
-11
bin/feature-flag
bin/feature-flag
+3
-0
spec/bin/feature_flag_spec.rb
spec/bin/feature_flag_spec.rb
+32
-11
No files found.
bin/feature-flag
View file @
ef9a63b6
...
...
@@ -118,6 +118,9 @@ class FeatureFlagOptionParser
end
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
TYPES
.
each
do
|
type
,
data
|
...
...
spec/bin/feature_flag_spec.rb
View file @
ef9a63b6
...
...
@@ -115,24 +115,45 @@ RSpec.describe 'bin/feature-flag' do
describe
'.read_type'
do
let
(
:type
)
{
'development'
}
it
'reads type from $stdin'
do
expect
(
$stdin
).
to
receive
(
:gets
).
and_return
(
type
)
expect
do
context
'when there is only a single type defined'
do
before
do
stub_const
(
'FeatureFlagOptionParser::TYPES'
,
development:
{
description:
'short'
}
)
end
it
'returns that type'
do
expect
(
described_class
.
read_type
).
to
eq
(
:development
)
end
.
to
output
(
/specify the type/
).
to_stdout
end
end
context
'invalid type given'
do
let
(
:type
)
{
'invalid'
}
context
'when there are many types defined'
do
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_raise
(
'EOF'
)
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
.
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment