diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb index 788c84bf5de..9defb17dc92 100644 --- a/spec/models/concerns/has_status_spec.rb +++ b/spec/models/concerns/has_status_spec.rb @@ -124,30 +124,28 @@ describe HasStatus do end end - def self.random_type - %i[ci_build generic_commit_status].sample - end - context 'for scope with one status' do - shared_examples 'having a job' do |type, status| - context "when it's #{status} #{type} job" do - let!(:job) { create(type, status) } + shared_examples 'having a job' do |status| + %i[ci_build generic_commit_status].each do |type| + context "when it's #{status} #{type} job" do + let!(:job) { create(type, status) } - describe ".#{status}" do - it 'contains the job' do - expect(CommitStatus.public_send(status).all). - to contain_exactly(job) - end - end - - describe '.relevant' do - if status == :created - it 'contains nothing' do - expect(CommitStatus.relevant.all).to be_empty - end - else + describe ".#{status}" do it 'contains the job' do - expect(CommitStatus.relevant.all).to contain_exactly(job) + expect(CommitStatus.public_send(status).all). + to contain_exactly(job) + end + end + + describe '.relevant' do + if status == :created + it 'contains nothing' do + expect(CommitStatus.relevant.all).to be_empty + end + else + it 'contains the job' do + expect(CommitStatus.relevant.all).to contain_exactly(job) + end end end end @@ -156,27 +154,31 @@ describe HasStatus do %i[created running pending success failed canceled skipped].each do |status| - it_behaves_like 'having a job', random_type, status + it_behaves_like 'having a job', status end end context 'for scope with more statuses' do - shared_examples 'containing the job' do |type, status| - context "when it's #{status} #{type} job" do - let!(:job) { create(type, status) } + shared_examples 'containing the job' do |status| + %i[ci_build generic_commit_status].each do |type| + context "when it's #{status} #{type} job" do + let!(:job) { create(type, status) } - it 'contains the job' do - is_expected.to contain_exactly(job) + it 'contains the job' do + is_expected.to contain_exactly(job) + end end end end - shared_examples 'not containing the job' do |type, status| - context "when it's #{status} #{type} job" do - let!(:job) { create(type, status) } + shared_examples 'not containing the job' do |status| + %i[ci_build generic_commit_status].each do |type| + context "when it's #{status} #{type} job" do + let!(:job) { create(type, status) } - it 'contains nothing' do - is_expected.to be_empty + it 'contains nothing' do + is_expected.to be_empty + end end end end @@ -185,30 +187,36 @@ describe HasStatus do subject { CommitStatus.running_or_pending } %i[running pending].each do |status| - it_behaves_like 'containing the job', random_type, status + it_behaves_like 'containing the job', status end - it_behaves_like 'not containing the job', random_type, :created + %i[created failed success].each do |status| + it_behaves_like 'not containing the job', status + end end describe '.finished' do subject { CommitStatus.finished } %i[success failed canceled].each do |status| - it_behaves_like 'containing the job', random_type, status + it_behaves_like 'containing the job', status end - it_behaves_like 'not containing the job', random_type, :created + %i[created running pending].each do |status| + it_behaves_like 'not containing the job', status + end end describe '.cancelable' do subject { CommitStatus.cancelable } %i[running pending created].each do |status| - it_behaves_like 'containing the job', random_type, status + it_behaves_like 'containing the job', status end - it_behaves_like 'not containing the job', random_type, :failed + %i[failed success skipped canceled].each do |status| + it_behaves_like 'not containing the job', status + end end end end