File: delete.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (71 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
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
65
66
67
68
69
70
71
describe :dir_delete, :shared => true do
  before :all do
    DirSpecs.rmdir_dirs
  end

  after :all do
    DirSpecs.rmdir_dirs false
  end

  it "removes empty directories" do
    Dir.send(@method, DirSpecs.mock_rmdir("empty")).should == 0
  end

  ruby_version_is "1.9" do
    it "calls #to_path on non-String arguments" do
      DirSpecs.rmdir_dirs
      p = mock('path')
      p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty"))
      Dir.send(@method, p)
    end
  end

  ruby_version_is ""..."1.9" do
    it "calls #to_str on non-String arguments" do
      DirSpecs.rmdir_dirs
      p = mock('path')
      p.should_receive(:to_str).and_return(DirSpecs.mock_rmdir("empty"))
      Dir.send(@method, p)
    end
  end

  platform_is_not :solaris do
    it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
      lambda do
        Dir.send @method, DirSpecs.mock_rmdir("nonempty")
      end.should raise_error(Errno::ENOTEMPTY)
    end
  end

  platform_is :solaris do
    it "raises an Errno::EEXIST when trying to remove a nonempty directory" do
      lambda do
        Dir.send @method, DirSpecs.mock_rmdir("nonempty")
      end.should raise_error(Errno::EEXIST)
    end
  end

  it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
    lambda do
      Dir.send @method, DirSpecs.nonexistent
    end.should raise_error(Errno::ENOENT)
  end

  it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
    lambda do
      Dir.send @method, __FILE__
    end.should raise_error(Errno::ENOTDIR)
  end

  # this won't work on Windows, since chmod(0000) does not remove all permissions
  platform_is_not :windows do
    it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
      parent = DirSpecs.mock_rmdir("noperm")
      child = DirSpecs.mock_rmdir("noperm", "child")
      File.chmod(0000, parent)
      lambda do
        Dir.send @method, child
      end.should raise_error(Errno::EACCES)
    end
  end
end