Commit a30d34b2 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'spec_optimization' into 'master'

Make specs a bit faster

See merge request !6992
parents 90dfae93 a6ba358a
......@@ -7,15 +7,16 @@ describe "Admin Runners" do
describe "Runners page" do
before do
runner = FactoryGirl.create(:ci_runner)
runner = FactoryGirl.create(:ci_runner, contacted_at: Time.now)
pipeline = FactoryGirl.create(:ci_pipeline)
FactoryGirl.create(:ci_build, pipeline: pipeline, runner_id: runner.id)
visit admin_runners_path
end
it { page.has_text? "Manage Runners" }
it { page.has_text? "To register a new runner" }
it { page.has_text? "Runners with last contact less than a minute ago: 1" }
it 'has all necessary texts' do
expect(page).to have_text "To register a new Runner"
expect(page).to have_text "Runners with last contact less than a minute ago: 1"
end
describe 'search' do
before do
......@@ -27,8 +28,10 @@ describe "Admin Runners" do
search_form.click_button 'Search'
end
it { expect(page).to have_content("runner-foo") }
it { expect(page).not_to have_content("runner-bar") }
it 'shows correct runner' do
expect(page).to have_content("runner-foo")
expect(page).not_to have_content("runner-bar")
end
end
end
......@@ -46,8 +49,10 @@ describe "Admin Runners" do
end
describe 'projects' do
it { expect(page).to have_content(@project1.name_with_namespace) }
it { expect(page).to have_content(@project2.name_with_namespace) }
it 'contains project names' do
expect(page).to have_content(@project1.name_with_namespace)
expect(page).to have_content(@project2.name_with_namespace)
end
end
describe 'search' do
......@@ -57,8 +62,10 @@ describe "Admin Runners" do
search_form.click_button 'Search'
end
it { expect(page).to have_content(@project1.name_with_namespace) }
it { expect(page).not_to have_content(@project2.name_with_namespace) }
it 'contains name of correct project' do
expect(page).to have_content(@project1.name_with_namespace)
expect(page).not_to have_content(@project2.name_with_namespace)
end
end
describe 'enable/create' do
......
......@@ -64,9 +64,11 @@ describe 'Commits' do
visit ci_status_path(pipeline)
end
it { expect(page).to have_content pipeline.sha[0..7] }
it { expect(page).to have_content pipeline.git_commit_message }
it { expect(page).to have_content pipeline.git_author_name }
it 'shows pipeline`s data' do
expect(page).to have_content pipeline.sha[0..7]
expect(page).to have_content pipeline.git_commit_message
expect(page).to have_content pipeline.git_author_name
end
end
context 'Download artifacts' do
......
......@@ -79,12 +79,14 @@ describe "Builds" do
click_link "Cancel running"
end
it { expect(page).to have_selector('.nav-links li.active', text: 'All') }
it { expect(page).to have_content 'canceled' }
it { expect(page).to have_content @build.short_sha }
it { expect(page).to have_content @build.ref }
it { expect(page).to have_content @build.name }
it { expect(page).not_to have_link 'Cancel running' }
it 'shows all necessary content' do
expect(page).to have_selector('.nav-links li.active', text: 'All')
expect(page).to have_content 'canceled'
expect(page).to have_content @build.short_sha
expect(page).to have_content @build.ref
expect(page).to have_content @build.name
expect(page).not_to have_link 'Cancel running'
end
end
describe "GET /:project/builds/:id" do
......@@ -93,10 +95,12 @@ describe "Builds" do
visit namespace_project_build_path(@project.namespace, @project, @build)
end
it { expect(page.status_code).to eq(200) }
it { expect(page).to have_content @commit.sha[0..7] }
it { expect(page).to have_content @commit.git_commit_message }
it { expect(page).to have_content @commit.git_author_name }
it 'shows commit`s data' do
expect(page.status_code).to eq(200)
expect(page).to have_content @commit.sha[0..7]
expect(page).to have_content @commit.git_commit_message
expect(page).to have_content @commit.git_author_name
end
end
context "Build from other project" do
......@@ -167,7 +171,7 @@ describe "Builds" do
describe 'Variables' do
before do
@trigger_request = create :ci_trigger_request_with_variables
@trigger_request = create :ci_trigger_request_with_variables
@build = create :ci_build, pipeline: @commit, trigger_request: @trigger_request
visit namespace_project_build_path(@project.namespace, @project, @build)
end
......@@ -176,14 +180,14 @@ describe "Builds" do
expect(page).to have_css('.reveal-variables')
expect(page).not_to have_css('.js-build-variable')
expect(page).not_to have_css('.js-build-value')
click_button 'Reveal Variables'
expect(page).not_to have_css('.reveal-variables')
expect(page).to have_selector('.js-build-variable', text: 'TRIGGER_KEY_1')
expect(page).to have_selector('.js-build-value', text: 'TRIGGER_VALUE_1')
end
end
end
end
describe "POST /:project/builds/:id/cancel" do
......@@ -194,9 +198,11 @@ describe "Builds" do
click_link "Cancel"
end
it { expect(page.status_code).to eq(200) }
it { expect(page).to have_content 'canceled' }
it { expect(page).to have_content 'Retry' }
it 'loads the page and shows all needed controls' do
expect(page.status_code).to eq(200)
expect(page).to have_content 'canceled'
expect(page).to have_content 'Retry'
end
end
context "Build from other project" do
......
......@@ -14,14 +14,14 @@ describe API::API, 'MergeRequestDiffs', api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions' do
context 'valid merge request' do
before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user) }
let(:merge_request_diff) { merge_request.merge_request_diffs.first }
it { expect(response.status).to eq 200 }
it { expect(json_response.size).to eq(merge_request.merge_request_diffs.size) }
it { expect(json_response.first['id']).to eq(merge_request_diff.id) }
it { expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) }
it 'returns 200 for a valid merge request' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
merge_request_diff = merge_request.merge_request_diffs.first
expect(response.status).to eq 200
expect(json_response.size).to eq(merge_request.merge_request_diffs.size)
expect(json_response.first['id']).to eq(merge_request_diff.id)
expect(json_response.first['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
end
it 'returns a 404 when merge_request_id not found' do
......@@ -31,14 +31,14 @@ describe API::API, 'MergeRequestDiffs', api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions/:version_id' do
context 'valid merge request' do
before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user) }
let(:merge_request_diff) { merge_request.merge_request_diffs.first }
it { expect(response.status).to eq 200 }
it { expect(json_response['id']).to eq(merge_request_diff.id) }
it { expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha) }
it { expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size) }
it 'returns a 200 for a valid merge request' do
merge_request_diff = merge_request.merge_request_diffs.first
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
expect(response.status).to eq 200
expect(json_response['id']).to eq(merge_request_diff.id)
expect(json_response['head_commit_sha']).to eq(merge_request_diff.head_commit_sha)
expect(json_response['diffs'].size).to eq(merge_request_diff.diffs.size)
end
it 'returns a 404 when merge_request_id not found' do
......
......@@ -186,14 +186,14 @@ describe API::API, api: true do
end
describe 'GET /projects/:id/merge_requests/:merge_request_id/commits' do
context 'valid merge request' do
before { get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user) }
let(:commit) { merge_request.commits.first }
it { expect(response.status).to eq 200 }
it { expect(json_response.size).to eq(merge_request.commits.size) }
it { expect(json_response.first['id']).to eq(commit.id) }
it { expect(json_response.first['title']).to eq(commit.title) }
it 'returns a 200 when merge request is valid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/commits", user)
commit = merge_request.commits.first
expect(response.status).to eq 200
expect(json_response.size).to eq(merge_request.commits.size)
expect(json_response.first['id']).to eq(commit.id)
expect(json_response.first['title']).to eq(commit.title)
end
it 'returns a 404 when merge_request_id not found' do
......
......@@ -220,26 +220,33 @@ describe Ci::API::API do
end
context 'when request is valid' do
it { expect(response.status).to eq 202 }
it 'gets correct response' do
expect(response.status).to eq 202
expect(response.header).to have_key 'Range'
expect(response.header).to have_key 'Build-Status'
end
it { expect(build.reload.trace).to eq 'BUILD TRACE appended' }
it { expect(response.header).to have_key 'Range' }
it { expect(response.header).to have_key 'Build-Status' }
end
context 'when content-range start is too big' do
let(:headers_with_range) { headers.merge({ 'Content-Range' => '15-20' }) }
it { expect(response.status).to eq 416 }
it { expect(response.header).to have_key 'Range' }
it { expect(response.header['Range']).to eq '0-11' }
it 'gets correct response' do
expect(response.status).to eq 416
expect(response.header).to have_key 'Range'
expect(response.header['Range']).to eq '0-11'
end
end
context 'when content-range start is too small' do
let(:headers_with_range) { headers.merge({ 'Content-Range' => '8-20' }) }
it { expect(response.status).to eq 416 }
it { expect(response.header).to have_key 'Range' }
it { expect(response.header['Range']).to eq '0-11' }
it 'gets correct response' do
expect(response.status).to eq 416
expect(response.header).to have_key 'Range'
expect(response.header['Range']).to eq '0-11'
end
end
context 'when Content-Range header is missing' do
......
......@@ -109,10 +109,12 @@ describe Ci::API::API do
end
describe "DELETE /runners/delete" do
let!(:runner) { FactoryGirl.create(:ci_runner) }
before { delete ci_api("/runners/delete"), token: runner.token }
it 'returns 200' do
runner = FactoryGirl.create(:ci_runner)
delete ci_api("/runners/delete"), token: runner.token
it { expect(response).to have_http_status 200 }
it { expect(Ci::Runner.count).to eq(0) }
expect(response).to have_http_status 200
expect(Ci::Runner.count).to eq(0)
end
end
end
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