BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7babc59e
Commit
7babc59e
authored
May 15, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use parameterized RSpec to improve variables expressions specs
parent
65f4e7b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
43 deletions
+44
-43
statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+44
-43
No files found.
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
7babc59e
require
'fast_spec_helper'
require
'rspec-parameterized'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
do
subject
do
...
...
@@ -82,54 +83,54 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
describe
'#evaluate'
do
statements
=
[
[
'$PRESENT_VARIABLE == "my variable"'
,
true
],
[
'"my variable" == $PRESENT_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE == null'
,
false
],
[
'$EMPTY_VARIABLE == null'
,
false
],
[
'"" == $EMPTY_VARIABLE'
,
true
],
[
'$EMPTY_VARIABLE'
,
''
],
[
'$UNDEFINED_VARIABLE == null'
,
true
],
[
'null == $UNDEFINED_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE'
,
'my variable'
],
[
'$UNDEFINED_VARIABLE'
,
nil
],
[
"$PRESENT_VARIABLE =~ /var.*e$/"
,
true
],
[
"$PRESENT_VARIABLE =~ /^var.*/"
,
false
],
[
"$EMPTY_VARIABLE =~ /var.*/"
,
false
],
[
"$UNDEFINED_VARIABLE =~ /var.*/"
,
false
]
]
statements
.
each
do
|
expression
,
value
|
context
"when using expression `
#{
expression
}
`"
do
let
(
:text
)
{
expression
}
it
"evaluates to `
#{
value
.
inspect
}
`"
do
expect
(
subject
.
evaluate
).
to
eq
value
e
nd
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:expression
,
:value
)
do
'$PRESENT_VARIABLE == "my variable"'
|
true
'"my variable" == $PRESENT_VARIABLE'
|
true
'$PRESENT_VARIABLE == null'
|
false
'$EMPTY_VARIABLE == null'
|
false
'"" == $EMPTY_VARIABLE'
|
true
'$EMPTY_VARIABLE'
|
''
'$UNDEFINED_VARIABLE == null'
|
true
'null == $UNDEFINED_VARIABLE'
|
true
'$PRESENT_VARIABLE'
|
'my variable'
'$UNDEFINED_VARIABLE'
|
nil
"$PRESENT_VARIABLE =~ /var.*e$/"
|
true
"$PRESENT_VARIABLE =~ /^var.*/"
|
false
"$EMPTY_VARIABLE =~ /var.*/"
|
false
"$UNDEFINED_VARIABLE =~ /var.*/"
|
false
end
with_them
do
let
(
:text
)
{
expression
}
it
"evaluates to `
#{
params
[
:value
].
inspect
}
`"
do
e
xpect
(
subject
.
evaluate
).
to
eq
value
end
end
end
describe
'#truthful?'
do
statements
=
[
[
'$PRESENT_VARIABLE == "my variable"'
,
true
],
[
"$PRESENT_VARIABLE == 'no match'"
,
false
],
[
'$UNDEFINED_VARIABLE == null'
,
true
],
[
'$PRESENT_VARIABLE'
,
true
],
[
'$UNDEFINED_VARIABLE'
,
false
],
[
'$EMPTY_VARIABLE'
,
false
],
[
'$INVALID = 1'
,
false
],
[
"$PRESENT_VARIABLE =~ /var.*/"
,
true
],
[
"$UNDEFINED_VARIABLE =~ /var.*/"
,
false
]
]
statements
.
each
do
|
expression
,
value
|
context
"when using expression `
#{
expression
}
`"
do
let
(
:text
)
{
expression
}
it
"returns `
#{
value
.
inspect
}
`"
do
expect
(
subject
.
truthful?
).
to
eq
value
e
nd
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:expression
,
:value
)
do
'$PRESENT_VARIABLE == "my variable"'
|
true
"$PRESENT_VARIABLE == 'no match'"
|
false
'$UNDEFINED_VARIABLE == null'
|
true
'$PRESENT_VARIABLE'
|
true
'$UNDEFINED_VARIABLE'
|
false
'$EMPTY_VARIABLE'
|
false
'$INVALID = 1'
|
false
"$PRESENT_VARIABLE =~ /var.*/"
|
true
"$UNDEFINED_VARIABLE =~ /var.*/"
|
false
end
with_them
do
let
(
:text
)
{
expression
}
it
"returns `
#{
params
[
:value
].
inspect
}
`"
do
e
xpect
(
subject
.
truthful?
).
to
eq
value
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