Commit af786052 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix all specs

parent ee890c26
Pipeline #4664330 failed with stages
in 35 minutes and 13 seconds
......@@ -15,10 +15,12 @@ module SharedBuilds
end
step 'recent build is successful' do
allow(PipelineHooksWorker).to receive(:perform_async).and_return(true)
@build.success
end
step 'recent build failed' do
allow(PipelineHooksWorker).to receive(:perform_async).and_return(true)
@build.drop
end
......
......@@ -42,6 +42,10 @@ describe 'Commits' do
let!(:build) { FactoryGirl.create :ci_build, pipeline: pipeline }
let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
before do
stub_ci_pipeline_hooks
end
context 'when logged as developer' do
before do
project.team << [@user, :developer]
......
......@@ -84,7 +84,10 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
end
context 'when build succeeds' do
background { build.success }
background do
stub_repository_forbidden_access
build.success
end
it 'merges merge request' do
visit_merge_request(merge_request) # refresh the page
......
......@@ -4,6 +4,10 @@ feature 'test coverage badge' do
given!(:user) { create(:user) }
given!(:project) { create(:project, :private) }
before do
stub_ci_pipeline_hooks
end
context 'when user has access to view badge' do
background do
project.team << [user, :developer]
......
......@@ -5,6 +5,7 @@ describe "Builds" do
let(:artifacts_file) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
before do
stub_ci_pipeline_hooks
login_as(:user)
@commit = FactoryGirl.create :ci_pipeline
@build = FactoryGirl.create :ci_build, :trace, pipeline: @commit
......
......@@ -9,6 +9,7 @@ describe "Pipelines" do
before do
login_as(user)
project.team << [user, :developer]
stub_ci_pipeline_hooks
end
describe 'GET /:project/pipelines' do
......
......@@ -6,6 +6,10 @@ describe Gitlab::Badge::Build::Status do
let(:branch) { 'master' }
let(:badge) { described_class.new(project, branch) }
before do
stub_ci_pipeline_hooks
end
describe '#entity' do
it 'always says build' do
expect(badge.entity).to eq 'build'
......
......@@ -8,6 +8,10 @@ describe Gitlab::Badge::Coverage::Report do
described_class.new(project, 'master', job_name)
end
before do
stub_ci_pipeline_hooks
end
describe '#entity' do
it 'describes a coverage' do
expect(badge.entity).to eq 'coverage'
......
......@@ -7,6 +7,10 @@ describe Notify do
include_context 'gitlab email notification'
before do
stub_ci_pipeline_hooks
end
describe 'build notification email' do
let(:build) { create(:ci_build) }
let(:project) { build.project }
......
......@@ -16,6 +16,10 @@ describe Ci::Build, models: true do
it { is_expected.to respond_to :trace_html }
before do
stub_ci_pipeline_hooks
end
describe '#first_pending' do
let!(:first) { create(:ci_build, pipeline: pipeline, status: 'pending', created_at: Date.yesterday) }
let!(:second) { create(:ci_build, pipeline: pipeline, status: 'pending') }
......
......@@ -20,6 +20,10 @@ describe Ci::Pipeline, models: true do
it { is_expected.to delegate_method(:stages).to(:statuses) }
before do
stub_ci_pipeline_hooks
end
describe '#valid_commit_sha' do
context 'commit.sha can not start with 00000000' do
before do
......@@ -425,6 +429,10 @@ describe Ci::Pipeline, models: true do
before do
WebMock.stub_request(:post, hook.url)
stub_repository_forbidden_access
allow(PipelineHooksWorker).to receive(:perform_async).and_call_original
end
context 'with multiple builds' do
......
......@@ -41,6 +41,8 @@ describe HipchatService, models: true do
token: token
)
WebMock.stub_request(:post, api_url)
stub_repository_forbidden_access
end
it 'tests and return errors' do
......
......@@ -12,6 +12,10 @@ describe API::API, api: true do
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) }
let!(:build) { create(:ci_build, pipeline: pipeline) }
before do
stub_ci_pipeline_hooks
end
describe 'GET /projects/:id/builds ' do
let(:query) { '' }
......
......@@ -11,6 +11,10 @@ describe API::CommitStatuses, api: true do
let(:developer) { create_user(:developer) }
let(:sha) { commit.id }
before do
stub_ci_pipeline_hooks
end
describe "GET /projects/:id/repository/commits/:sha/statuses" do
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
......
......@@ -108,6 +108,10 @@ describe API::API, api: true do
let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
before do
stub_ci_pipeline_hooks
end
context 'authorized user' do
it 'retries failed builds' do
post api("/projects/#{project.id}/pipelines/#{pipeline.id}/cancel", user)
......
......@@ -14,6 +14,10 @@ describe API::API do
let!(:trigger2) { create(:ci_trigger, project: project, token: trigger_token_2) }
let!(:trigger_request) { create(:ci_trigger_request, trigger: trigger, created_at: '2015-01-01 12:13:14') }
before do
stub_ci_pipeline_hooks
end
describe 'POST /projects/:project_id/trigger' do
let!(:project2) { create(:empty_project) }
let(:options) do
......
......@@ -6,6 +6,10 @@ describe Ci::API::API do
let(:runner) { FactoryGirl.create(:ci_runner, tag_list: ["mysql", "ruby"]) }
let(:project) { FactoryGirl.create(:empty_project) }
before do
stub_ci_pipeline_hooks
end
describe "Builds API for runners" do
let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') }
......
......@@ -38,6 +38,10 @@ describe Ci::API::API do
context 'Have a commit' do
let(:pipeline) { project.pipelines.last }
before do
stub_ci_pipeline_hooks
end
it 'creates builds' do
post ci_api("/projects/#{project.ci_id}/refs/master/trigger"), options
expect(response).to have_http_status(201)
......
......@@ -6,6 +6,7 @@ describe Ci::CreatePipelineService, services: true do
before do
stub_ci_pipeline_to_return_yaml_file
stub_ci_pipeline_hooks
end
describe '#execute' do
......
......@@ -7,6 +7,7 @@ describe Ci::CreateTriggerRequestService, services: true do
before do
stub_ci_pipeline_to_return_yaml_file
stub_ci_pipeline_hooks
end
describe '#execute' do
......
......@@ -8,6 +8,10 @@ module Ci
let(:pipeline) { project.ensure_pipeline('master', commit_sha) }
let(:build) { FactoryGirl.create(:ci_build, pipeline: pipeline) }
before do
stub_ci_pipeline_hooks
end
describe '#execute' do
before { build }
......
......@@ -7,6 +7,7 @@ describe Ci::ProcessPipelineService, services: true do
before do
allow(pipeline).to receive(:ci_yaml_file).and_return(config)
stub_ci_pipeline_hooks
end
describe '#execute' do
......
......@@ -11,6 +11,7 @@ module Ci
before do
specific_runner.assign_to(project)
stub_ci_pipeline_hooks
end
describe '#execute' do
......
......@@ -6,6 +6,10 @@ describe CreateDeploymentService, services: true do
let(:service) { described_class.new(project, user, params) }
before do
stub_ci_pipeline_hooks
end
describe '#execute' do
let(:params) do
{ environment: 'production',
......
......@@ -141,17 +141,19 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
allow_any_instance_of(MergeRequest).to receive(:pipeline).and_wrap_original do
Ci::Pipeline.find(pipeline.id)
end
stub_ci_pipeline_hooks
end
it "doesn't merge if any of stages failed" do
expect(MergeWorker).not_to receive(:perform_async)
expect(PipelineSuccessWorker).not_to receive(:perform_async)
build.success
test.drop
end
it 'merges when all stages succeeded' do
expect(MergeWorker).to receive(:perform_async)
expect(PipelineSuccessWorker).to receive(:perform_async).and_return(true)
build.success
test.success
......
......@@ -13,6 +13,18 @@ module StubGitlabCalls
allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
end
def stub_ci_pipeline_hooks
allow(PipelineHooksWorker).to receive(:perform_async).and_return(true)
end
def stub_ci_build_hooks
allow(BuildHooksWorker).to receive(:perform_async).and_return(true)
end
def stub_repository_forbidden_access
allow(Repository).to receive(:is_access_forbidden?).and_return(false)
end
def stub_ci_pipeline_to_return_yaml_file
stub_ci_pipeline_yaml_file(gitlab_ci_yaml)
end
......
......@@ -15,6 +15,8 @@ describe 'projects/builds/show' do
assign(:project, project)
allow(view).to receive(:can?).and_return(true)
stub_ci_pipeline_hooks
end
context 'when build is running' do
......
......@@ -10,6 +10,7 @@ describe BuildEmailWorker do
subject { BuildEmailWorker.new }
before do
stub_ci_pipeline_hooks
allow(build).to receive(:execute_hooks).and_return(false)
build.success
end
......
......@@ -59,6 +59,7 @@ describe PostReceive do
end
allow_any_instance_of(Ci::CreatePipelineService).to receive(:branch?).and_return(true)
stub_ci_pipeline_to_return_yaml_file
stub_ci_pipeline_hooks
end
it { expect{ subject }.to change{ Ci::Pipeline.count }.by(2) }
......
......@@ -4,6 +4,10 @@ describe StuckCiBuildsWorker do
let!(:build) { create :ci_build }
let(:worker) { described_class.new }
before do
stub_ci_pipeline_hooks
end
subject do
build.reload
build.status
......
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