Commit a6ba358a authored by Valery Sizov's avatar Valery Sizov

Make specs a bit faster

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