2017-03-02 11:44:15 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Build::Step do
|
|
|
|
describe '#from_commands' do
|
2017-07-06 10:57:34 -04:00
|
|
|
shared_examples 'has correct script' do
|
|
|
|
subject { described_class.from_commands(job) }
|
|
|
|
|
|
|
|
it 'fabricates an object' do
|
|
|
|
expect(subject.name).to eq(:script)
|
|
|
|
expect(subject.script).to eq(script)
|
|
|
|
expect(subject.timeout).to eq(job.timeout)
|
|
|
|
expect(subject.when).to eq('on_success')
|
|
|
|
expect(subject.allow_failure).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commands are specified' do
|
|
|
|
it_behaves_like 'has correct script' do
|
|
|
|
let(:job) { create(:ci_build, :no_options, commands: "ls -la\ndate") }
|
|
|
|
let(:script) { ['ls -la', 'date'] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when script option is specified' do
|
|
|
|
it_behaves_like 'has correct script' do
|
|
|
|
let(:job) { create(:ci_build, :no_options, options: { script: ["ls -la\necho aaa", "date"] }) }
|
|
|
|
let(:script) { ["ls -la\necho aaa", 'date'] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when before and script option is specified' do
|
|
|
|
it_behaves_like 'has correct script' do
|
|
|
|
let(:job) do
|
|
|
|
create(:ci_build, options: {
|
|
|
|
before_script: ["ls -la\necho aaa"],
|
|
|
|
script: ["date"]
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:script) { ["ls -la\necho aaa", 'date'] }
|
|
|
|
end
|
2017-03-07 06:30:34 -05:00
|
|
|
end
|
2017-03-02 11:44:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#from_after_script' do
|
2017-07-06 10:57:34 -04:00
|
|
|
let(:job) { create(:ci_build) }
|
|
|
|
|
2017-03-02 11:44:15 -05:00
|
|
|
subject { described_class.from_after_script(job) }
|
|
|
|
|
|
|
|
context 'when after_script is empty' do
|
2017-03-07 06:30:34 -05:00
|
|
|
it 'doesn not fabricate an object' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
2017-03-02 11:44:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when after_script is not empty' do
|
2017-03-23 09:37:49 -04:00
|
|
|
let(:job) { create(:ci_build, options: { after_script: ['ls -la', 'date'] }) }
|
2017-03-02 11:44:15 -05:00
|
|
|
|
2017-03-07 06:30:34 -05:00
|
|
|
it 'fabricates an object' do
|
|
|
|
expect(subject.name).to eq(:after_script)
|
|
|
|
expect(subject.script).to eq(['ls -la', 'date'])
|
|
|
|
expect(subject.timeout).to eq(job.timeout)
|
|
|
|
expect(subject.when).to eq('always')
|
|
|
|
expect(subject.allow_failure).to be_truthy
|
|
|
|
end
|
2017-03-02 11:44:15 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-06 05:51:09 -05:00
|
|
|
end
|