summaryrefslogtreecommitdiff
path: root/spec/ruby/core/file/socket_spec.rb
blob: 5d12e21f5596b67c78d1b211cbe27c6997d93c58 (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
require_relative '../../spec_helper'
require_relative '../../shared/file/socket'
require 'socket'

describe "File.socket?" do
  it_behaves_like :file_socket, :socket?, File
end

describe "File.socket?" do
  it "returns false if file does not exist" do
    File.socket?("I_am_a_bogus_file").should == false
  end

  it "returns false if the file is not a socket" do
    filename = tmp("i_exist")
    touch(filename)

    File.socket?(filename).should == false

    rm_r filename
  end
end

platform_is_not :windows do
  describe "File.socket?" do
    before :each do
      # We need a really short name here.
      # On Linux the path length is limited to 107, see unix(7).
      @name = tmp("s")
      @server = UNIXServer.new @name
    end

    after :each do
      @server.close
      rm_r @name
    end

    it "returns true if the file is a socket" do
      File.socket?(@name).should == true
    end
  end
end