spec/kintone/command/guests_spec.rb in kintone-0.1.4 vs spec/kintone/command/guests_spec.rb in kintone-0.1.5

- old
+ new

@@ -11,12 +11,15 @@ stub_request( :post, 'https://example.cybozu.com/k/v1/guests.json' ) .with(body: { guests: guests }.to_json) - .to_return(body: '{}', status: 200, - headers: { 'Content-type' => 'application/json' }) + .to_return( + body: '{}', + status: 200, + headers: { 'Content-type' => 'application/json' } + ) end subject { target.register(guests) } let(:guests) do @@ -37,21 +40,41 @@ } ] end it { is_expected.to be_truthy } + + context 'fail to request' do + before(:each) do + stub_request( + :post, + 'https://example.cybozu.com/k/v1/guests.json' + ) + .with(body: { guests: guests }.to_json) + .to_return( + body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}', + status: 500, + headers: { 'Content-type' => 'application/json' } + ) + end + + it { expect { subject }.to raise_error Kintone::KintoneError } + end end describe '#delete' do before(:each) do stub_request( :delete, 'https://example.cybozu.com/k/v1/guests.json' ) .with(body: { guests: guests }.to_json) - .to_return(body: '{}', status: 200, - headers: { 'Content-type' => 'application/json' }) + .to_return( + body: '{}', + status: 200, + headers: { 'Content-type' => 'application/json' } + ) end subject { target.delete(guests) } let(:guests) do @@ -61,7 +84,24 @@ 'guest3@example.com' ] end it { is_expected.to be_truthy } + + context 'fail to request' do + before(:each) do + stub_request( + :delete, + 'https://example.cybozu.com/k/v1/guests.json' + ) + .with(body: { guests: guests }.to_json) + .to_return( + body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}', + status: 500, + headers: { 'Content-Type' => 'application/json' } + ) + end + + it { expect { subject }.to raise_error Kintone::KintoneError } + end end end