Commit 8da2ff21 authored by James Fargher's avatar James Fargher

Improved specs based on review feedback

parent f6b10751
......@@ -3,14 +3,15 @@
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) }
describe '#satisfied_by?' do
it_behaves_like 'a glob matching rule' do
let(:pipeline) { build(:ci_pipeline) }
before do
allow(pipeline).to receive(:modified_paths).and_return(files.keys)
end
before do
allow(pipeline).to receive(:modified_paths).and_return(files.keys)
end
it_behaves_like 'a glob matching rule'
subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
end
end
end
......@@ -3,11 +3,12 @@
require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule::Clause::Exists do
describe 'satisfied_by?' 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) }
describe '#satisfied_by?' do
it_behaves_like 'a glob matching rule' do
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
it_behaves_like 'a glob matching rule'
subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
end
end
end
......@@ -4,20 +4,20 @@ 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
'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
'ext top-level match' | ['*.go'] | { 'main.go' => '', 'cmd/goproject/main.go' => '' } | true
'ext nested no match' | ['*.go'] | { 'cmd/goproject/main.go' => '' } | false
'ext slash no match' | ['/*.go'] | { 'main.go' => '', 'cmd/goproject/main.go' => '' } | false
end
with_them do
it 'checks if any files exist' do
expect(subject.satisfied_by?(pipeline, nil)).to eq(satisfied)
end
it { is_expected.to eq(satisfied) }
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