diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-06-27 21:02:36 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-06-27 21:02:36 +0200 |
commit | d80e44deec77678fe2d72f94c17b2409b3e794d5 (patch) | |
tree | 612bf2313550e0982dda452f48492cc069e1c21a /spec/ruby/library | |
parent | c940397116c5aef76b1c0d05561c11d43ef596a7 (diff) | |
download | ruby-d80e44deec77678fe2d72f94c17b2409b3e794d5.tar.gz |
Update to ruby/spec@8d74d49
Diffstat (limited to 'spec/ruby/library')
21 files changed, 113 insertions, 27 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 98b3f47703..ec38c6f113 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -150,8 +150,13 @@ describe "Kernel#BigDecimal" do BigDecimal("-12345.6E-1").should == -reference end - it 'raises ArgumentError when Float is used without precision' do + it "raises ArgumentError when Float is used without precision" do lambda { BigDecimal(1.0) }.should raise_error(ArgumentError) end + it "returns appropriate BigDecimal zero for signed zero" do + BigDecimal(-0.0, Float::DIG).sign.should == -1 + BigDecimal(0.0, Float::DIG).sign.should == 1 + end + end diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb index 18e9ca9a0c..7ce47142b2 100644 --- a/spec/ruby/library/bigdecimal/inspect_spec.rb +++ b/spec/ruby/library/bigdecimal/inspect_spec.rb @@ -15,6 +15,12 @@ describe "BigDecimal#inspect" do @bigdec.inspect.should == "0.12345678e4" end + it "does not add an exponent for zero values" do + BigDecimal("0").inspect.should == "0.0" + BigDecimal("+0").inspect.should == "0.0" + BigDecimal("-0").inspect.should == "-0.0" + end + it "properly cases non-finite values" do BigDecimal("NaN").inspect.should == "NaN" BigDecimal("Infinity").inspect.should == "Infinity" diff --git a/spec/ruby/library/bigdecimal/to_d_spec.rb b/spec/ruby/library/bigdecimal/to_d_spec.rb index 8e20901fd9..50aea99bf7 100644 --- a/spec/ruby/library/bigdecimal/to_d_spec.rb +++ b/spec/ruby/library/bigdecimal/to_d_spec.rb @@ -2,7 +2,6 @@ require_relative '../../spec_helper' require 'bigdecimal' require 'bigdecimal/util' - describe "Float#to_d" do it "returns appropriate BigDecimal zero for signed zero" do -0.0.to_d.sign.should == -1 diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 247db1a5d2..c7ee6a01b0 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -19,6 +19,12 @@ describe "BigDecimal#to_s" do @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/ end + it "does not add an exponent for zero values" do + BigDecimal("0").to_s.should == "0.0" + BigDecimal("+0").to_s.should == "0.0" + BigDecimal("-0").to_s.should == "-0.0" + end + it "takes an optional argument" do lambda {@bigdec.to_s("F")}.should_not raise_error() end diff --git a/spec/ruby/library/matrix/coerce_spec.rb b/spec/ruby/library/matrix/coerce_spec.rb index b8d5484657..280243d372 100644 --- a/spec/ruby/library/matrix/coerce_spec.rb +++ b/spec/ruby/library/matrix/coerce_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' require 'matrix' describe "Matrix#coerce" do - it "needs to be reviewed for spec completeness" - it "allows the division of fixnum by a Matrix " do (1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] end diff --git a/spec/ruby/library/net/ftp/set_socket_spec.rb b/spec/ruby/library/net/ftp/set_socket_spec.rb index 3aa5686326..7ca3bbbe27 100644 --- a/spec/ruby/library/net/ftp/set_socket_spec.rb +++ b/spec/ruby/library/net/ftp/set_socket_spec.rb @@ -4,5 +4,5 @@ require_relative 'spec_helper' describe "Net::FTP#set_socket" do # TODO: I won't spec this method, as it is not used # anywhere and it should be private anyway. - #it "needs to be reviewed for spec completeness" + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/open3/popen3_spec.rb b/spec/ruby/library/open3/popen3_spec.rb index 9afb5f5382..d3103ad3cb 100644 --- a/spec/ruby/library/open3/popen3_spec.rb +++ b/spec/ruby/library/open3/popen3_spec.rb @@ -38,6 +38,4 @@ describe "Open3.popen3" do out.read.should == "foo" end end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/pp/pp_spec.rb b/spec/ruby/library/pp/pp_spec.rb index dba20d190d..c4559b35ca 100644 --- a/spec/ruby/library/pp/pp_spec.rb +++ b/spec/ruby/library/pp/pp_spec.rb @@ -20,6 +20,4 @@ describe "PP.pp" do other_out.to_s.should == "[1, 2, 3]\n" end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb index 1b6027d26c..26683b3d23 100644 --- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb @@ -35,6 +35,11 @@ describe "Socket::BasicSocket#recv_nonblock" do } end + it "returns :wait_readable with exception: false" do + @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) + @s1.recv_nonblock(5, exception: false).should == :wait_readable + end + it "receives data after it's ready" do @s1.bind(Socket.pack_sockaddr_in(0, ip_address)) @s2.send("aaa", 0, @s1.getsockname) diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb index 8f6b75029c..c440bac8bf 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -31,6 +31,10 @@ describe 'BasicSocket#recvmsg_nonblock' do it 'raises an exception extending IO::WaitReadable' do lambda { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvmsg_nonblock(exception: false).should == :wait_readable + end end describe 'with data available' do diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb index de5e2aa749..000971f6af 100644 --- a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb @@ -98,6 +98,15 @@ describe 'BasicSocket#sendmsg_nonblock' do 10.times { @client.sendmsg_nonblock('hello' * 1_000_000) } }.should raise_error(IO::WaitWritable) end + + it 'returns :wait_writable when the underlying buffer is full with exception: false' do + ret = nil + 10.times { + ret = @client.sendmsg_nonblock('hello' * 1_000_000, exception: false) + break unless ret.is_a?(Integer) + } + ret.should == :wait_writable + end end end end diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb index 9367030e25..2696f44566 100644 --- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb @@ -2,15 +2,15 @@ require_relative '../spec_helper' require_relative '../fixtures/classes' -describe "Socket#gethostbyname" do +describe "Socket.gethostbyname" do it "returns broadcast address info for '<broadcast>'" do addr = Socket.gethostbyname('<broadcast>'); - addr.should == ["255.255.255.255", [], 2, "\377\377\377\377"] + addr.should == ["255.255.255.255", [], 2, "\xFF\xFF\xFF\xFF"] end it "returns broadcast address info for '<any>'" do addr = Socket.gethostbyname('<any>'); - addr.should == ["0.0.0.0", [], 2, "\000\000\000\000"] + addr.should == ["0.0.0.0", [], 2, "\x00\x00\x00\x00"] end end diff --git a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb index 74fd286c42..5f717d4b54 100644 --- a/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb @@ -31,6 +31,10 @@ describe 'Socket#recvfrom_nonblock' do it 'raises IO::WaitReadable' do lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvfrom_nonblock(1, exception: false).should == :wait_readable + end end describe 'with data available' do diff --git a/spec/ruby/library/socket/udpsocket/initialize_spec.rb b/spec/ruby/library/socket/udpsocket/initialize_spec.rb index 9497d0dcbc..1d635149f7 100644 --- a/spec/ruby/library/socket/udpsocket/initialize_spec.rb +++ b/spec/ruby/library/socket/udpsocket/initialize_spec.rb @@ -31,12 +31,10 @@ describe 'UDPSocket#initialize' do end it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do - begin + -> { UDPSocket.new(666) - rescue Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT => e + }.should raise_error(SystemCallError) { |e| [Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT].should include(e.class) - else - raise "expected Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT exception raised" - end + } end end diff --git a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb index 62bbaf0dc9..fb88a2dc13 100644 --- a/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb +++ b/spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb @@ -34,6 +34,10 @@ describe 'UDPSocket#recvfrom_nonblock' do it 'raises IO::WaitReadable' do lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable) end + + it 'returns :wait_readable with exception: false' do + @server.recvfrom_nonblock(1, exception: false).should == :wait_readable + end end platform_is_not :windows do diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb index 56b3ccc557..cbf315f9f4 100644 --- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb +++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb @@ -47,3 +47,50 @@ with_feature :unix_socket do end end end + +with_feature :unix_socket do + describe 'UNIXSocket#local_address with a UNIX socket pair' do + before :each do + @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + end + + after :each do + @sock.close + @sock2.close + end + + it 'returns an Addrinfo' do + @sock.local_address.should be_an_instance_of(Addrinfo) + end + + describe 'the returned Addrinfo' do + it 'uses AF_UNIX as the address family' do + @sock.local_address.afamily.should == Socket::AF_UNIX + end + + it 'uses PF_UNIX as the protocol family' do + @sock.local_address.pfamily.should == Socket::PF_UNIX + end + + it 'uses SOCK_STREAM as the socket type' do + @sock.local_address.socktype.should == Socket::SOCK_STREAM + end + + it 'raises SocketError for #ip_address' do + -> { + @sock.local_address.ip_address + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end + + it 'raises SocketError for #ip_port' do + -> { + @sock.local_address.ip_port + }.should raise_error(SocketError, "need IPv4 or IPv6 address") + end + + it 'uses 0 as the protocol' do + @sock.local_address.protocol.should == 0 + end + end + end +end diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb index 7a79eef3c5..2a8f926bd0 100644 --- a/spec/ruby/library/stringio/read_nonblock_spec.rb +++ b/spec/ruby/library/stringio/read_nonblock_spec.rb @@ -26,4 +26,17 @@ describe "StringIO#read_nonblock" do stringio.read_nonblock(3, exception: false).should == 'foo' end + context "when exception option is set to false" do + context "when the end is reached" do + it "returns nil" do + stringio = StringIO.new('') + stringio << "hello" + stringio.rewind + + stringio.read_nonblock(5).should == "hello" + stringio.read_nonblock(5, exception: false).should be_nil + end + end + end + end diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb index 604bf880e5..139c4fb02f 100644 --- a/spec/ruby/library/stringio/shared/read.rb +++ b/spec/ruby/library/stringio/shared/read.rb @@ -69,7 +69,7 @@ describe :stringio_read_length, shared: true do end it "returns a binary String" do - @io.send(@method, 4).encoding.should == Encoding::ASCII_8BIT + @io.send(@method, 4).encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/library/stringscanner/shared/concat.rb b/spec/ruby/library/stringscanner/shared/concat.rb index 28788d3ff1..214455d1b9 100644 --- a/spec/ruby/library/stringscanner/shared/concat.rb +++ b/spec/ruby/library/stringscanner/shared/concat.rb @@ -25,6 +25,6 @@ describe :strscan_concat_fixnum, shared: true do x = mock('x') x.should_not_receive(:to_int) - lambda { "".send(@method, x) }.should raise_error(TypeError) + lambda { StringScanner.new("").send(@method, x) }.should raise_error(TypeError) end end diff --git a/spec/ruby/library/uri/mailto/build_spec.rb b/spec/ruby/library/uri/mailto/build_spec.rb index 80af931c8c..ca3b270c2c 100644 --- a/spec/ruby/library/uri/mailto/build_spec.rb +++ b/spec/ruby/library/uri/mailto/build_spec.rb @@ -90,9 +90,3 @@ describe "URI::Mailto.build" do ok.flatten.join("\0").should == ok_all end end - - - -describe "URI::MailTo.build" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/library/zlib/gzipwriter/append_spec.rb b/spec/ruby/library/zlib/gzipwriter/append_spec.rb index 9404dbd8b2..6aa2824180 100644 --- a/spec/ruby/library/zlib/gzipwriter/append_spec.rb +++ b/spec/ruby/library/zlib/gzipwriter/append_spec.rb @@ -12,6 +12,4 @@ describe "Zlib::GzipWriter#<<" do (gzio << "test").should equal(gzio) end end - - it "needs to be reviewed for spec completeness" end |