Improve readability of specs for pipeline stages
This commit is contained in:
parent
cff9c16be7
commit
e66b0414cb
1 changed files with 63 additions and 38 deletions
|
@ -122,55 +122,80 @@ describe Ci::Pipeline, models: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#stages' do
|
describe 'pipeline stages' do
|
||||||
before do
|
before do
|
||||||
create(:commit_status, pipeline: pipeline, stage: 'build', name: 'linux', stage_idx: 0, status: 'success')
|
create(:commit_status, pipeline: pipeline,
|
||||||
create(:commit_status, pipeline: pipeline, stage: 'build', name: 'mac', stage_idx: 0, status: 'failed')
|
stage: 'build',
|
||||||
create(:commit_status, pipeline: pipeline, stage: 'deploy', name: 'staging', stage_idx: 2, status: 'running')
|
name: 'linux',
|
||||||
create(:commit_status, pipeline: pipeline, stage: 'test', name: 'rspec', stage_idx: 1, status: 'success')
|
stage_idx: 0,
|
||||||
|
status: 'success')
|
||||||
|
|
||||||
|
create(:commit_status, pipeline: pipeline,
|
||||||
|
stage: 'build',
|
||||||
|
name: 'mac',
|
||||||
|
stage_idx: 0,
|
||||||
|
status: 'failed')
|
||||||
|
|
||||||
|
create(:commit_status, pipeline: pipeline,
|
||||||
|
stage: 'deploy',
|
||||||
|
name: 'staging',
|
||||||
|
stage_idx: 2,
|
||||||
|
status: 'running')
|
||||||
|
|
||||||
|
create(:commit_status, pipeline: pipeline,
|
||||||
|
stage: 'test',
|
||||||
|
name: 'rspec',
|
||||||
|
stage_idx: 1,
|
||||||
|
status: 'success')
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { pipeline.stages }
|
describe '#stages' do
|
||||||
|
subject { pipeline.stages }
|
||||||
|
|
||||||
context 'stages list' do
|
context 'stages list' do
|
||||||
it 'returns ordered list of stages' do
|
it 'returns ordered list of stages' do
|
||||||
expect(subject.map(&:name)).to eq(%w[build test deploy])
|
expect(subject.map(&:name)).to eq(%w[build test deploy])
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns a valid number of stages' do
|
|
||||||
expect(pipeline.stages_count).to eq(3)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns a valid names of stages' do
|
|
||||||
expect(pipeline.stages_name).to eq(['build', 'test', 'deploy'])
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'stages with statuses' do
|
|
||||||
let(:statuses) do
|
|
||||||
subject.map do |stage|
|
|
||||||
[stage.name, stage.status]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns list of stages with statuses' do
|
context 'stages with statuses' do
|
||||||
expect(statuses).to eq([['build', 'failed'],
|
let(:statuses) do
|
||||||
['test', 'success'],
|
subject.map { |stage| [stage.name, stage.status] }
|
||||||
['deploy', 'running']
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when build is retried' do
|
|
||||||
before do
|
|
||||||
create(:commit_status, pipeline: pipeline, stage: 'build', name: 'mac', stage_idx: 0, status: 'success')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ignores the previous state' do
|
it 'returns list of stages with correct statuses' do
|
||||||
expect(statuses).to eq([['build', 'success'],
|
expect(statuses).to eq([['build', 'failed'],
|
||||||
['test', 'success'],
|
['test', 'success'],
|
||||||
['deploy', 'running']
|
['deploy', 'running']])
|
||||||
])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when commit status is retried' do
|
||||||
|
before do
|
||||||
|
create(:commit_status, pipeline: pipeline,
|
||||||
|
stage: 'build',
|
||||||
|
name: 'mac',
|
||||||
|
stage_idx: 0,
|
||||||
|
status: 'success')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores the previous state' do
|
||||||
|
expect(statuses).to eq([['build', 'success'],
|
||||||
|
['test', 'success'],
|
||||||
|
['deploy', 'running']])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#stages_count' do
|
||||||
|
it 'returns a valid number of stages' do
|
||||||
|
expect(pipeline.stages_count).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#stages_name' do
|
||||||
|
it 'returns a valid names of stages' do
|
||||||
|
expect(pipeline.stages_name).to eq(['build', 'test', 'deploy'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue