summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/socket/ip_address_list_spec.rb
blob: f97c2d7f85b2498e741feea17d8fb97f808225e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require_relative '../spec_helper'

describe 'Socket.ip_address_list' do
  it 'returns an Array' do
    Socket.ip_address_list.should be_an_instance_of(Array)
  end

  describe 'the returned Array' do
    before do
      @array = Socket.ip_address_list
    end

    it 'is not empty' do
      @array.should_not be_empty
    end

    it 'contains Addrinfo objects' do
      @array.each do |klass|
        klass.should be_an_instance_of(Addrinfo)
      end
    end
  end

  describe 'each returned Addrinfo' do
    before do
      @array = Socket.ip_address_list
    end

    it 'has a non-empty IP address' do
      @array.each do |addr|
        addr.ip_address.should be_an_instance_of(String)
        addr.ip_address.should_not be_empty
      end
    end

    it 'has an address family' do
      families = [Socket::AF_INET, Socket::AF_INET6]

      @array.each do |addr|
        families.include?(addr.afamily).should == true
      end
    end

    it 'uses 0 as the port number' do
      @array.each do |addr|
        addr.ip_port.should == 0
      end
    end
  end
end