require 'spec_helper'
describe Ci::BuildRunnerPresenter do
let(:presenter) { described_class.new(build) }
let(:archive) { { paths: ['sample.txt'] } }
let(:archive_expectation) do
{
artifact_type: :archive,
artifact_format: :zip,
paths: archive[:paths],
untracked: archive[:untracked]
}
end
describe '#artifacts' do
context "when option contains archive-type artifacts" do
let(:build) { create(:ci_build, options: { artifacts: archive } ) }
it 'presents correct hash' do
expect(presenter.artifacts.first).to include(archive_expectation)
context "when untracked is specified" do
let(:archive) { { untracked: true } }
context "when untracked and paths are missing" do
let(:archive) { { when: 'always' } }
it 'does not present hash' do
expect(presenter.artifacts).to be_empty
context "with reports" do
Ci::JobArtifact::DEFAULT_FILE_NAMES.each do |file_type, filename|
let(:report) { { "#{file_type}": [filename] } }
let(:build) { create(:ci_build, options: { artifacts: { reports: report } } ) }
let(:report_expectation) do
name: filename,
artifact_type: :"#{file_type}",
artifact_format: :gzip,
paths: [filename],
when: 'always'
expect(presenter.artifacts.first).to include(report_expectation)
context "when option has both archive and reports specification" do
let(:report) { { junit: ['junit.xml'] } }
let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } } ) }
name: 'junit.xml',
artifact_type: :junit,
paths: ['junit.xml'],
expect(presenter.artifacts.second).to include(report_expectation)
context "when archive specifies 'expire_in' keyword" do
let(:archive) { { paths: ['sample.txt'], expire_in: '3 mins 4 sec' } }
it 'inherits expire_in from archive' do
expect(presenter.artifacts.first).to include({ **archive_expectation, expire_in: '3 mins 4 sec' })
expect(presenter.artifacts.second).to include({ **report_expectation, expire_in: '3 mins 4 sec' })
context "when option has no artifact keywords" do
let(:build) { create(:ci_build, :no_options) }
expect(presenter.artifacts).to be_nil