summaryrefslogtreecommitdiff
path: root/spec/ruby/core/file/stat/ftype_spec.rb
blob: eb892eae5fa634183625b0aa484f94f89e306237 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require_relative '../../../spec_helper'
require_relative '../fixtures/file_types'

describe "File::Stat#ftype" do
  before :all do
    FileSpecs.configure_types
  end

  it "returns a String" do
    FileSpecs.normal_file do |file|
      File.lstat(file).ftype.should be_kind_of(String)
    end
  end

  it "returns 'file' when the file is a file" do
    FileSpecs.normal_file do |file|
      File.lstat(file).ftype.should == 'file'
    end
  end

  it "returns 'directory' when the file is a dir" do
    FileSpecs.directory do |dir|
      File.lstat(dir).ftype.should == 'directory'
    end
  end

  platform_is_not :windows do
    it "returns 'characterSpecial' when the file is a char"  do
      FileSpecs.character_device do |char|
        File.lstat(char).ftype.should == 'characterSpecial'
      end
    end
  end

  platform_is_not :freebsd do  # FreeBSD does not have block devices
    with_block_device do
      it "returns 'blockSpecial' when the file is a block" do
        FileSpecs.block_device do |block|
          File.lstat(block).ftype.should == 'blockSpecial'
        end
      end
    end
  end

  platform_is_not :windows do
    it "returns 'link' when the file is a link" do
      FileSpecs.symlink do |link|
        File.lstat(link).ftype.should == 'link'
      end
    end

    it "returns fifo when the file is a fifo" do
      FileSpecs.fifo do |fifo|
        File.lstat(fifo).ftype.should == 'fifo'
      end
    end

    it "returns 'socket' when the file is a socket" do
      FileSpecs.socket do |socket|
        File.lstat(socket).ftype.should == 'socket'
      end
    end
  end
end