From ec4109d413f6161b43ad4cc1a6251af30d3bcf03 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 12 Jul 2018 23:17:05 -0700 Subject: Make Connection#post consistent with Connection#get and add specs --- spec/lib/bitbucket_server/connection_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'spec/lib/bitbucket_server') diff --git a/spec/lib/bitbucket_server/connection_spec.rb b/spec/lib/bitbucket_server/connection_spec.rb index 911f6eea8bf..45affbcf4e4 100644 --- a/spec/lib/bitbucket_server/connection_spec.rb +++ b/spec/lib/bitbucket_server/connection_spec.rb @@ -4,12 +4,11 @@ describe BitbucketServer::Connection do let(:options) { { base_uri: 'https://test:7990', user: 'bitbucket', password: 'mypassword' } } let(:payload) { { 'test' => 1 } } let(:headers) { { "Content-Type" => "application/json" } } + let(:url) { 'https://test:7990/rest/api/1.0/test?something=1' } subject { described_class.new(options) } describe '#get' do - let(:url) { 'https://test:7990/rest/api/1.0/test?something=1' } - it 'returns JSON body' do WebMock.stub_request(:get, url).to_return(body: payload.to_json, status: 200, headers: headers) @@ -24,5 +23,16 @@ describe BitbucketServer::Connection do end describe '#post' do + it 'returns JSON body' do + WebMock.stub_request(:post, url).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) + + expect { subject.post(url, payload) }.to raise_error(described_class::ConnectionError) + end end end -- cgit v1.2.1