Commit 4ec1b65b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'refactoring/improve-build-specs' into 'master'

Remove redundant factory namespace in build specs

Extracted from !4351.

See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4351#note_12154604

See merge request !4373
parents c12c77eb 2f1a229d
require 'spec_helper' require 'spec_helper'
describe Ci::Build, models: true do describe Ci::Build, models: true do
let(:project) { FactoryGirl.create :project } let(:project) { create(:project) }
let(:commit) { FactoryGirl.create :ci_commit, project: project } let(:commit) { create(:ci_commit, project: project) }
let(:build) { FactoryGirl.create :ci_build, commit: commit } let(:build) { create(:ci_build, commit: commit) }
it { is_expected.to validate_presence_of :ref } it { is_expected.to validate_presence_of :ref }
it { is_expected.to respond_to :trace_html } it { is_expected.to respond_to :trace_html }
describe '#first_pending' do describe '#first_pending' do
let(:first) { FactoryGirl.create :ci_build, commit: commit, status: 'pending', created_at: Date.yesterday } let!(:first) { create(:ci_build, commit: commit, status: 'pending', created_at: Date.yesterday) }
let(:second) { FactoryGirl.create :ci_build, commit: commit, status: 'pending' } let!(:second) { create(:ci_build, commit: commit, status: 'pending') }
before { first; second }
subject { Ci::Build.first_pending } subject { Ci::Build.first_pending }
it { is_expected.to be_a(Ci::Build) } it { is_expected.to be_a(Ci::Build) }
...@@ -219,8 +218,8 @@ describe Ci::Build, models: true do ...@@ -219,8 +218,8 @@ describe Ci::Build, models: true do
it { is_expected.to eq(predefined_variables + yaml_variables + secure_variables) } it { is_expected.to eq(predefined_variables + yaml_variables + secure_variables) }
context 'and trigger variables' do context 'and trigger variables' do
let(:trigger) { FactoryGirl.create :ci_trigger, project: project } let(:trigger) { create(:ci_trigger, project: project) }
let(:trigger_request) { FactoryGirl.create :ci_trigger_request_with_variables, commit: commit, trigger: trigger } let(:trigger_request) { create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger) }
let(:trigger_variables) do let(:trigger_variables) do
[ [
{ key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false } { key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false }
...@@ -329,7 +328,7 @@ describe Ci::Build, models: true do ...@@ -329,7 +328,7 @@ describe Ci::Build, models: true do
end end
context 'if there are runner' do context 'if there are runner' do
let(:runner) { FactoryGirl.create :ci_runner } let(:runner) { create(:ci_runner) }
before do before do
build.project.runners << runner build.project.runners << runner
...@@ -366,7 +365,7 @@ describe Ci::Build, models: true do ...@@ -366,7 +365,7 @@ describe Ci::Build, models: true do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
context "and there are specific runner" do context "and there are specific runner" do
let(:runner) { FactoryGirl.create :ci_runner, contacted_at: 1.second.ago } let(:runner) { create(:ci_runner, contacted_at: 1.second.ago) }
before do before do
build.project.runners << runner build.project.runners << runner
...@@ -415,7 +414,7 @@ describe Ci::Build, models: true do ...@@ -415,7 +414,7 @@ describe Ci::Build, models: true do
end end
describe '#repo_url' do describe '#repo_url' do
let(:build) { FactoryGirl.create :ci_build } let(:build) { create(:ci_build) }
let(:project) { build.project } let(:project) { build.project }
subject { build.repo_url } subject { build.repo_url }
...@@ -429,10 +428,10 @@ describe Ci::Build, models: true do ...@@ -429,10 +428,10 @@ describe Ci::Build, models: true do
end end
describe '#depends_on_builds' do describe '#depends_on_builds' do
let!(:build) { FactoryGirl.create :ci_build, commit: commit, name: 'build', stage_idx: 0, stage: 'build' } let!(:build) { create(:ci_build, commit: commit, name: 'build', stage_idx: 0, stage: 'build') }
let!(:rspec_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rspec', stage_idx: 1, stage: 'test' } let!(:rspec_test) { create(:ci_build, commit: commit, name: 'rspec', stage_idx: 1, stage: 'test') }
let!(:rubocop_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rubocop', stage_idx: 1, stage: 'test' } let!(:rubocop_test) { create(:ci_build, commit: commit, name: 'rubocop', stage_idx: 1, stage: 'test') }
let!(:staging) { FactoryGirl.create :ci_build, commit: commit, name: 'staging', stage_idx: 2, stage: 'deploy' } let!(:staging) { create(:ci_build, commit: commit, name: 'staging', stage_idx: 2, stage: 'deploy') }
it 'to have no dependents if this is first build' do it 'to have no dependents if this is first build' do
expect(build.depends_on_builds).to be_empty expect(build.depends_on_builds).to be_empty
...@@ -453,8 +452,7 @@ describe Ci::Build, models: true do ...@@ -453,8 +452,7 @@ describe Ci::Build, models: true do
end end
def create_mr(build, commit, factory: :merge_request, created_at: Time.now) def create_mr(build, commit, factory: :merge_request, created_at: Time.now)
FactoryGirl.create(factory, create(factory, source_project_id: commit.gl_project_id,
source_project_id: commit.gl_project_id,
target_project_id: commit.gl_project_id, target_project_id: commit.gl_project_id,
source_branch: build.ref, source_branch: build.ref,
created_at: created_at) created_at: created_at)
...@@ -501,8 +499,8 @@ describe Ci::Build, models: true do ...@@ -501,8 +499,8 @@ describe Ci::Build, models: true do
context 'when a Build is created after the MR' do context 'when a Build is created after the MR' do
before do before do
@merge_request = create_mr(build, commit, factory: :merge_request_with_diffs) @merge_request = create_mr(build, commit, factory: :merge_request_with_diffs)
commit2 = FactoryGirl.create :ci_commit, project: project commit2 = create(:ci_commit, project: project)
@build2 = FactoryGirl.create :ci_build, commit: commit2 @build2 = create(:ci_build, commit: commit2)
commits = [double(id: commit.sha), double(id: commit2.sha)] commits = [double(id: commit.sha), double(id: commit2.sha)]
allow(@merge_request).to receive(:commits).and_return(commits) allow(@merge_request).to receive(:commits).and_return(commits)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment