File: exist.rb

package info (click to toggle)
ruby3.4 3.4.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 154,784 kB
  • sloc: ruby: 1,259,653; ansic: 829,955; yacc: 28,233; pascal: 7,359; sh: 3,864; python: 1,799; cpp: 1,158; asm: 808; makefile: 801; javascript: 414; lisp: 109; perl: 62; awk: 36; sed: 4; xml: 4
file content (57 lines) | stat: -rw-r--r-- 1,569 bytes parent folder | download | duplicates (3)
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
describe :dir_exist, shared: true do
  it "returns true if the given directory exists" do
    Dir.send(@method, __dir__).should be_true
  end

  it "returns true for '.'" do
    Dir.send(@method, '.').should be_true
  end

  it "returns true for '..'" do
    Dir.send(@method, '..').should be_true
  end

  it "understands non-ASCII paths" do
    subdir = File.join(tmp("\u{9876}\u{665}"))
    Dir.send(@method, subdir).should be_false
    Dir.mkdir(subdir)
    Dir.send(@method, subdir).should be_true
    Dir.rmdir(subdir)
  end

  it "understands relative paths" do
    Dir.send(@method, __dir__ + '/../').should be_true
  end

  it "returns false if the given directory doesn't exist" do
    Dir.send(@method, 'y26dg27n2nwjs8a/').should be_false
  end

  it "doesn't require the name to have a trailing slash" do
    dir = __dir__
    dir.sub!(/\/$/,'')
    Dir.send(@method, dir).should be_true
  end

  it "doesn't expand paths" do
    skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
    Dir.send(@method, File.expand_path('~')).should be_true
    Dir.send(@method, '~').should be_false
  end

  it "returns false if the argument exists but is a file" do
    File.should.exist?(__FILE__)
    Dir.send(@method, __FILE__).should be_false
  end

  it "doesn't set $! when file doesn't exist" do
    Dir.send(@method, "/path/to/non/existent/dir")
    $!.should be_nil
  end

  it "calls #to_path on non String arguments" do
    p = mock('path')
    p.should_receive(:to_path).and_return(__dir__)
    Dir.send(@method, p)
  end
end