summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket/shared')
-rw-r--r--spec/ruby/library/socket/shared/address.rb92
-rw-r--r--spec/ruby/library/socket/shared/pack_sockaddr.rb69
-rw-r--r--spec/ruby/library/socket/shared/socketpair.rb38
3 files changed, 96 insertions, 103 deletions
diff --git a/spec/ruby/library/socket/shared/address.rb b/spec/ruby/library/socket/shared/address.rb
index f3be9cfb99..c64602df2f 100644
--- a/spec/ruby/library/socket/shared/address.rb
+++ b/spec/ruby/library/socket/shared/address.rb
@@ -46,7 +46,7 @@ describe :socket_local_remote_address, shared: true do
end
it 'returns an Addrinfo' do
- @addr.should be_an_instance_of(Addrinfo)
+ @addr.should.instance_of?(Addrinfo)
end
it 'uses 0 as the protocol' do
@@ -110,7 +110,7 @@ describe :socket_local_remote_address, shared: true do
end
it 'returns an Addrinfo' do
- @addr.should be_an_instance_of(Addrinfo)
+ @addr.should.instance_of?(Addrinfo)
end
it 'uses 0 as the protocol' do
@@ -129,41 +129,51 @@ describe :socket_local_remote_address, shared: true do
end
end
- with_feature :unix_socket do
- describe 'using UNIXSocket' do
- before :each do
- @path = SocketSpecs.socket_path
- @s = UNIXServer.new(@path)
- @a = UNIXSocket.new(@path)
- @b = @s.accept
- @addr = @object.call(@a)
- end
+ describe 'using UNIXSocket' do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @s = UNIXServer.new(@path)
+ @a = UNIXSocket.new(@path)
+ @b = @s.accept
+ @addr = @object.call(@a)
+ end
- after :each do
- [@b, @a, @s].each(&:close)
- rm_r(@path)
- end
+ after :each do
+ [@b, @a, @s].each(&:close)
+ rm_r(@path)
+ end
- it 'uses AF_UNIX as the address family' do
- @addr.afamily.should == Socket::AF_UNIX
- end
+ it 'uses AF_UNIX as the address family' do
+ @addr.afamily.should == Socket::AF_UNIX
+ end
- it 'uses PF_UNIX as the protocol family' do
- @addr.pfamily.should == Socket::PF_UNIX
- end
+ it 'uses PF_UNIX as the protocol family' do
+ @addr.pfamily.should == Socket::PF_UNIX
+ end
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
+ it 'uses SOCK_STREAM as the socket type' do
+ @addr.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'uses the correct socket path' do
+ if @method == :local_address
+ @addr.unix_path.should == ""
+ else
+ @addr.unix_path.should == @path
end
+ end
- it 'uses the correct socket path' do
+ platform_is_not :windows do
+ it 'equals address of peer socket' do
if @method == :local_address
- @addr.unix_path.should == ""
+ @addr.to_s.should == @b.remote_address.to_s
else
- @addr.unix_path.should == @path
+ @addr.to_s.should == @b.local_address.to_s
end
end
+ end
+ guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do
it 'equals address of peer socket' do
if @method == :local_address
@addr.to_s.should == @b.remote_address.to_s
@@ -171,23 +181,23 @@ describe :socket_local_remote_address, shared: true do
@addr.to_s.should == @b.local_address.to_s
end
end
+ end
- it 'returns an Addrinfo' do
- @addr.should be_an_instance_of(Addrinfo)
- end
+ it 'returns an Addrinfo' do
+ @addr.should.instance_of?(Addrinfo)
+ end
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
+ it 'uses 0 as the protocol' do
+ @addr.protocol.should == 0
+ end
- it 'can be used to connect to the server' do
- skip if @method == :local_address
- b = @addr.connect
- begin
- b.remote_address.to_s.should == @addr.to_s
- ensure
- b.close
- end
+ it 'can be used to connect to the server' do
+ skip if @method == :local_address
+ b = @addr.connect
+ begin
+ b.remote_address.to_s.should == @addr.to_s
+ ensure
+ b.close
end
end
end
@@ -230,7 +240,7 @@ describe :socket_local_remote_address, shared: true do
end
it 'returns an Addrinfo' do
- @addr.should be_an_instance_of(Addrinfo)
+ @addr.should.instance_of?(Addrinfo)
end
it 'uses 0 as the protocol' do
diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb
index 26fdf682b1..db6f39612d 100644
--- a/spec/ruby/library/socket/shared/pack_sockaddr.rb
+++ b/spec/ruby/library/socket/shared/pack_sockaddr.rb
@@ -22,70 +22,53 @@ describe :socket_pack_sockaddr_in, shared: true do
Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0']
end
- platform_is_not :solaris do
- it 'resolves the service name to a port' do
- sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1')
- Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1']
- end
+ it 'resolves the service name to a port' do
+ sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1')
+ Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1']
end
describe 'using an IPv4 address' do
it 'returns a String of 16 bytes' do
str = Socket.public_send(@method, 80, '127.0.0.1')
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
str.bytesize.should == 16
end
end
- platform_is_not :solaris do
- describe 'using an IPv6 address' do
- it 'returns a String of 28 bytes' do
- str = Socket.public_send(@method, 80, '::1')
-
- str.should be_an_instance_of(String)
- str.bytesize.should == 28
- end
- end
- end
-
- platform_is :solaris do
- describe 'using an IPv6 address' do
- it 'returns a String of 32 bytes' do
- str = Socket.public_send(@method, 80, '::1')
+ describe 'using an IPv6 address' do
+ it 'returns a String of 28 bytes' do
+ str = Socket.public_send(@method, 80, '::1')
- str.should be_an_instance_of(String)
- str.bytesize.should == 32
- end
+ str.should.instance_of?(String)
+ str.bytesize.should == 28
end
end
end
describe :socket_pack_sockaddr_un, shared: true do
- with_feature :unix_socket do
- it 'should be idempotent' do
- bytes = Socket.public_send(@method, '/tmp/foo').bytes
- bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111]
- bytes[10..-1].all?(&:zero?).should == true
- end
+ it 'should be idempotent' do
+ bytes = Socket.public_send(@method, '/tmp/foo').bytes
+ bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111]
+ bytes[10..-1].all?(&:zero?).should == true
+ end
- it "packs and unpacks" do
- sockaddr_un = Socket.public_send(@method, '/tmp/s')
- Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s'
- end
+ it "packs and unpacks" do
+ sockaddr_un = Socket.public_send(@method, '/tmp/s')
+ Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s'
+ end
- it "handles correctly paths with multibyte chars" do
- sockaddr_un = Socket.public_send(@method, '/home/вася/sock')
- path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8')
- path.should == '/home/вася/sock'
- end
+ it "handles correctly paths with multibyte chars" do
+ sockaddr_un = Socket.public_send(@method, '/home/вася/sock')
+ path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8')
+ path.should == '/home/вася/sock'
end
platform_is :linux do
it 'returns a String of 110 bytes' do
str = Socket.public_send(@method, '/tmp/test.sock')
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
str.bytesize.should == 110
end
end
@@ -94,16 +77,16 @@ describe :socket_pack_sockaddr_un, shared: true do
it 'returns a String of 106 bytes' do
str = Socket.public_send(@method, '/tmp/test.sock')
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
str.bytesize.should == 106
end
end
- platform_is_not :windows, :aix do
+ platform_is_not :aix do
it "raises ArgumentError for paths that are too long" do
# AIX doesn't raise error
long_path = 'a' * 110
- -> { Socket.public_send(@method, long_path) }.should raise_error(ArgumentError)
+ -> { Socket.public_send(@method, long_path) }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/library/socket/shared/socketpair.rb b/spec/ruby/library/socket/shared/socketpair.rb
index 25146cfff6..7fcd4d6b46 100644
--- a/spec/ruby/library/socket/shared/socketpair.rb
+++ b/spec/ruby/library/socket/shared/socketpair.rb
@@ -12,8 +12,8 @@ describe :socket_socketpair, shared: true do
begin
s1, s2 = Socket.public_send(@method, :UNIX, :STREAM)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
ensure
s1.close
s2.close
@@ -24,8 +24,8 @@ describe :socket_socketpair, shared: true do
it 'returns two Socket objects' do
s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, Socket::SOCK_STREAM)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
s1.close
s2.close
end
@@ -35,18 +35,18 @@ describe :socket_socketpair, shared: true do
it 'returns two Socket objects' do
s1, s2 = Socket.public_send(@method, :UNIX, :STREAM)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
s1.close
s2.close
end
it 'raises SocketError for an unknown address family' do
- -> { Socket.public_send(@method, :CATS, :STREAM) }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, :CATS, :STREAM) }.should.raise(SocketError)
end
it 'raises SocketError for an unknown socket type' do
- -> { Socket.public_send(@method, :UNIX, :CATS) }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, :UNIX, :CATS) }.should.raise(SocketError)
end
end
@@ -54,18 +54,18 @@ describe :socket_socketpair, shared: true do
it 'returns two Socket objects' do
s1, s2 = Socket.public_send(@method, 'UNIX', 'STREAM')
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
s1.close
s2.close
end
it 'raises SocketError for an unknown address family' do
- -> { Socket.public_send(@method, 'CATS', 'STREAM') }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, 'CATS', 'STREAM') }.should.raise(SocketError)
end
it 'raises SocketError for an unknown socket type' do
- -> { Socket.public_send(@method, 'UNIX', 'CATS') }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, 'UNIX', 'CATS') }.should.raise(SocketError)
end
end
@@ -79,8 +79,8 @@ describe :socket_socketpair, shared: true do
s1, s2 = Socket.public_send(@method, family, type)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
s1.close
s2.close
end
@@ -92,7 +92,7 @@ describe :socket_socketpair, shared: true do
family.stub!(:to_str).and_return(Socket::AF_UNIX)
type.stub!(:to_str).and_return(Socket::SOCK_STREAM)
- -> { Socket.public_send(@method, family, type) }.should raise_error(TypeError)
+ -> { Socket.public_send(@method, family, type) }.should.raise(TypeError)
end
it 'raises SocketError for an unknown address family' do
@@ -102,7 +102,7 @@ describe :socket_socketpair, shared: true do
family.stub!(:to_str).and_return('CATS')
type.stub!(:to_str).and_return('STREAM')
- -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, family, type) }.should.raise(SocketError)
end
it 'raises SocketError for an unknown socket type' do
@@ -112,14 +112,14 @@ describe :socket_socketpair, shared: true do
family.stub!(:to_str).and_return('UNIX')
type.stub!(:to_str).and_return('CATS')
- -> { Socket.public_send(@method, family, type) }.should raise_error(SocketError)
+ -> { Socket.public_send(@method, family, type) }.should.raise(SocketError)
end
end
it 'accepts a custom protocol as an Integer as the 3rd argument' do
s1, s2 = Socket.public_send(@method, :UNIX, :STREAM, Socket::IPPROTO_IP)
- s1.should be_an_instance_of(Socket)
- s2.should be_an_instance_of(Socket)
+ s1.should.instance_of?(Socket)
+ s2.should.instance_of?(Socket)
s1.close
s2.close
end