diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-13 08:33:36 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-13 08:33:36 +0300 |
commit | 15220291ae1752b9e36ad0b2320180614ec37c59 (patch) | |
tree | 4365ad78af4a81b524781719379acd9284c61114 /spec/lib/bitbucket_server | |
parent | f85712fb9814170aac631c7c24ca287fe5a0eb04 (diff) |
Add spec for BitbucketServer::Connection
Diffstat (limited to 'spec/lib/bitbucket_server')
-rw-r--r-- | spec/lib/bitbucket_server/connection_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/lib/bitbucket_server/connection_spec.rb b/spec/lib/bitbucket_server/connection_spec.rb new file mode 100644 index 00000000000..911f6eea8bf --- /dev/null +++ b/spec/lib/bitbucket_server/connection_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +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" } } + + 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) + + 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) + + expect { subject.get(url) }.to raise_error(described_class::ConnectionError) + end + end + + describe '#post' do + end +end |