summaryrefslogtreecommitdiff
path: root/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb
blob: f8be672612aa8f507cf9b1ff46c06a4dfa45b04a (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
require_relative '../spec_helper'

describe 'Socket.udp_server_sockets' do
  describe 'without a block' do
    before do
      @sockets = nil
    end

    after do
      @sockets.each(&:close)
    end

    it 'returns an Array of Socket objects' do
      @sockets = Socket.udp_server_sockets(0)

      @sockets.should be_an_instance_of(Array)
      @sockets[0].should be_an_instance_of(Socket)
    end
  end

  describe 'with a block' do
    it 'yields the sockets to the supplied block' do
      Socket.udp_server_sockets(0) do |sockets|
        sockets.should be_an_instance_of(Array)
        sockets[0].should be_an_instance_of(Socket)
      end
    end

    it 'closes all sockets after the block returns' do
      sockets = nil

      Socket.udp_server_sockets(0) { |socks| sockets = socks }

      sockets.each do |socket|
        socket.should.closed?
      end
    end
  end
end