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
def truthful?
evaluate.present?
rescue StatementError
false
end
def valid?
......
require 'spec_helper'
require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Statement do
subject do
......@@ -114,7 +114,8 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
['$UNDEFINED_VARIABLE == null', true],
['$PRESENT_VARIABLE', true],
['$UNDEFINED_VARIABLE', false],
['$EMPTY_VARIABLE', false]
['$EMPTY_VARIABLE', false],
['$INVALID = 1', false]
]
statements.each do |expression, value|
......@@ -126,5 +127,16 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
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
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