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

with_feature :unix_socket do
  describe 'Socket.unix_server_socket' do
    before do
      @path = SocketSpecs.socket_path
    end

    after do
      rm_r(@path)
    end

    describe 'when no block is given' do
      before do
        @socket = nil
      end

      after do
        @socket.close
      end

      it 'returns a Socket' do
        @socket = Socket.unix_server_socket(@path)

        @socket.should be_an_instance_of(Socket)
      end
    end

    describe 'when a block is given' do
      it 'yields a Socket' do
        Socket.unix_server_socket(@path) do |sock|
          sock.should be_an_instance_of(Socket)
        end
      end

      it 'closes the Socket when the block returns' do
        socket = nil

        Socket.unix_server_socket(@path) do |sock|
          socket = sock
        end

        socket.should be_an_instance_of(Socket)
      end
    end
  end
end