summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-03-07 12:30:34 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-07 12:30:34 +0100
commit32b09b8847955052765895063297181835c45b8c (patch)
treead8a173ec83c8d48dd246215b87b2c72c792252f /spec
parent0905fe4d7ad778eba78d57da2fa1f38575721622 (diff)
downloadgitlab-ce-32b09b8847955052765895063297181835c45b8c.tar.gz
Add minor refactoringfeature/runner-jobs-v4-api
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/build/image_spec.rb37
-rw-r--r--spec/lib/gitlab/ci/build/step_spec.rb28
-rw-r--r--spec/requests/api/runner_spec.rb12
3 files changed, 53 insertions, 24 deletions
diff --git a/spec/lib/gitlab/ci/build/image_spec.rb b/spec/lib/gitlab/ci/build/image_spec.rb
index 0816f53c604..382385dfd6b 100644
--- a/spec/lib/gitlab/ci/build/image_spec.rb
+++ b/spec/lib/gitlab/ci/build/image_spec.rb
@@ -10,18 +10,27 @@ describe Gitlab::Ci::Build::Image 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) }
+ it 'fabricates an object of the proper class' do
+ is_expected.to be_kind_of(described_class)
+ end
+
+ it 'populates fabricated object with the proper name attribute' do
+ expect(subject.name).to eq(image_name)
+ end
context 'when image name is empty' do
let(:image_name) { '' }
- it { is_expected.to eq(nil) }
+ it 'does not fabricate an object' do
+ is_expected.to be_nil
+ end
end
end
context 'when image is not defined in job' do
- it { is_expected.to eq(nil) }
+ it 'does not fabricate an object' do
+ is_expected.to be_nil
+ end
end
end
@@ -32,21 +41,27 @@ describe Gitlab::Ci::Build::Image 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) }
+ it 'fabricates an non-empty array of objects' do
+ is_expected.to be_kind_of(Array)
+ is_expected.not_to be_empty
+ expect(subject.first.name).to eq(service_image_name)
+ end
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 }
+ it 'fabricates an empty array' do
+ is_expected.to be_kind_of(Array)
+ is_expected.to be_empty
+ end
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 }
+ it 'fabricates an empty array' do
+ is_expected.to be_kind_of(Array)
+ is_expected.to be_empty
+ end
end
end
end
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb
index 8c9aa5ec988..2a314a744ca 100644
--- a/spec/lib/gitlab/ci/build/step_spec.rb
+++ b/spec/lib/gitlab/ci/build/step_spec.rb
@@ -6,28 +6,34 @@ describe Gitlab::Ci::Build::Step do
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 }
+ it 'fabricates an object' do
+ expect(subject.name).to eq(:script)
+ expect(subject.script).to eq(['ls -la', 'date'])
+ expect(subject.timeout).to eq(job.timeout)
+ expect(subject.when).to eq('on_success')
+ expect(subject.allow_failure).to be_falsey
+ end
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) }
+ it 'doesn not fabricate an object' do
+ is_expected.to be_nil
+ end
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 }
+ 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
end
end
end
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index a1819c4d5d3..15d458e0795 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -155,7 +155,10 @@ describe API::Runner do
let(:project) { create(:empty_project, shared_runners_enabled: false) }
let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') }
let(:runner) { create(:ci_runner) }
- let!(:job) { create(:ci_build, :artifacts, :extended_options, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0, commands: "ls\ndate") }
+ let!(:job) do
+ create(:ci_build, :artifacts, :extended_options,
+ pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0, commands: "ls\ndate")
+ end
before { project.runners << runner }
@@ -283,6 +286,7 @@ describe API::Runner do
'project_id' => job.project.id,
'project_name' => job.project.name }
end
+
let(:expected_git_info) do
{ 'repo_url' => job.repo_url,
'ref' => job.ref,
@@ -290,6 +294,7 @@ describe API::Runner do
'before_sha' => job.before_sha,
'ref_type' => 'branch' }
end
+
let(:expected_steps) do
[{ 'name' => 'script',
'script' => %w(ls date),
@@ -302,11 +307,13 @@ describe API::Runner do
'when' => 'always',
'allow_failure' => true }]
end
+
let(:expected_variables) do
[{ 'key' => 'CI_BUILD_NAME', 'value' => 'spinach', 'public' => true },
{ 'key' => 'CI_BUILD_STAGE', 'value' => 'test', 'public' => true },
{ 'key' => 'DB_NAME', 'value' => 'postgres', 'public' => true }]
end
+
let(:expected_artifacts) do
[{ 'name' => 'artifacts_file',
'untracked' => false,
@@ -314,13 +321,14 @@ describe API::Runner do
'when' => 'always',
'expire_in' => '7d' }]
end
+
let(:expected_cache) do
[{ 'key' => 'cache_key',
'untracked' => false,
'paths' => ['vendor/*'] }]
end
- it 'starts a job' do
+ it 'picks a job' do
request_job info: { platform: :darwin }
expect(response).to have_http_status(201)