diff options
author | Valery Sizov <valery@gitlab.com> | 2016-10-19 15:25:37 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2016-11-01 14:46:59 +0200 |
commit | a6ba358a8fe5a965a46ca07c8c0382348b2b8d8c (patch) | |
tree | a1ac8c2fe33e9a618a347e890ed9ab6a0cf4bbba /spec | |
parent | 957308af84ca8312ea362c7272a4008dac808086 (diff) | |
download | gitlab-ce-a6ba358a8fe5a965a46ca07c8c0382348b2b8d8c.tar.gz |
Make specs a bit fasterspec_optimization
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/admin/admin_runners_spec.rb | 27 | ||||
-rw-r--r-- | spec/features/commits_spec.rb | 8 | ||||
-rw-r--r-- | spec/features/projects/builds_spec.rb | 38 | ||||
-rw-r--r-- | spec/requests/api/merge_request_diffs_spec.rb | 32 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 16 | ||||
-rw-r--r-- | spec/requests/ci/api/builds_spec.rb | 25 | ||||
-rw-r--r-- | spec/requests/ci/api/runners_spec.rb | 10 |
7 files changed, 90 insertions, 66 deletions
diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 2f82fafc13a..d92c66b689d 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -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 diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index 5910803df51..338c53f08a6 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -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 diff --git a/spec/features/projects/builds_spec.rb b/spec/features/projects/builds_spec.rb index d1685f95503..23ea3857dd7 100644 --- a/spec/features/projects/builds_spec.rb +++ b/spec/features/projects/builds_spec.rb @@ -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 diff --git a/spec/requests/api/merge_request_diffs_spec.rb b/spec/requests/api/merge_request_diffs_spec.rb index 8f1e5ac9891..131c2d406ea 100644 --- a/spec/requests/api/merge_request_diffs_spec.rb +++ b/spec/requests/api/merge_request_diffs_spec.rb @@ -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 diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index b813ee967f8..bae4fa11ec2 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -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 diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb index 7b7d62feb2c..6d49c42c215 100644 --- a/spec/requests/ci/api/builds_spec.rb +++ b/spec/requests/ci/api/builds_spec.rb @@ -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 diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb index 43596f07cb5..d6c26fd8a94 100644 --- a/spec/requests/ci/api/runners_spec.rb +++ b/spec/requests/ci/api/runners_spec.rb @@ -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 |