summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-28 12:10:32 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-28 12:10:32 +0100
commit1926eca04d36793b9d9646d5a0e720e4b835fd3c (patch)
treef6ed183f841822cd6207b60c4113cddbef92dda2 /spec/lib
parent64e86dab627681c52ffa78e99415b3b9d00b2f43 (diff)
downloadgitlab-ce-1926eca04d36793b9d9646d5a0e720e4b835fd3c.tar.gz
Add method that checks if pipeline expression is truthy
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb49
1 files changed, 38 insertions, 11 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
index 3d97d71d629..475ac7afcb3 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
@@ -8,13 +8,16 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
before do
- pipeline.variables.build([key: 'VARIABLE', value: 'my variable'])
+ variables = [{ key: 'PRESENT_VARIABLE', value: 'my variable' },
+ { key: 'EMPTY_VARIABLE', value: '' }]
+
+ pipeline.variables.build(variables)
end
describe '.new' do
context 'when pipeline is not provided' do
it 'allows to properly initialize the statement' do
- statement = described_class.new('$VARIABLE')
+ statement = described_class.new('$PRESENT_VARIABLE')
expect(statement.evaluate).to be_nil
end
@@ -72,7 +75,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
context 'when using a single token' do
- let(:text) { '$VARIABLE' }
+ let(:text) { '$PRESENT_VARIABLE' }
it 'returns a single token instance' do
expect(subject.parse_tree)
@@ -84,14 +87,17 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
describe '#evaluate' do
statements = [
- ['$VARIABLE == "my variable"', true],
- ["$VARIABLE == 'my variable'", true],
- ['"my variable" == $VARIABLE', true],
- ['$VARIABLE == null', false],
- ['$VAR == null', true],
- ['null == $VAR', true],
- ['$VARIABLE', 'my variable'],
- ['$VAR', nil]
+ ['$PRESENT_VARIABLE == "my variable"', true],
+ ["$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]
]
statements.each do |expression, value|
@@ -104,4 +110,25 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
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]
+ ]
+
+ 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
+ end
+ end
+ end
+ end
end