summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket')
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb5
-rw-r--r--spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb4
-rw-r--r--spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb9
-rw-r--r--spec/ruby/library/socket/socket/gethostbyname_spec.rb6
-rw-r--r--spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb4
-rw-r--r--spec/ruby/library/socket/udpsocket/initialize_spec.rb8
-rw-r--r--spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb4
-rw-r--r--spec/ruby/library/socket/unixsocket/local_address_spec.rb47
8 files changed, 79 insertions, 8 deletions
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