summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 16:19:40 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 16:19:40 +0000
commitb53cf149ad8d7c46572e4567ca949b4f82ebb22c (patch)
treeee5032bcb38573dade8ba2c46acbcc0d5f3ddfe3 /spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
parentaeeaadaad08038217440c1e9e7c5ca126d7dc633 (diff)
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb')
-rw-r--r--spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb62
1 files changed, 61 insertions, 1 deletions
diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
index 9f25280a70..230d14bfb0 100644
--- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../../spec_helper'
+require_relative '../spec_helper'
require_relative '../fixtures/classes'
# TODO: verify these for windows
@@ -49,3 +49,63 @@ describe "TCPSocket#gethostbyname" do
@host_info[1].should be_kind_of(Array)
end
end
+
+describe 'TCPSocket#gethostbyname' do
+ it 'returns an Array' do
+ TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array)
+ end
+
+ describe 'using a hostname' do
+ describe 'the returned Array' do
+ before do
+ @array = TCPSocket.gethostbyname('127.0.0.1')
+ end
+
+ it 'includes the canonical name as the 1st value' do
+ @array[0].should == '127.0.0.1'
+ end
+
+ it 'includes an array of alternative hostnames as the 2nd value' do
+ @array[1].should be_an_instance_of(Array)
+ end
+
+ it 'includes the address family as the 3rd value' do
+ @array[2].should be_an_instance_of(Fixnum)
+ end
+
+ it 'includes the IP addresses as all the remaining values' do
+ ips = %w{::1 127.0.0.1}
+
+ ips.include?(@array[3]).should == true
+
+ # Not all machines might have both IPv4 and IPv6 set up, so this value is
+ # optional.
+ ips.include?(@array[4]).should == true if @array[4]
+ end
+ end
+ end
+
+ SocketSpecs.each_ip_protocol do |family, ip_address|
+ describe 'the returned Array' do
+ before do
+ @array = TCPSocket.gethostbyname(ip_address)
+ end
+
+ it 'includes the IP address as the 1st value' do
+ @array[0].should == ip_address
+ end
+
+ it 'includes an empty list of aliases as the 2nd value' do
+ @array[1].should == []
+ end
+
+ it 'includes the address family as the 3rd value' do
+ @array[2].should == family
+ end
+
+ it 'includes the IP address as the 4th value' do
+ @array[3].should == ip_address
+ end
+ end
+ end
+end