/spec/lib/gitlab/ci/templates/Jobs/build_gitlab_ci_yaml_spec.rb

https://gitlab.com/klml/gitlab-ee · Ruby · 58 lines · 45 code · 12 blank · 1 comment · 0 complexity · d6ed045228ae3725f5d6f388f7c88ec9 MD5 · raw file

  1. # frozen_string_literal: true
  2. require 'spec_helper'
  3. RSpec.describe 'Jobs/Build.gitlab-ci.yml' do
  4. subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Jobs/Build') }
  5. describe 'the created pipeline' do
  6. let_it_be(:project) { create(:project, :repository) }
  7. let_it_be(:user) { project.owner }
  8. let(:default_branch) { 'master' }
  9. let(:pipeline_ref) { default_branch }
  10. let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_ref) }
  11. let(:pipeline) { service.execute!(:push) }
  12. let(:build_names) { pipeline.builds.pluck(:name) }
  13. before do
  14. stub_ci_pipeline_yaml_file(template.content)
  15. allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
  16. allow(project).to receive(:default_branch).and_return(default_branch)
  17. end
  18. context 'on master' do
  19. it 'creates the build job' do
  20. expect(build_names).to contain_exactly('build')
  21. end
  22. end
  23. context 'on another branch' do
  24. let(:pipeline_ref) { 'feature' }
  25. it 'creates the build job' do
  26. expect(build_names).to contain_exactly('build')
  27. end
  28. end
  29. context 'on tag' do
  30. let(:pipeline_ref) { 'v1.0.0' }
  31. it 'creates the build job' do
  32. expect(pipeline).to be_tag
  33. expect(build_names).to contain_exactly('build')
  34. end
  35. end
  36. context 'on merge request' do
  37. let(:service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) }
  38. let(:merge_request) { create(:merge_request, :simple, source_project: project) }
  39. let(:pipeline) { service.execute(merge_request) }
  40. it 'has no jobs' do
  41. expect(pipeline).to be_merge_request_event
  42. expect(build_names).to be_empty
  43. end
  44. end
  45. end
  46. end