debian-mirror-gitlab/spec/lib/gitlab/ci/config/external/rules_spec.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe Gitlab::Ci::Config::External::Rules do
let(:rule_hashes) {}
subject(:rules) { described_class.new(rule_hashes) }
describe '#evaluate' do
let(:context) { double(variables: {}) }
subject(:result) { rules.evaluate(context).pass? }
context 'when there is no rule' do
it { is_expected.to eq(true) }
end
2021-11-18 22:05:49 +05:30
context 'when there is a rule with if' do
2021-10-27 15:23:28 +05:30
let(:rule_hashes) { [{ if: '$MY_VAR == "hello"' }] }
context 'when the rule matches' do
let(:context) { double(variables: { MY_VAR: 'hello' }) }
it { is_expected.to eq(true) }
end
context 'when the rule does not match' do
let(:context) { double(variables: { MY_VAR: 'invalid' }) }
it { is_expected.to eq(false) }
end
end
2021-11-18 22:05:49 +05:30
context 'when there is a rule with if and when' do
let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'on_success' }] }
it 'raises an error' do
expect { result }.to raise_error(described_class::InvalidIncludeRulesError,
'invalid include rule: {:if=>"$MY_VAR == \"hello\"", :when=>"on_success"}')
end
end
context 'when there is a rule with exists' do
let(:rule_hashes) { [{ exists: ['$MY_VAR'] }] }
it 'raises an error' do
expect { result }.to raise_error(described_class::InvalidIncludeRulesError,
'invalid include rule: {:exists=>["$MY_VAR"]}')
end
end
2021-10-27 15:23:28 +05:30
end
end