Skip to content

Commit

Permalink
Merge pull request #54 from agustin/fix-real_tcp-call
Browse files Browse the repository at this point in the history
Propagates positional and keyword arguments to the real_tcp method
  • Loading branch information
sionide21 authored Nov 27, 2024
2 parents f4d53fc + f1dfdcf commit f2eedc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class Socket
class << self
alias_method :real_tcp, :tcp

def tcp(host, port, *socket_opts)
def tcp(host, port, *local_args, **timeout_opts)
if TCR.configuration.hook_tcp_ports.include?(port)
TCR::RecordableTCPSocket.new(host, port, TCR.cassette)
else
real_tcp(host, port, *socket_opts)
real_tcp(host, port, *local_args, **timeout_opts)
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/tcr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,18 @@
end
}.not_to raise_error
end

context "when port is not in hook_tcp_ports" do
it "it honors Socket.tcp keyword arguments" do
TCR.configure { |c|
c.hook_tcp_ports = [8080]
c.cassette_library_dir = "."
}

TCR.use_cassette("test") do
sock = Socket.tcp("google.com", 80, connect_timeout: 1, resolv_timeout: 1)
expect(sock).to be_a(Socket)
end
end
end
end

0 comments on commit f2eedc5

Please sign in to comment.