From 3ae2a94eac6496bd0795ebdea78b082beae7847e Mon Sep 17 00:00:00 2001 From: Agustin Date: Tue, 4 Jun 2024 12:28:16 +0200 Subject: [PATCH] Propagates positional and keyword arguments to the real_tcp method --- lib/tcr.rb | 4 ++-- spec/tcr_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/tcr.rb b/lib/tcr.rb index 2999f23..9bccd49 100644 --- a/lib/tcr.rb +++ b/lib/tcr.rb @@ -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 diff --git a/spec/tcr_spec.rb b/spec/tcr_spec.rb index 3fd628b..cdc14ea 100644 --- a/spec/tcr_spec.rb +++ b/spec/tcr_spec.rb @@ -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