summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 17:44:15 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 17:48:00 +0100
commit5c1aa5fb65ec7474956e6972e40b04b3a967c338 (patch)
tree9588d71165d0cbc57e56da1c123a201c9d2a5c8e /spec/lib
parent1bbf2c2cd16140aa95bbf93368209b16795172bd (diff)
downloadgitlab-ce-5c1aa5fb65ec7474956e6972e40b04b3a967c338.tar.gz
Add some fixes and refactoring after review
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/build/image_spec.rb52
-rw-r--r--spec/lib/gitlab/ci/build/step_spec.rb33
2 files changed, 85 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/build/image_spec.rb b/spec/lib/gitlab/ci/build/image_spec.rb
new file mode 100644
index 00000000000..c561e4f40e8
--- /dev/null
+++ b/spec/lib/gitlab/ci/build/image_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+describe Gitlab::Ci::Build::Image do
+ let(:job) { create(:ci_build, :no_options) }
+
+ describe '#from_image' do
+ subject { described_class.from_image(job) }
+
+ context 'when image is defined in job' do
+ let(:image_name) { 'ruby:2.1' }
+ let(:job) { create(:ci_build, options: { image: image_name } ) }
+
+ it { is_expected.to be_kind_of(described_class) }
+ it { expect(subject.name).to eq(image_name) }
+
+ context 'when image name is empty' do
+ let(:image_name) { '' }
+
+ it { is_expected.to eq(nil) }
+ end
+ end
+
+ context 'when image is not defined in job' do
+ it { is_expected.to eq(nil) }
+ end
+ end
+
+ describe '#from_services' do
+ subject { described_class.from_services(job) }
+
+ context 'when services are defined in job' do
+ let(:service_image_name) { 'postgres' }
+ let(:job) { create(:ci_build, options: { services: [service_image_name] }) }
+
+ it { is_expected.to be_kind_of(Array) }
+ it { is_expected.not_to be_empty }
+ it { expect(subject[0].name).to eq(service_image_name) }
+
+ context 'when service image name is empty' do
+ let(:service_image_name) { '' }
+
+ it { is_expected.to be_kind_of(Array) }
+ it { is_expected.to be_empty }
+ end
+ end
+
+ context 'when services are not defined in job' do
+ it { is_expected.to be_kind_of(Array) }
+ it { is_expected.to be_empty }
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb
new file mode 100644
index 00000000000..630d7ff6c66
--- /dev/null
+++ b/spec/lib/gitlab/ci/build/step_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Gitlab::Ci::Build::Step do
+ let(:job) { create(:ci_build, :no_options, commands: "ls -la\ndate") }
+
+ describe '#from_commands' do
+ subject { described_class.from_commands(job) }
+
+ it { expect(subject.name).to eq(:script) }
+ it { expect(subject.script).to eq(['ls -la', 'date']) }
+ it { expect(subject.timeout).to eq(job.timeout) }
+ it { expect(subject.when).to eq('on_success') }
+ it { expect(subject.allow_failure).to be_falsey }
+ end
+
+ describe '#from_after_script' do
+ subject { described_class.from_after_script(job) }
+
+ context 'when after_script is empty' do
+ it { is_expected.to be(nil) }
+ end
+
+ context 'when after_script is not empty' do
+ let(:job) { create(:ci_build, options: { after_script: "ls -la\ndate" }) }
+
+ it { expect(subject.name).to eq(:after_script) }
+ it { expect(subject.script).to eq(['ls -la', 'date']) }
+ it { expect(subject.timeout).to eq(job.timeout) }
+ it { expect(subject.when).to eq('always') }
+ it { expect(subject.allow_failure).to be_truthy }
+ end
+ end
+end \ No newline at end of file