Module: Dir::MakeDirs::Etest

Defined in:
lib/vex/base/filesystem/make_dirs.rb

Instance Method Summary collapse

Instance Method Details

#test_existsObject



65
66
67
68
69
70
# File 'lib/vex/base/filesystem/make_dirs.rb', line 65

def test_exists
  assert Dir.exists?(File.dirname(__FILE__))
  assert !Dir.exists?(__FILE__)
  assert !Dir.exists?(__FILE__ + ".unknown")
  assert !Dir.exists?(__FILE__ + ":invalid")
end

#test_mkdirsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vex/base/filesystem/make_dirs.rb', line 46

def test_mkdirs
  base = File.dirname(__FILE__) + "/dirtest"
  
  assert !Dir.exists?(base)
  Dir.mkdirs "#{base}/a/b/c"
  Dir.mkdirs "#{base}/a/b/.dot"
  assert Dir.exists?(base)
  assert Dir.exists?("#{base}/a/b/c")

  File.touch "#{base}/a/b/x.y"
  File.touch "#{base}/a/b/.x.y"
  File.touch "#{base}/a/b/..x.y"
  File.touch "#{base}/a/b/.dot/a"

  Dir.rmdirs("#{base}")
  assert !Dir.exists?(base)
  assert !Dir.exists?("#{base}/a/b/c")
end

#test_tmpdirObject



72
73
74
75
76
77
78
79
80
# File 'lib/vex/base/filesystem/make_dirs.rb', line 72

def test_tmpdir
  p = nil
  Dir.tmp do |pdir|
    p = pdir
  end
  
  assert p.starts_with?("#{App.tmpdir}/")
  assert_file_doesnt_exist p
end


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vex/base/filesystem/make_dirs.rb', line 82

def test_tmpdir_unlinks_on_raise
  p = nil
  assert_raise(RuntimeError) {  
    Dir.tmp do |pdir|
      p = pdir
      raise RuntimeError
    end
  }
  
  assert p.starts_with?("#{App.tmpdir}/")
  assert_file_doesnt_exist p
end