Fix BitbucketServer::Client failing with Webmock 3.5.1

Webmock 3.1.0 changed the behavior to return `nil` for the body if an
HTTP 204 No Content response were received
(b837e64278).

Update the Bitbucket Server connection to ignore these No Content
response codes.
This commit is contained in:
Stan Hu 2019-02-16 15:30:02 -08:00
parent a6b7c4ee31
commit a0856cf7b9
2 changed files with 3 additions and 2 deletions

View file

@ -77,6 +77,7 @@ module BitbucketServer
private
def check_errors!(response)
return if ActionDispatch::Response::NO_CONTENT_CODES.include?(response.code)
raise ConnectionError, "Response is not valid JSON" unless response.parsed_response.is_a?(Hash)
return if response.code >= 200 && response.code < 300

View file

@ -64,7 +64,7 @@ describe BitbucketServer::Client do
let(:url) { "#{base_uri}rest/api/1.0/projects/SOME-PROJECT/repos/my-repo/branches" }
it 'requests Bitbucket to create a branch' do
stub_request(:post, url).to_return(status: 204, headers: headers, body: '{}')
stub_request(:post, url).to_return(status: 204, headers: headers, body: nil)
subject.create_branch(project, repo_slug, branch, sha)
@ -78,7 +78,7 @@ describe BitbucketServer::Client do
let(:url) { "#{base_uri}rest/branch-utils/1.0/projects/SOME-PROJECT/repos/my-repo/branches" }
it 'requests Bitbucket to create a branch' do
stub_request(:delete, url).to_return(status: 204, headers: headers, body: '{}')
stub_request(:delete, url).to_return(status: 204, headers: headers, body: nil)
subject.delete_branch(project, repo_slug, branch, sha)