diff --git a/lib/webmock/http_lib_adapters/net_http.rb b/lib/webmock/http_lib_adapters/net_http.rb index 7e779502..20fdee92 100644 --- a/lib/webmock/http_lib_adapters/net_http.rb +++ b/lib/webmock/http_lib_adapters/net_http.rb @@ -98,12 +98,8 @@ def request(request, body = nil, &block) after_request.call(response) } if started? - if WebMock::Config.instance.net_http_connect_on_start - super_with_after_request.call - else - start_with_connect_without_finish - super_with_after_request.call - end + ensure_actual_connection + super_with_after_request.call else start_with_connect { super_with_after_request.call @@ -131,12 +127,8 @@ def start_without_connect end - def start_with_connect_without_finish - if @socket - @socket.close - @socket = nil - end - do_start + def ensure_actual_connection + do_start if @socket.is_a?(StubSocket) end alias_method :start_with_connect, :start diff --git a/spec/acceptance/net_http/net_http_shared.rb b/spec/acceptance/net_http/net_http_shared.rb index 9d540418..ea261b71 100644 --- a/spec/acceptance/net_http/net_http_shared.rb +++ b/spec/acceptance/net_http/net_http_shared.rb @@ -68,8 +68,11 @@ if WebMock::Config.instance.net_http_connect_on_start expect(sockets.length).to eq(1) + expect(sockets.to_a[0]).to be_a(Net::BufferedIO) else - expect(sockets.length).to eq(4) + expect(sockets.length).to eq(2) + expect(sockets.to_a[0]).to be_a(StubSocket) + expect(sockets.to_a[1]).to be_a(Net::BufferedIO) end expect(sockets.all?(&:closed?)).to be(true)