diff options
author | Rémy Coutable <remy@rymai.me> | 2016-04-11 17:38:10 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-04-11 17:39:17 +0200 |
commit | 9f3e6d072b7fc1fa82fb1859f0dd5adc1caa7e9b (patch) | |
tree | 72258b64f9bb5d6a9dd43a805a38b2f3f2fba5d9 | |
parent | c20799e4cde5b7e3509a9b29e2bc6ef186b4a6fa (diff) | |
download | gitlab-ce-ctmay4/gitlab-ce-master.tar.gz |
Use WebMock instead of RSpec stubbingctmay4/gitlab-ce-master
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | app/models/project_services/bamboo_service.rb | 6 | ||||
-rw-r--r-- | app/models/project_services/teamcity_service.rb | 6 | ||||
-rw-r--r-- | spec/models/project_services/bamboo_service_spec.rb | 198 | ||||
-rw-r--r-- | spec/models/project_services/teamcity_service_spec.rb | 151 |
5 files changed, 173 insertions, 190 deletions
diff --git a/CHANGELOG b/CHANGELOG index 68a27dd2582..50b0b4a81cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -124,8 +124,6 @@ v 8.6.0 - Add information about `image` and `services` field at `job` level in the `.gitlab-ci.yml` documentation (Pat Turner) - HTTP error pages work independently from location and config (Artem Sidorenko) - Update `omniauth-saml` to 1.5.0 to allow for custom response attributes to be set - - Fix avatar stretching by providing a cropping feature (Johann Pardanaud) - - Don't load all of GitLab in mail_room - Memoize @group in Admin::GroupsController (Yatish Mehta) - Indicate how much an MR diverged from the target branch (Pierre de La Morinerie) - Added omniauth-auth0 Gem (Daniel Carraro) diff --git a/app/models/project_services/bamboo_service.rb b/app/models/project_services/bamboo_service.rb index ca1119c3617..060062aaf7a 100644 --- a/app/models/project_services/bamboo_service.rb +++ b/app/models/project_services/bamboo_service.rb @@ -120,11 +120,11 @@ class BambooService < CiService end if status.include?('Success') - :success + 'success' elsif status.include?('Failed') - :failed + 'failed' elsif status.include?('Pending') - :pending + 'pending' else :error end diff --git a/app/models/project_services/teamcity_service.rb b/app/models/project_services/teamcity_service.rb index 1f2ae06c789..8dceee5e2c5 100644 --- a/app/models/project_services/teamcity_service.rb +++ b/app/models/project_services/teamcity_service.rb @@ -124,11 +124,11 @@ class TeamcityService < CiService end if status.include?('SUCCESS') - :success + 'success' elsif status.include?('FAILURE') - :failed + 'failed' elsif status.include?('Pending') - :pending + 'pending' else :error end diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb index 54b0f9d23c5..d20db94ce8c 100644 --- a/spec/models/project_services/bamboo_service_spec.rb +++ b/spec/models/project_services/bamboo_service_spec.rb @@ -91,158 +91,150 @@ describe BambooService, models: true do end end - module BambooServiceSpec - Response = Struct.new(:code, :data) do - def [](key) - data[key] - end - end - end - - describe '#build_info' do - let(:bamboo_url) { 'http://gitlab.com' } - let(:response) { BambooServiceSpec::Response.new(200, {}) } - subject do - BambooService.create( - project: create(:project), - properties: { - bamboo_url: bamboo_url, - username: 'mic', - password: 'password' - }) - end - before { allow(HTTParty).to receive(:get).and_return(response) } + describe '#build_page' do + let(:bamboo_full_url) { 'http://mic:password@gitlab.com/rest/api/latest/result?label=123&os_authType=basic' } - context 'when username and password are blank' do + context 'when response code is not 200' do + before do + WebMock.stub_request(:get, bamboo_full_url).to_return(status: 500) + end subject do BambooService.create( - project: create(:project), + project: build_stubbed(:empty_project), properties: { - bamboo_url: bamboo_url - }) + bamboo_url: 'http://gitlab.com', + username: 'mic', + password: 'password', + build_key: 'foo' + } + ) end - it { expect(subject.build_info('123')).to eq(response) } - end - - context 'when bamboo_url has no trailing slash' do - it { expect(subject.build_info('123')).to eq(response) } - end - - context 'when bamboo_url has a trailing slash' do - let(:bamboo_url) { 'http://gitlab.com/' } - - it { expect(subject.build_info('123')).to eq(response) } + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/foo') } end - end - describe '#build_page' do - let(:bamboo_url) { 'http://gitlab.com' } - let(:response_code) { 200 } - let(:response) do - BambooServiceSpec::Response.new(response_code, { - 'results' => { - 'results' => { 'result' => { 'planResultKey' => { 'key' => '42' } } } - } - }) - end - subject do - BambooService.create( - project: create(:project), - properties: { - bamboo_url: bamboo_url, - username: 'mic', - password: 'password', - build_key: 'foo' - }) - end - before { allow(HTTParty).to receive(:get).and_return(response) } + context 'when response has no result' do + before do + WebMock.stub_request(:get, bamboo_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"results":{"results":{"size":"0"}}}) + ) + end + subject do + BambooService.create( + project: build_stubbed(:empty_project), + properties: { + bamboo_url: 'http://gitlab.com', + username: 'mic', + password: 'password', + build_key: 'foo' + } + ) + end - context 'when bamboo_url has no trailing slash' do - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/42') } + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/foo') } end - context 'when bamboo_url has a trailing slash' do - let(:bamboo_url) { 'http://gitlab.com/' } + context 'when response has result' do + before do + WebMock.stub_request(:get, bamboo_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"results":{"results":{"result":{"planResultKey":{"key":"42"}}}}}) + ) + end + subject do + BambooService.create( + project: build_stubbed(:empty_project), + properties: { + bamboo_url: bamboo_url, + username: 'mic', + password: 'password', + build_key: 'foo' + } + ) + end - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/42') } - end + context 'when bamboo_url has no trailing slash' do + let(:bamboo_url) { 'http://gitlab.com' } - context 'when response code is not 200' do - let(:response_code) { 500 } + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/42') } + end - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/foo') } - end + context 'when bamboo_url has a trailing slash' do + let(:bamboo_url) { 'http://gitlab.com/' } - context 'when response returns no result' do - let(:response) do - BambooServiceSpec::Response.new(response_code, { - 'results' => { 'results' => { 'size' => '0' } } - }) + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/42') } end - - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/browse/foo') } end end describe '#commit_status' do - let(:bamboo_url) { 'http://gitlab.com' } - let(:response_code) { 200 } - let(:build_state) { 'YAY Success!' } - let(:response) do - BambooServiceSpec::Response.new(response_code, { - 'results' => { 'results' => { 'result' => { 'buildState' => build_state } } } - }) - end + let(:bamboo_full_url) { 'http://mic:password@gitlab.com/rest/api/latest/result?label=123&os_authType=basic' } subject do BambooService.create( - project: create(:project), + project: build_stubbed(:empty_project), properties: { - bamboo_url: bamboo_url, + bamboo_url: 'http://gitlab.com', username: 'mic', - password: 'password', - build_type: 'foo' - }) + password: 'password' + } + ) end - before { allow(HTTParty).to receive(:get).and_return(response) } context 'when response code is not 200' do - let(:response_code) { 500 } + before do + WebMock.stub_request(:get, bamboo_full_url).to_return(status: 500) + end it { expect(subject.commit_status('123', 'unused')).to eq(:error) } end - context 'when response has no results' do - let(:response) do - BambooServiceSpec::Response.new(response_code, { - 'results' => { 'results' => { 'size' => '0' } } - }) + context 'when response code is 404' do + before do + WebMock.stub_request(:get, bamboo_full_url).to_return(status: 404) end - it { expect(subject.commit_status('123', 'unused')).to eq(:pending) } + it { expect(subject.commit_status('123', 'unused')).to eq('pending') } end - context 'when response code is 404' do - let(:response_code) { 404 } + context 'when response has no results' do + before do + WebMock.stub_request(:get, bamboo_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"results":{"results":{"size":"0"}}}) + ) + end - it { expect(subject.commit_status('123', 'unused')).to eq(:pending) } + it { expect(subject.commit_status('123', 'unused')).to eq('pending') } end - context 'when response code is 200' do + context 'when response has results' do + let(:build_state) { 'YAY Success!' } + before do + WebMock.stub_request(:get, bamboo_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"results":{"results":{"result":{"buildState":"#{build_state}"}}}}) + ) + end + context 'when build status contains Success' do - it { expect(subject.commit_status('123', 'unused')).to eq(:success) } + it { expect(subject.commit_status('123', 'unused')).to eq('success') } end context 'when build status contains Failed' do let(:build_state) { 'NO Failed!' } - it { expect(subject.commit_status('123', 'unused')).to eq(:failed) } + it { expect(subject.commit_status('123', 'unused')).to eq('failed') } end context 'when build status contains Failed' do let(:build_state) { 'NO Pending!' } - it { expect(subject.commit_status('123', 'unused')).to eq(:pending) } + it { expect(subject.commit_status('123', 'unused')).to eq('pending') } end context 'when build status contains anything else' do diff --git a/spec/models/project_services/teamcity_service_spec.rb b/spec/models/project_services/teamcity_service_spec.rb index 7bfb6160f57..fa741fb7ff6 100644 --- a/spec/models/project_services/teamcity_service_spec.rb +++ b/spec/models/project_services/teamcity_service_spec.rb @@ -91,126 +91,119 @@ describe TeamcityService, models: true do end end - module TeamcityServiceSpec - Response = Struct.new(:code, :data) do - def [](key) - data[key] - end - end - end - - describe '#build_info' do - let(:teamcity_url) { 'http://gitlab.com' } - let(:response) { TeamcityServiceSpec::Response.new(200, {}) } - subject do - TeamcityService.create( - project: create(:project), - properties: { - teamcity_url: teamcity_url, - username: 'mic', - password: 'password', - build_type: 'foo' - }) - end - before { allow(HTTParty).to receive(:get).and_return(response) } - - context 'when teamcity_url has no trailing slash' do - it { expect(subject.build_info('123')).to eq(response) } - end + describe '#build_page' do + let(:teamcity_full_url) { 'http://mic:password@gitlab.com/httpAuth/app/rest/builds/branch:unspecified:any,number:123' } - context 'when teamcity_url has a trailing slash' do - let(:teamcity_url) { 'http://gitlab.com/' } + context 'when response code is not 200' do + before do + WebMock.stub_request(:get, teamcity_full_url).to_return(status: 500) + end + subject do + TeamcityService.create( + project: build_stubbed(:empty_project), + properties: { + teamcity_url: 'http://gitlab.com/', + username: 'mic', + password: 'password', + build_type: 'foo' + } + ) + end - it { expect(subject.build_info('123')).to eq(response) } - end - end + it 'returns a specific URL' do - describe '#build_page' do - let(:teamcity_url) { 'http://gitlab.com' } - let(:response_code) { 200 } - let(:response) do - TeamcityServiceSpec::Response.new(response_code, { 'build' => { 'id' => '666' } }) - end - subject do - TeamcityService.create( - project: create(:project), - properties: { - teamcity_url: teamcity_url, - username: 'mic', - password: 'password', - build_type: 'foo' - }) + expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildTypeId=foo') + end end - before { allow(HTTParty).to receive(:get).and_return(response) } - context 'when teamcity_url has no trailing slash' do - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') } - end + context 'when response has result' do + before do + WebMock.stub_request(:get, teamcity_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"build":{"id":"666"}}) + ) + end + subject do + TeamcityService.create( + project: build_stubbed(:empty_project), + properties: { + teamcity_url: teamcity_url, + username: 'mic', + password: 'password', + build_type: 'foo' + } + ) + end - context 'when teamcity_url has a trailing slash' do - let(:teamcity_url) { 'http://gitlab.com/' } + context 'when teamcity_url has no trailing slash' do + let(:teamcity_url) { 'http://gitlab.com' } - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') } - end + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') } + end - context 'when response code is not 200' do - let(:response_code) { 500 } + context 'when teamcity_url has a trailing slash' do + let(:teamcity_url) { 'http://gitlab.com/' } - it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildTypeId=foo') } + it { expect(subject.build_page('123', 'unused')).to eq('http://gitlab.com/viewLog.html?buildId=666&buildTypeId=foo') } + end end end describe '#commit_status' do - let(:teamcity_url) { 'http://gitlab.com' } - let(:response_code) { 200 } - let(:build_status) { 'YAY SUCCESS!' } - let(:response) do - TeamcityServiceSpec::Response.new(response_code, { - 'build' => { - 'status' => build_status, - 'id' => '666' - } - }) - end + let(:teamcity_full_url) { 'http://mic:password@gitlab.com/httpAuth/app/rest/builds/branch:unspecified:any,number:123' } subject do TeamcityService.create( - project: create(:project), + project: build_stubbed(:empty_project), properties: { - teamcity_url: teamcity_url, + teamcity_url: 'http://gitlab.com', username: 'mic', password: 'password', build_type: 'foo' - }) + } + ) end - before { allow(HTTParty).to receive(:get).and_return(response) } context 'when response code is not 200' do - let(:response_code) { 500 } + before do + WebMock.stub_request(:get, teamcity_full_url).to_return(status: 500) + end it { expect(subject.commit_status('123', 'unused')).to eq(:error) } end context 'when response code is 404' do - let(:response_code) { 404 } + before do + WebMock.stub_request(:get, teamcity_full_url).to_return(status: 404) + end - it { expect(subject.commit_status('123', 'unused')).to eq(:pending) } + it { expect(subject.commit_status('123', 'unused')).to eq('pending') } end - context 'when response code is 200' do + context 'when response has results' do + let(:build_status) { 'YAY SUCCESS!' } + before do + WebMock.stub_request(:get, teamcity_full_url).to_return( + status: 200, + headers: { 'Content-Type': 'application/json' }, + body: %Q({"build":{"status":"#{build_status}","id":"666"}}) + ) + end + context 'when build status contains SUCCESS' do - it { expect(subject.commit_status('123', 'unused')).to eq(:success) } + it { expect(subject.commit_status('123', 'unused')).to eq('success') } end context 'when build status contains FAILURE' do let(:build_status) { 'NO FAILURE!' } - it { expect(subject.commit_status('123', 'unused')).to eq(:failed) } + it { expect(subject.commit_status('123', 'unused')).to eq('failed') } end context 'when build status contains Pending' do let(:build_status) { 'NO Pending!' } - it { expect(subject.commit_status('123', 'unused')).to eq(:pending) } + it { expect(subject.commit_status('123', 'unused')).to eq('pending') } end context 'when build status contains anything else' do |