diff options
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb index 6b6e25ca1dd..4b4a7f4ce9d 100644 --- a/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb @@ -47,3 +47,47 @@ RSpec.shared_examples 'file template shared examples' do |filename, file_extensi end end end + +RSpec.shared_examples 'acts as branch pipeline' do |jobs| + context 'when branch pipeline' do + let(:pipeline_branch) { default_branch } + let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_branch) } + let(:pipeline) { service.execute!(:push).payload } + + it 'includes a job' do + expect(pipeline.builds.pluck(:name)).to match_array(jobs) + end + end +end + +RSpec.shared_examples 'acts as MR pipeline' do |jobs, files| + context 'when MR pipeline' do + let(:pipeline_branch) { 'patch-1' } + let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) } + let(:pipeline) { service.execute(merge_request).payload } + + let(:merge_request) do + create(:merge_request, + source_project: project, + source_branch: pipeline_branch, + target_project: project, + target_branch: default_branch) + end + + before do + files.each do |filename, contents| + project.repository.create_file( + project.creator, + filename, + contents, + message: "Add #{filename}", + branch_name: pipeline_branch) + end + end + + it 'includes a job' do + expect(pipeline).to be_merge_request_event + expect(pipeline.builds.pluck(:name)).to match_array(jobs) + end + end +end |