···2233shared_examples "post_request" do
44 describe '#post_request' do
55- let(:response) {{ body: { "result": "ok" }}}
55+ let(:response) {{ body: '{ "result": "ok" }', headers: { 'Content-Type': 'application/json' }}}
6677 before do
88- stub_request(:post, "https://#{host}/xrpc/com.example.service.doStuff").to_return_json(response)
88+ stub_request(:post, "https://#{host}/xrpc/com.example.service.doStuff").to_return(response)
99 end
10101111 it 'should make a request to the given XRPC endpoint' do
···5656 end
57575858 context 'if the response has a 4xx status' do
5959- let(:response) {{ body: '{ "error": "message" }', status: 403 }}
5959+ let(:response) {{ body: '{ "error": "message" }', status: 403, headers: { 'Content-Type': 'application/json' }}}
60606161 it 'should raise an error' do
6262 expect { subject.post_request('com.example.service.doStuff') }.to raise_error(Minisky::ClientErrorResponse)
6363+ end
6464+ end
6565+6666+ context 'if the response has a 2xx status, but the response is not json' do
6767+ let(:response) {{ body: 'ok', status: 201, headers: { 'Content-Type': 'text/plain' }}}
6868+6969+ it 'should not raise an error' do
7070+ expect { subject.post_request('com.example.service.doStuff') }.to_not raise_error
7171+ end
7272+7373+ it 'should return the body as a string' do
7474+ subject.post_request('com.example.service.doStuff').should == 'ok'
6375 end
6476 end
6577