From 976577cfdeaf25e5a1eb291dbf98f843076e7333 Mon Sep 17 00:00:00 2001 From: Juan Carlos Ruiz Date: Fri, 15 Oct 2021 23:32:44 -0500 Subject: [PATCH 1/3] Kernel#eval when called with two arguments will use "(eval)" for __FILE__ and 1 for __LINE__ in the evaluated code. --- core/kernel/eval_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/kernel/eval_spec.rb b/core/kernel/eval_spec.rb index 1e2764a4de..59c38c6dee 100644 --- a/core/kernel/eval_spec.rb +++ b/core/kernel/eval_spec.rb @@ -182,6 +182,16 @@ class Object end end + ruby_version_is "3.0" do + context 'with two arguments ' do + platform_is_not :windows do + it 'will use (eval) for __FILE__ and 1 for __LINE__' do + eval("p [__FILE__, __LINE__]", binding).should == ["(eval)", 1] + end + end + end + end + # Found via Rubinius bug github:#149 it "does not alter the value of __FILE__ in the binding" do first_time = EvalSpecs.call_eval From 2a2efe63686efcdbc1ea7178669aa4f53a2a873f Mon Sep 17 00:00:00 2001 From: Juan Carlos Ruiz Date: Fri, 15 Oct 2021 23:45:31 -0500 Subject: [PATCH 2/3] Wrap ETIMEDOUT on ruby_version_is block https://bugs.ruby-lang.org/issues/17187 --- library/socket/tcpsocket/shared/new.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/socket/tcpsocket/shared/new.rb b/library/socket/tcpsocket/shared/new.rb index 30e963b12a..4189acc2f8 100644 --- a/library/socket/tcpsocket/shared/new.rb +++ b/library/socket/tcpsocket/shared/new.rb @@ -14,10 +14,12 @@ } end - it 'raises Errno::ETIMEDOUT with :connect_timeout when no server is listening on the given address' do - -> { - TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) - }.should raise_error(Errno::ETIMEDOUT) + ruby_version_is "3.0" do + it 'raises Errno::ETIMEDOUT with :connect_timeout when no server is listening on the given address' do + -> { + TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) + }.should raise_error(Errno::ETIMEDOUT) + end end describe "with a running server" do From e30b341d81ea7869ea8248b352e210f1affb3bd6 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 16 Oct 2021 13:01:37 +0200 Subject: [PATCH 3/3] Fix eval with Binding __FILE__/__LINE__ spec --- core/kernel/eval_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/kernel/eval_spec.rb b/core/kernel/eval_spec.rb index 59c38c6dee..9be0f2dfd3 100644 --- a/core/kernel/eval_spec.rb +++ b/core/kernel/eval_spec.rb @@ -168,6 +168,12 @@ class Object suppress_warning {eval("eval '__FILE__', binding", binding)}.should == __FILE__ suppress_warning {eval("eval '__FILE__', binding", binding, 'success')}.should == 'success' end + + it 'uses the given binding file and line for __FILE__ and __LINE__' do + suppress_warning { + eval("[__FILE__, __LINE__]", binding).should == [__FILE__, __LINE__] + } + end end ruby_version_is "3.0" do @@ -180,15 +186,9 @@ class Object eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' eval("eval '__FILE__', binding, 'success'", binding).should == 'success' end - end - ruby_version_is "3.0" do - context 'with two arguments ' do - platform_is_not :windows do - it 'will use (eval) for __FILE__ and 1 for __LINE__' do - eval("p [__FILE__, __LINE__]", binding).should == ["(eval)", 1] - end - end + it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] end end