Commit b784a985 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not raise if variable expression can not be evaluated

parent 8b736c91
...@@ -35,6 +35,8 @@ module Gitlab ...@@ -35,6 +35,8 @@ module Gitlab
def truthful? def truthful?
evaluate.present? evaluate.present?
rescue StatementError
false
end end
def valid? def valid?
......
require 'spec_helper' require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Statement do describe Gitlab::Ci::Pipeline::Expression::Statement do
subject do subject do
...@@ -114,7 +114,8 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do ...@@ -114,7 +114,8 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
['$UNDEFINED_VARIABLE == null', true], ['$UNDEFINED_VARIABLE == null', true],
['$PRESENT_VARIABLE', true], ['$PRESENT_VARIABLE', true],
['$UNDEFINED_VARIABLE', false], ['$UNDEFINED_VARIABLE', false],
['$EMPTY_VARIABLE', false] ['$EMPTY_VARIABLE', false],
['$INVALID = 1', false]
] ]
statements.each do |expression, value| statements.each do |expression, value|
...@@ -126,5 +127,16 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do ...@@ -126,5 +127,16 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end end
end end
end end
context 'when evaluating expression raises an error' do
let(:text) { '$PRESENT_VARIABLE' }
it 'returns false' do
allow(subject).to receive(:evaluate)
.and_raise(described_class::StatementError)
expect(subject.truthful?).to be_falsey
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