Skip to content

Commit

Permalink
Use super instead of copy-and-paste in `Net::WebMockNetBufferedIO#i…
Browse files Browse the repository at this point in the history
…nitialize`

The body of `Net::WebMockNetBufferedIO#initialize` is a code clone from `Net::BufferedIO#initialize`.
(BTW, it seems that `@continue_timeout = continue_timeout` lacks.)

It is difficult to maintain such a code clone.  Instead, it would be better to use `super` if possible.  This PR also should fix #786 gracefully.
  • Loading branch information
mame authored Dec 19, 2018
1 parent a135a37 commit f2a9ab3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/webmock/http_lib_adapters/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,18 @@ def readuntil(*args)
module Net #:nodoc: all

class WebMockNetBufferedIO < BufferedIO
def initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil)
@read_timeout = read_timeout
@write_timeout = write_timeout
@rbuf = ''.dup
@debug_output = debug_output

@io = case io
def initialize(io, **)
io = case io
when Socket, OpenSSL::SSL::SSLSocket, IO
io
when StringIO
PatchedStringIO.new(io.string)
when String
PatchedStringIO.new(io)
end
raise "Unable to create local socket" unless @io
raise "Unable to create local socket" unless io

super
end

if RUBY_VERSION >= '2.6.0'
Expand Down

0 comments on commit f2a9ab3

Please sign in to comment.