diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-27 22:58:03 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-27 22:58:17 +0300 |
commit | 450030e9029f5de6fcfb850e5940838c2a76c81e (patch) | |
tree | 0d34dc41be83958b8a60b24701e4b709ff5bed2b /spec/lib | |
parent | d27ae9f55dcf9b339c3f6d6df89853798c11f5f7 (diff) |
Add Accept header for JSON
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/bitbucket_server/connection_spec.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/spec/lib/bitbucket_server/connection_spec.rb b/spec/lib/bitbucket_server/connection_spec.rb index 4a421d062a3..33a037218a0 100644 --- a/spec/lib/bitbucket_server/connection_spec.rb +++ b/spec/lib/bitbucket_server/connection_spec.rb @@ -10,46 +10,50 @@ describe BitbucketServer::Connection do describe '#get' do it 'returns JSON body' do - WebMock.stub_request(:get, url).to_return(body: payload.to_json, status: 200, headers: headers) + WebMock.stub_request(:get, url).with(headers: { 'Accept' => 'application/json' }).to_return(body: payload.to_json, status: 200, headers: headers) expect(subject.get(url, { something: 1 })).to eq(payload) end it 'throws an exception if the response is not 200' do - WebMock.stub_request(:get, url).to_return(body: payload.to_json, status: 500, headers: headers) + WebMock.stub_request(:get, url).with(headers: { 'Accept' => 'application/json' }).to_return(body: payload.to_json, status: 500, headers: headers) expect { subject.get(url) }.to raise_error(described_class::ConnectionError) end end describe '#post' do + let(:headers) { { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } } + it 'returns JSON body' do - WebMock.stub_request(:post, url).to_return(body: payload.to_json, status: 200, headers: headers) + WebMock.stub_request(:post, url).with(headers: headers).to_return(body: payload.to_json, status: 200, headers: headers) expect(subject.post(url, payload)).to eq(payload) end it 'throws an exception if the response is not 200' do - WebMock.stub_request(:post, url).to_return(body: payload.to_json, status: 500, headers: headers) + WebMock.stub_request(:post, url).with(headers: headers).to_return(body: payload.to_json, status: 500, headers: headers) expect { subject.post(url, payload) }.to raise_error(described_class::ConnectionError) end end describe '#delete' do + let(:headers) { { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } } + context 'branch API' do let(:branch_path) { '/projects/foo/repos/bar/branches' } let(:branch_url) { 'https://test:7990/rest/branch-utils/1.0/projects/foo/repos/bar/branches' } let(:path) { } it 'returns JSON body' do - WebMock.stub_request(:delete, branch_url).to_return(body: payload.to_json, status: 200, headers: headers) + WebMock.stub_request(:delete, branch_url).with(headers: headers).to_return(body: payload.to_json, status: 200, headers: headers) expect(subject.delete(:branches, branch_path, payload)).to eq(payload) end it 'throws an exception if the response is not 200' do - WebMock.stub_request(:delete, branch_url).to_return(body: payload.to_json, status: 500, headers: headers) + WebMock.stub_request(:delete, branch_url).with(headers: headers).to_return(body: payload.to_json, status: 500, headers: headers) expect { subject.delete(:branches, branch_path, payload) }.to raise_error(described_class::ConnectionError) end |