debian-mirror-gitlab/spec/lib/gitlab/ci/build/rules/rule_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Build::Rules::Rule do
2019-12-04 20:38:33 +05:30
let(:seed) do
double('build seed',
to_resource: ci_build,
2022-01-26 12:08:38 +05:30
variables_hash: ci_build.scoped_variables.to_hash
2019-12-04 20:38:33 +05:30
)
end
let(:pipeline) { create(:ci_pipeline) }
let(:ci_build) { build(:ci_build, pipeline: pipeline) }
let(:rule) { described_class.new(rule_hash) }
2022-08-13 15:12:31 +05:30
before do
allow(pipeline).to receive(:modified_paths).and_return(['file.rb'])
end
2019-12-04 20:38:33 +05:30
describe '#matches?' do
subject { rule.matches?(pipeline, seed) }
2022-08-13 15:12:31 +05:30
context 'with one matching clause if' do
2019-12-04 20:38:33 +05:30
let(:rule_hash) do
{ if: '$VAR == null', when: 'always' }
end
it { is_expected.to eq(true) }
end
2022-08-13 15:12:31 +05:30
context 'with one matching clause changes' do
let(:rule_hash) do
{ changes: { paths: ['**/*'] }, when: 'always' }
end
it { is_expected.to eq(true) }
end
2019-12-04 20:38:33 +05:30
context 'with two matching clauses' do
let(:rule_hash) do
2022-08-13 15:12:31 +05:30
{ if: '$VAR == null', changes: { paths: ['**/*'] }, when: 'always' }
2019-12-04 20:38:33 +05:30
end
it { is_expected.to eq(true) }
end
context 'with a matching and non-matching clause' do
let(:rule_hash) do
2022-08-13 15:12:31 +05:30
{ if: '$VAR != null', changes: { paths: ['invalid.xyz'] }, when: 'always' }
2019-12-04 20:38:33 +05:30
end
it { is_expected.to eq(false) }
end
context 'with two non-matching clauses' do
let(:rule_hash) do
2022-08-13 15:12:31 +05:30
{ if: '$VAR != null', changes: { paths: ['README'] }, when: 'always' }
2019-12-04 20:38:33 +05:30
end
it { is_expected.to eq(false) }
end
end
end