Merge pull request #1069 from ioquatix/patch-1

Add default implementation of `Middleware#close`.
This commit is contained in:
risk danger olson 2019-11-13 10:06:07 -07:00 committed by GitHub
commit 69f3078825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 1 deletions

View File

@ -13,7 +13,7 @@ Metrics/AbcSize:
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 233
Max: 234
# Offense count: 17
Metrics/CyclomaticComplexity:

View File

@ -117,6 +117,13 @@ module Faraday
def_delegators :builder, :build, :use, :request, :response, :adapter, :app
# Closes the underlying resources and/or connections. In the case of
# persistent connections, this closes all currently open connections
# but does not prevent new connections from being made.
def close
app.close
end
# @!method get(url = nil, params = nil, headers = nil)
# Makes a GET HTTP request without a body.
# @!scope class

View File

@ -9,5 +9,13 @@ module Faraday
def initialize(app = nil)
@app = app
end
def close
if @app.respond_to?(:close)
@app.close
else
warn "#{@app} does not implement \#close!"
end
end
end
end

View File

@ -127,6 +127,13 @@ RSpec.describe Faraday::Connection do
end
end
describe '#close' do
it 'can close underlying app' do
expect(conn.app).to receive(:close)
conn.close
end
end
describe 'basic_auth' do
subject { conn }

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
RSpec.describe Faraday::Middleware do
subject { described_class.new(app) }
describe '#close' do
context "with app that doesn't support \#close" do
let(:app) { double }
it 'should issue warning' do
expect(subject).to receive(:warn)
subject.close
end
end
context "with app that supports \#close" do
let(:app) { double }
it 'should issue warning' do
expect(app).to receive(:close)
expect(subject).to_not receive(:warn)
subject.close
end
end
end
end