mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Merge pull request #1069 from ioquatix/patch-1
Add default implementation of `Middleware#close`.
This commit is contained in:
commit
69f3078825
@ -13,7 +13,7 @@ Metrics/AbcSize:
|
||||
# Offense count: 4
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ClassLength:
|
||||
Max: 233
|
||||
Max: 234
|
||||
|
||||
# Offense count: 17
|
||||
Metrics/CyclomaticComplexity:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
|
||||
|
26
spec/faraday/middleware_spec.rb
Normal file
26
spec/faraday/middleware_spec.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user