summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-10-22 08:55:16 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-10-22 08:55:16 +0000
commitb5dfa745800a38cc17cadc0aa49a933713bdc1a5 (patch)
tree8f843e2578b1c7d3ab0e6f1436b06ac89f2de0a9 /spec
parent631f4e2f54290b539fa3a7bc928589b1949adc34 (diff)
parent995d2d13a3e3aea2cd68ebf4a4017a597b0428f2 (diff)
downloadgitlab-ce-b5dfa745800a38cc17cadc0aa49a933713bdc1a5.tar.gz
Merge branch 'improve-specs-for-ci-processbuildservice' into 'master'
Improve specs for Ci::ProcessBuildService Closes #52279 See merge request gitlab-org/gitlab-ce!22254
Diffstat (limited to 'spec')
-rw-r--r--spec/services/ci/process_build_service_spec.rb232
1 files changed, 77 insertions, 155 deletions
diff --git a/spec/services/ci/process_build_service_spec.rb b/spec/services/ci/process_build_service_spec.rb
index 9f47439dc4a..9a53b32394d 100644
--- a/spec/services/ci/process_build_service_spec.rb
+++ b/spec/services/ci/process_build_service_spec.rb
@@ -11,213 +11,135 @@ describe Ci::ProcessBuildService, '#execute' do
project.add_maintainer(user)
end
- shared_examples_for 'Enqueuing properly' do |valid_statuses_for_when|
- valid_statuses_for_when.each do |status_for_prior_stages|
- context "when status for prior stages is #{status_for_prior_stages}" do
- let(:current_status) { status_for_prior_stages }
-
- %w[created skipped manual scheduled].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
-
- it 'enqueues the build' do
- expect { subject }.to change { build.status }.to('pending')
- end
- end
- end
+ context 'when build has on_success option' do
+ let(:build) { create(:ci_build, :created, when: :on_success, user: user, project: project) }
- %w[pending running success failed canceled].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
- it 'does not change the build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('pending')
end
end
- (HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages|
- let(:current_status) { status_for_prior_stages }
-
- context "when status for prior stages is #{status_for_prior_stages}" do
- %w[created pending].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
- it 'skips the build' do
- expect { subject }.to change { build.status }.to('skipped')
- end
- end
- end
-
- (HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, when: when_option, user: user, project: project) }
-
- it 'does not change build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('skipped')
end
end
end
- shared_examples_for 'Actionizing properly' do |valid_statuses_for_when|
- valid_statuses_for_when.each do |status_for_prior_stages|
- context "when status for prior stages is #{status_for_prior_stages}" do
- let(:current_status) { status_for_prior_stages }
-
- %w[created].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
-
- it 'enqueues the build' do
- expect { subject }.to change { build.status }.to('manual')
- end
- end
- end
+ context 'when build has on_failure option' do
+ let(:build) { create(:ci_build, :created, when: :on_failure, user: user, project: project) }
- %w[manual skipped pending running success failed canceled scheduled].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
- it 'does not change the build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('skipped')
end
end
- (HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages|
- let(:current_status) { status_for_prior_stages }
-
- context "when status for prior stages is #{status_for_prior_stages}" do
- %w[created pending].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
-
- it 'skips the build' do
- expect { subject }.to change { build.status }.to('skipped')
- end
- end
- end
-
- (HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :actionable, user: user, project: project) }
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
- it 'does not change build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('pending')
end
end
end
- shared_examples_for 'Scheduling properly' do |valid_statuses_for_when|
- valid_statuses_for_when.each do |status_for_prior_stages|
- context "when status for prior stages is #{status_for_prior_stages}" do
- let(:current_status) { status_for_prior_stages }
-
- %w[created].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
-
- it 'enqueues the build' do
- expect { subject }.to change { build.status }.to('scheduled')
- end
- end
- end
+ context 'when build has always option' do
+ let(:build) { create(:ci_build, :created, when: :always, user: user, project: project) }
- %w[manual skipped pending running success failed canceled scheduled].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
- it 'does not change the build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('pending')
end
end
- (HasStatus::AVAILABLE_STATUSES - valid_statuses_for_when).each do |status_for_prior_stages|
- let(:current_status) { status_for_prior_stages }
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
- context "when status for prior stages is #{status_for_prior_stages}" do
- %w[created pending].each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
-
- it 'skips the build' do
- expect { subject }.to change { build.status }.to('skipped')
- end
- end
- end
-
- (HasStatus::AVAILABLE_STATUSES - %w[created pending]).each do |status|
- context "when build status is #{status}" do
- let(:build) { create(:ci_build, status.to_sym, :schedulable, user: user, project: project) }
-
- it 'does not change build status' do
- expect { subject }.not_to change { build.status }
- end
- end
- end
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('pending')
end
end
end
- context 'when build has on_success option' do
- let(:when_option) { :on_success }
-
- it_behaves_like 'Enqueuing properly', %w[success skipped]
- end
-
- context 'when build has on_failure option' do
- let(:when_option) { :on_failure }
-
- it_behaves_like 'Enqueuing properly', %w[failed]
- end
+ context 'when build has manual option' do
+ let(:build) { create(:ci_build, :created, :actionable, user: user, project: project) }
- context 'when build has always option' do
- let(:when_option) { :always }
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
- it_behaves_like 'Enqueuing properly', %w[success failed skipped]
- end
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('manual')
+ end
+ end
- context 'when build has manual option' do
- let(:when_option) { :manual }
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
- it_behaves_like 'Actionizing properly', %w[success skipped]
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('skipped')
+ end
+ end
end
context 'when build has delayed option' do
- let(:when_option) { :delayed }
-
before do
allow(Ci::BuildScheduleWorker).to receive(:perform_at) { }
end
+ let(:build) { create(:ci_build, :created, :schedulable, user: user, project: project) }
+
context 'when ci_enable_scheduled_build is enabled' do
before do
stub_feature_flags(ci_enable_scheduled_build: true)
end
- it_behaves_like 'Scheduling properly', %w[success skipped]
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
+
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('scheduled')
+ end
+ end
+
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
+
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('skipped')
+ end
+ end
end
- context 'when ci_enable_scheduled_build is enabled' do
+ context 'when ci_enable_scheduled_build is disabled' do
before do
stub_feature_flags(ci_enable_scheduled_build: false)
end
- it_behaves_like 'Actionizing properly', %w[success skipped]
+ context 'when current status is success' do
+ let(:current_status) { 'success' }
+
+ it 'changes the build status' do
+ expect { subject }.to change { build.status }.to('manual')
+ end
+ end
+
+ context 'when current status is failed' do
+ let(:current_status) { 'failed' }
+
+ it 'does not change the build status' do
+ expect { subject }.to change { build.status }.to('skipped')
+ end
+ end
end
end
end