summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/tcpsocket
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/socket/tcpsocket')
-rw-r--r--spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb18
-rw-r--r--spec/ruby/library/socket/tcpsocket/initialize_spec.rb10
-rw-r--r--spec/ruby/library/socket/tcpsocket/local_address_spec.rb2
-rw-r--r--spec/ruby/library/socket/tcpsocket/remote_address_spec.rb2
-rw-r--r--spec/ruby/library/socket/tcpsocket/shared/new.rb68
5 files changed, 48 insertions, 52 deletions
diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
index f0e98778f5..c6fe007827 100644
--- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
# TODO: verify these for windows
-describe "TCPSocket#gethostbyname" do
+describe "TCPSocket.gethostbyname" do
before :each do
suppress_warning do
@host_info = TCPSocket.gethostbyname(SocketSpecs.hostname)
@@ -10,7 +10,7 @@ describe "TCPSocket#gethostbyname" do
end
it "returns an array elements of information on the hostname" do
- @host_info.should be_kind_of(Array)
+ @host_info.should.is_a?(Array)
end
platform_is_not :windows do
@@ -20,12 +20,12 @@ describe "TCPSocket#gethostbyname" do
it "returns the address type as the third value" do
address_type = @host_info[2]
- [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should be_true
+ [Socket::AF_INET, Socket::AF_INET6].include?(address_type).should == true
end
it "returns the IP address as the fourth value" do
ip = @host_info[3]
- ["127.0.0.1", "::1"].include?(ip).should be_true
+ ["127.0.0.1", "::1"].include?(ip).should == true
end
end
@@ -48,14 +48,14 @@ describe "TCPSocket#gethostbyname" do
end
it "returns any aliases to the address as second value" do
- @host_info[1].should be_kind_of(Array)
+ @host_info[1].should.is_a?(Array)
end
end
-describe 'TCPSocket#gethostbyname' do
+describe 'TCPSocket.gethostbyname' do
it 'returns an Array' do
suppress_warning do
- TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array)
+ TCPSocket.gethostbyname('127.0.0.1').should.instance_of?(Array)
end
end
@@ -72,11 +72,11 @@ describe 'TCPSocket#gethostbyname' do
end
it 'includes an array of alternative hostnames as the 2nd value' do
- @array[1].should be_an_instance_of(Array)
+ @array[1].should.instance_of?(Array)
end
it 'includes the address family as the 3rd value' do
- @array[2].should be_kind_of(Integer)
+ @array[2].should.is_a?(Integer)
end
it 'includes the IP addresses as all the remaining values' do
diff --git a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb
index d7feb9751b..a33d0b16ba 100644
--- a/spec/ruby/library/socket/tcpsocket/initialize_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/initialize_spec.rb
@@ -31,7 +31,7 @@ describe 'TCPSocket#initialize' do
SocketSpecs.each_ip_protocol do |family, ip_address|
describe 'when no server is listening on the given address' do
it 'raises Errno::ECONNREFUSED' do
- -> { TCPSocket.new(ip_address, 666) }.should raise_error(Errno::ECONNREFUSED)
+ -> { TCPSocket.new(ip_address, 666) }.should.raise(Errno::ECONNREFUSED)
end
end
@@ -48,21 +48,21 @@ describe 'TCPSocket#initialize' do
it 'returns a TCPSocket when using an Integer as the port' do
@client = TCPSocket.new(ip_address, @port)
- @client.should be_an_instance_of(TCPSocket)
+ @client.should.instance_of?(TCPSocket)
end
it 'returns a TCPSocket when using a String as the port' do
@client = TCPSocket.new(ip_address, @port.to_s)
- @client.should be_an_instance_of(TCPSocket)
+ @client.should.instance_of?(TCPSocket)
end
it 'raises SocketError when the port number is a non numeric String' do
- -> { TCPSocket.new(ip_address, 'cats') }.should raise_error(SocketError)
+ -> { TCPSocket.new(ip_address, 'cats') }.should.raise(SocketError)
end
it 'set the socket to binmode' do
@client = TCPSocket.new(ip_address, @port)
- @client.binmode?.should be_true
+ @client.binmode?.should == true
end
it 'connects to the right address' do
diff --git a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb b/spec/ruby/library/socket/tcpsocket/local_address_spec.rb
index ce66d5ff8f..5dcf741f29 100644
--- a/spec/ruby/library/socket/tcpsocket/local_address_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/local_address_spec.rb
@@ -23,7 +23,7 @@ describe 'TCPSocket#local_address' do
end
it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
+ @sock.local_address.should.instance_of?(Addrinfo)
end
describe 'the returned Addrinfo' do
diff --git a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb b/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb
index eb9dabc075..085d57b3f9 100644
--- a/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/remote_address_spec.rb
@@ -23,7 +23,7 @@ describe 'TCPSocket#remote_address' do
end
it 'returns an Addrinfo' do
- @sock.remote_address.should be_an_instance_of(Addrinfo)
+ @sock.remote_address.should.instance_of?(Addrinfo)
end
describe 'the returned Addrinfo' do
diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb
index 90f8d7e6a2..cf4834526d 100644
--- a/spec/ruby/library/socket/tcpsocket/shared/new.rb
+++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb
@@ -3,37 +3,24 @@ require_relative '../../fixtures/classes'
describe :tcpsocket_new, shared: true do
it "requires a hostname and a port as arguments" do
- -> { TCPSocket.send(@method) }.should raise_error(ArgumentError)
+ -> { TCPSocket.send(@method) }.should.raise(ArgumentError)
end
it "refuses the connection when there is no server to connect to" do
-> do
TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.reserved_unused_port)
- end.should raise_error(SystemCallError) {|e|
- [Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should include(e.class)
+ end.should.raise(SystemCallError) {|e|
+ [Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL].should.include?(e.class)
}
end
- ruby_version_is ""..."3.2" 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)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
- end
-
- ruby_version_is "3.2" do
- it 'raises IO::TimeoutError 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(IO::TimeoutError)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
+ it 'raises IO::TimeoutError 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(IO::TimeoutError)
+ rescue Errno::ENETUNREACH
+ # In the case all network interfaces down.
+ # raise_error cannot deal with multiple expected exceptions
end
describe "with a running server" do
@@ -52,34 +39,43 @@ describe :tcpsocket_new, shared: true do
it "silently ignores 'nil' as the third parameter" do
@socket = TCPSocket.send(@method, @hostname, @server.port, nil)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
end
it "connects to a listening server with host and port" do
@socket = TCPSocket.send(@method, @hostname, @server.port)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
end
it "connects to a server when passed local_host argument" do
@socket = TCPSocket.send(@method, @hostname, @server.port, @hostname)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
end
it "connects to a server when passed local_host and local_port arguments" do
- server = TCPServer.new(SocketSpecs.hostname, 0)
+ retries = 0
+ max_retries = 3
+
begin
- available_port = server.addr[1]
- ensure
- server.close
+ retries += 1
+ server = TCPServer.new(SocketSpecs.hostname, 0)
+ begin
+ available_port = server.addr[1]
+ ensure
+ server.close
+ end
+ @socket = TCPSocket.send(@method, @hostname, @server.port,
+ @hostname, available_port)
+ rescue Errno::EADDRINUSE
+ raise if retries >= max_retries
+ retry
end
- @socket = TCPSocket.send(@method, @hostname, @server.port,
- @hostname, available_port)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
end
it "has an address once it has connected to a listening server" do
@socket = TCPSocket.send(@method, @hostname, @server.port)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
# TODO: Figure out how to abstract this. You can get AF_INET
# from 'Socket.getaddrinfo(hostname, nil)[0][3]' but socket.addr
@@ -94,13 +90,13 @@ describe :tcpsocket_new, shared: true do
@socket.addr[3].should == SocketSpecs.addr(:ipv6)
end
- @socket.addr[1].should be_kind_of(Integer)
+ @socket.addr[1].should.is_a?(Integer)
@socket.addr[2].should =~ /^#{@hostname}/
end
it "connects to a server when passed connect_timeout argument" do
@socket = TCPSocket.send(@method, @hostname, @server.port, connect_timeout: 1)
- @socket.should be_an_instance_of(TCPSocket)
+ @socket.should.instance_of?(TCPSocket)
end
end
end