A minimal Ruby client of Bluesky/ATProto API
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

added tests for non-json response

+15 -3
+15 -3
spec/shared/ex_post_request.rb
··· 2 2 3 3 shared_examples "post_request" do 4 4 describe '#post_request' do 5 - let(:response) {{ body: { "result": "ok" }}} 5 + let(:response) {{ body: '{ "result": "ok" }', headers: { 'Content-Type': 'application/json' }}} 6 6 7 7 before do 8 - stub_request(:post, "https://#{host}/xrpc/com.example.service.doStuff").to_return_json(response) 8 + stub_request(:post, "https://#{host}/xrpc/com.example.service.doStuff").to_return(response) 9 9 end 10 10 11 11 it 'should make a request to the given XRPC endpoint' do ··· 56 56 end 57 57 58 58 context 'if the response has a 4xx status' do 59 - let(:response) {{ body: '{ "error": "message" }', status: 403 }} 59 + let(:response) {{ body: '{ "error": "message" }', status: 403, headers: { 'Content-Type': 'application/json' }}} 60 60 61 61 it 'should raise an error' do 62 62 expect { subject.post_request('com.example.service.doStuff') }.to raise_error(Minisky::ClientErrorResponse) 63 + end 64 + end 65 + 66 + context 'if the response has a 2xx status, but the response is not json' do 67 + let(:response) {{ body: 'ok', status: 201, headers: { 'Content-Type': 'text/plain' }}} 68 + 69 + it 'should not raise an error' do 70 + expect { subject.post_request('com.example.service.doStuff') }.to_not raise_error 71 + end 72 + 73 + it 'should return the body as a string' do 74 + subject.post_request('com.example.service.doStuff').should == 'ok' 63 75 end 64 76 end 65 77