spec/routemaster/api_client_spec.rb in routemaster-drain-2.4.3 vs spec/routemaster/api_client_spec.rb in routemaster-drain-2.4.4
- old
+ new
@@ -53,13 +53,23 @@
subject.status
assert_requested(:get, /example/) do |req|
expect(req.headers).to include('X-Custom-Header')
end
end
+ end
+ shared_examples 'a wrappable response' do
context 'when response_class is present' do
before do
+ @req = stub_request(:get, /example\.com/).to_return(
+ status: 200,
+ body: { id: 132, type: 'widget' }.to_json,
+ headers: {
+ 'content-type' => 'application/json;v=1'
+ }
+ )
+
class DummyResponse
def initialize(res, client: nil); end
def dummy; true; end
end
end
@@ -73,15 +83,17 @@
end
describe '#get' do
subject { fetcher.get(url, headers: headers) }
it_behaves_like 'a GET requester'
+ it_behaves_like 'a wrappable response'
end
describe '#fget' do
subject { fetcher.fget(url, headers: headers) }
it_behaves_like 'a GET requester'
+ it_behaves_like 'a wrappable response'
context "when setting callbacks" do
before do
stub_request(:get, /example\.com/).to_return(
status: status,
@@ -145,10 +157,12 @@
it 'POSTs from the URL' do
subject
expect(@post_req).to have_been_requested
end
+
+ it_behaves_like 'a wrappable response'
end
describe '#patch' do
subject { fetcher.patch(url, body: {}, headers: headers) }
@@ -164,9 +178,11 @@
it 'PATCH from the URL' do
subject
expect(@patch_req).to have_been_requested
end
+
+ it_behaves_like 'a wrappable response'
end
describe '#delete' do
subject { fetcher.delete(url, headers: headers) }