Commit 7fbafab1 authored by James Fargher's avatar James Fargher

Use a shared example for changes and exists glob matching rules

This ensures that the glob matching used by all rules are
consistent.
parent 6de09370
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
describe 'satisfied_by?' do
let(:pipeline) { build(:ci_pipeline) }
subject { described_class.new(globs) }
before do
allow(pipeline).to receive(:modified_paths).and_return(files.keys)
end
it_behaves_like 'a glob matching rule'
end
end
......@@ -4,27 +4,10 @@ require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule::Clause::Exists do
describe 'satisfied_by?' do
using RSpec::Parameterized::TableSyntax
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
subject { described_class.new(globs) }
where(:case_name, :globs, :files, :satisfied) do
'exact top-level match' | ['Dockerfile'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'exact top-level no match' | ['Dockerfile'] | { 'Gemfile' => '' } | false
'pattern top-level match' | ['Docker*'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'pattern top-level no match' | ['Docker*'] | { 'Gemfile' => '' } | false
'exact nested match' | ['project/build.properties'] | { 'project/build.properties' => '' } | true
'exact nested no match' | ['project/build.properties'] | { 'project/README.md' => '' } | false
'pattern nested match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/goproject.go' => '' } | true
'pattern nested no match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/README.md' => '' } | false
end
with_them do
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
subject { described_class.new(globs) }
it 'checks if any files exist' do
expect(subject.satisfied_by?(pipeline, nil)).to eq(satisfied)
end
end
it_behaves_like 'a glob matching rule'
end
end
# frozen_string_literal: true
RSpec.shared_examples 'a glob matching rule' do
using RSpec::Parameterized::TableSyntax
where(:case_name, :globs, :files, :satisfied) do
'exact top-level match' | ['Dockerfile'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'exact top-level no match' | ['Dockerfile'] | { 'Gemfile' => '' } | false
'pattern top-level match' | ['Docker*'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'pattern top-level no match' | ['Docker*'] | { 'Gemfile' => '' } | false
'exact nested match' | ['project/build.properties'] | { 'project/build.properties' => '' } | true
'exact nested no match' | ['project/build.properties'] | { 'project/README.md' => '' } | false
'pattern nested match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/goproject.go' => '' } | true
'pattern nested no match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/README.md' => '' } | false
'leading slash no match' | ['/*.go'] | { 'main.go' => '' } | false
end
with_them do
it 'checks if any files exist' do
expect(subject.satisfied_by?(pipeline, nil)).to eq(satisfied)
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