1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/rubyspec/core/dir/shared/delete.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

59 lines
1.7 KiB
Ruby

describe :dir_delete, shared: true do
before :each do
DirSpecs.rmdir_dirs true
end
after :each do
DirSpecs.rmdir_dirs false
end
it "removes empty directories" do
Dir.send(@method, DirSpecs.mock_rmdir("empty")).should == 0
end
it "calls #to_path on non-String arguments" do
p = mock('path')
p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty"))
Dir.send(@method, p)
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