summaryrefslogtreecommitdiff
path: root/spec/ruby/library
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library')
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb11
-rw-r--r--spec/ruby/library/net/http/http/get_spec.rb10
-rw-r--r--spec/ruby/library/objectspace/memsize_of_spec.rb4
-rw-r--r--spec/ruby/library/socket/tcpserver/accept_spec.rb20
4 files changed, 40 insertions, 5 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 4e839e21a3..5da0210145 100644
--- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -112,6 +112,17 @@ describe "Kernel#BigDecimal" do
neg_inf.should < 0
end
+ ruby_version_is "2.6" do
+ describe "with exception: false" do
+ it "returns nil for invalid strings" do
+ BigDecimal("invalid", exception: false).should be_nil
+ BigDecimal("0invalid", exception: false).should be_nil
+ BigDecimal("invalid0", exception: false).should be_nil
+ BigDecimal("0.", exception: false).should be_nil
+ end
+ end
+ end
+
describe "accepts NaN and [+-]Infinity as Float values" do
it "works without an explicit precision" do
BigDecimal(Float::NAN).should.nan?
diff --git a/spec/ruby/library/net/http/http/get_spec.rb b/spec/ruby/library/net/http/http/get_spec.rb
index 35bd51d9a3..dbdca4a431 100644
--- a/spec/ruby/library/net/http/http/get_spec.rb
+++ b/spec/ruby/library/net/http/http/get_spec.rb
@@ -60,15 +60,16 @@ describe "Net::HTTP.get" do
Thread.current.report_on_exception = false
Net::HTTP.get("127.0.0.1", '/', server.connect_address.ip_port)
end
+
+ socket = server_thread.value
Thread.pass until client_thread.stop?
- [server_thread, client_thread]
+ [socket, client_thread]
end
it "propagates exceptions interrupting the thread and does not replace it with Zlib::BufError" do
my_exception = Class.new(RuntimeError)
- server_thread, client_thread = start_threads
- socket = server_thread.value
+ socket, client_thread = start_threads
begin
client_thread.raise my_exception, "my exception"
-> { client_thread.value }.should raise_error(my_exception)
@@ -79,8 +80,7 @@ describe "Net::HTTP.get" do
ruby_version_is "2.8" do # https://bugs.ruby-lang.org/issues/13882#note-6
it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do
- server_thread, client_thread = start_threads
- socket = server_thread.value
+ socket, client_thread = start_threads
begin
client_thread.kill
client_thread.value.should == nil
diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb
index 06a80d9f9c..36d845824d 100644
--- a/spec/ruby/library/objectspace/memsize_of_spec.rb
+++ b/spec/ruby/library/objectspace/memsize_of_spec.rb
@@ -12,6 +12,10 @@ describe "ObjectSpace.memsize_of" do
ObjectSpace.memsize_of(42).should == 0
end
+ it "returns 0 for literal Symbols" do
+ ObjectSpace.memsize_of(:abc).should == 0
+ end
+
it "returns an Integer for an Object" do
obj = Object.new
ObjectSpace.memsize_of(obj).should be_kind_of(Integer)
diff --git a/spec/ruby/library/socket/tcpserver/accept_spec.rb b/spec/ruby/library/socket/tcpserver/accept_spec.rb
index 0da4e2218b..d38d95e0e1 100644
--- a/spec/ruby/library/socket/tcpserver/accept_spec.rb
+++ b/spec/ruby/library/socket/tcpserver/accept_spec.rb
@@ -58,6 +58,26 @@ describe "TCPServer#accept" do
t.join
end
+ it "is automatically retried when interrupted by SIGVTALRM" do
+ t = Thread.new do
+ client = @server.accept
+ value = client.read(2)
+ client.close
+ value
+ end
+
+ Thread.pass while t.status and t.status != "sleep"
+ # Thread#backtrace uses SIGVTALRM on TruffleRuby and potentially other implementations.
+ # Sending a signal to a thread is not possible with Ruby APIs.
+ t.backtrace.join("\n").should.include?("in `accept'")
+
+ socket = TCPSocket.new('127.0.0.1', @port)
+ socket.write("OK")
+ socket.close
+
+ t.value.should == "OK"
+ end
+
it "raises an IOError if the socket is closed" do
@server.close
-> { @server.accept }.should raise_error(IOError)