diff --git a/lib/oauth2/client.rb b/lib/oauth2/client.rb index f98a9f37..3a11aa27 100644 --- a/lib/oauth2/client.rb +++ b/lib/oauth2/client.rb @@ -59,15 +59,12 @@ def site=(value) # The Faraday connection object def connection - @connection ||= begin - conn = Faraday.new(site, options[:connection_opts]) - if options[:connection_build] - conn.build do |b| - options[:connection_build].call(b) + @connection ||= + Faraday.new(site, options[:connection_opts]) do |builder| + if options[:connection_build] + options[:connection_build].call(builder) end end - conn - end end # The authorize endpoint URL of the OAuth2 provider diff --git a/spec/oauth2/client_spec.rb b/spec/oauth2/client_spec.rb index 7ff3ce2d..85712f58 100644 --- a/spec/oauth2/client_spec.rb +++ b/spec/oauth2/client_spec.rb @@ -46,7 +46,7 @@ it 'is able to pass a block to configure the connection' do connection = double('connection') builder = double('builder') - allow(connection).to receive(:build).and_yield(builder) + allow(Faraday).to receive(:new).and_yield(builder) allow(Faraday::Connection).to receive(:new).and_return(connection) expect(builder).to receive(:adapter).with(:test)