Test against all types and more status:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7508#note_18748231
This commit is contained in:
Lin Jen-Shin 2016-11-21 22:39:58 +08:00
parent 9b1240783b
commit d09d6ad01d
1 changed files with 46 additions and 38 deletions

View File

@ -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