Skip to content

Commit cadef36

Browse files
committed
Make StubSocket#close work as one might expect
1 parent 0e583c0 commit cadef36

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/webmock/http_lib_adapters/net_http.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def start_without_connect
128128

129129

130130
def ensure_actual_connection
131-
do_start if @socket.is_a?(StubSocket)
131+
if @socket.is_a?(StubSocket)
132+
@socket&.close
133+
@socket = nil
134+
do_start
135+
end
132136
end
133137

134138
alias_method :start_with_connect, :start
@@ -232,13 +236,16 @@ class StubSocket #:nodoc:
232236
attr_accessor :read_timeout, :continue_timeout, :write_timeout
233237

234238
def initialize(*args)
239+
@closed = false
235240
end
236241

237242
def closed?
238-
@closed ||= true
243+
@closed
239244
end
240245

241246
def close
247+
@closed = true
248+
nil
242249
end
243250

244251
def readuntil(*args)

0 commit comments

Comments
 (0)