summaryrefslogtreecommitdiff
path: root/spec/ruby/core/dir
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/dir')
-rw-r--r--spec/ruby/core/dir/delete_spec.rb53
-rw-r--r--spec/ruby/core/dir/path_spec.rb34
-rw-r--r--spec/ruby/core/dir/pos_spec.rb36
-rw-r--r--spec/ruby/core/dir/rmdir_spec.rb12
-rw-r--r--spec/ruby/core/dir/shared/delete.rb53
-rw-r--r--spec/ruby/core/dir/tell_spec.rb36
-rw-r--r--spec/ruby/core/dir/to_path_spec.rb34
-rw-r--r--spec/ruby/core/dir/unlink_spec.rb12
8 files changed, 125 insertions, 145 deletions
diff --git a/spec/ruby/core/dir/delete_spec.rb b/spec/ruby/core/dir/delete_spec.rb
index a0020788ca..2dbd461c94 100644
--- a/spec/ruby/core/dir/delete_spec.rb
+++ b/spec/ruby/core/dir/delete_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
-require_relative 'shared/delete'
describe "Dir.delete" do
before :all do
@@ -11,5 +10,55 @@ describe "Dir.delete" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like :dir_delete, :delete
+ before :each do
+ DirSpecs.rmdir_dirs true
+ end
+
+ after :each do
+ DirSpecs.rmdir_dirs false
+ end
+
+ it "removes empty directories" do
+ Dir.delete(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.delete(p)
+ end
+
+ it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
+ -> do
+ Dir.delete DirSpecs.mock_rmdir("nonempty")
+ end.should.raise(Errno::ENOTEMPTY)
+ end
+
+ it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
+ -> do
+ Dir.delete DirSpecs.nonexistent
+ end.should.raise(Errno::ENOENT)
+ end
+
+ it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
+ file = DirSpecs.mock_rmdir("nonempty/regular")
+ touch(file)
+ -> do
+ Dir.delete file
+ end.should.raise(Errno::ENOTDIR)
+ end
+
+ # this won't work on Windows, since chmod(0000) does not remove all permissions
+ platform_is_not :windows do
+ as_user 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)
+ -> do
+ Dir.delete child
+ end.should.raise(Errno::EACCES)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/dir/path_spec.rb b/spec/ruby/core/dir/path_spec.rb
index 02ddd2cd42..e506db1222 100644
--- a/spec/ruby/core/dir/path_spec.rb
+++ b/spec/ruby/core/dir/path_spec.rb
@@ -1,37 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/common'
describe "Dir#path" do
- before :all do
- DirSpecs.create_mock_dirs
- end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it "returns the path that was supplied to .new or .open" do
- dir = Dir.open DirSpecs.mock_dir
- begin
- dir.path.should == DirSpecs.mock_dir
- ensure
- dir.close rescue nil
- end
- end
-
- it "returns the path even when called on a closed Dir instance" do
- dir = Dir.open DirSpecs.mock_dir
- dir.close
- dir.path.should == DirSpecs.mock_dir
- end
-
- it "returns a String with the same encoding as the argument to .open" do
- path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
- dir = Dir.open path
- begin
- dir.path.encoding.should.equal?(Encoding::IBM866)
- ensure
- dir.close
- end
+ it "is an alias of Dir#to_path" do
+ Dir.instance_method(:path).should == Dir.instance_method(:to_path)
end
end
diff --git a/spec/ruby/core/dir/pos_spec.rb b/spec/ruby/core/dir/pos_spec.rb
index f8ca06d778..1e364fbe3c 100644
--- a/spec/ruby/core/dir/pos_spec.rb
+++ b/spec/ruby/core/dir/pos_spec.rb
@@ -1,10 +1,42 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
+require_relative 'shared/closed'
require_relative 'shared/pos'
describe "Dir#pos" do
- it "is an alias of Dir#tell" do
- Dir.instance_method(:pos).should == Dir.instance_method(:tell)
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ it_behaves_like :dir_closed, :pos
+
+ before :each do
+ @dir = Dir.open DirSpecs.mock_dir
+ end
+
+ after :each do
+ @dir.close rescue nil
+ end
+
+ it "returns an Integer representing the current position in the directory" do
+ @dir.pos.should.is_a?(Integer)
+ @dir.pos.should.is_a?(Integer)
+ @dir.pos.should.is_a?(Integer)
+ end
+
+ it "returns a different Integer if moved from previous position" do
+ a = @dir.pos
+ @dir.read
+ b = @dir.pos
+
+ a.should.is_a?(Integer)
+ b.should.is_a?(Integer)
+
+ a.should_not == b
end
end
diff --git a/spec/ruby/core/dir/rmdir_spec.rb b/spec/ruby/core/dir/rmdir_spec.rb
index 08cd1a5bc6..c31067ca29 100644
--- a/spec/ruby/core/dir/rmdir_spec.rb
+++ b/spec/ruby/core/dir/rmdir_spec.rb
@@ -1,15 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/common'
-require_relative 'shared/delete'
describe "Dir.rmdir" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir.delete" do
+ Dir.method(:rmdir).should == Dir.method(:delete)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_delete, :rmdir
end
diff --git a/spec/ruby/core/dir/shared/delete.rb b/spec/ruby/core/dir/shared/delete.rb
deleted file mode 100644
index ba013e8615..0000000000
--- a/spec/ruby/core/dir/shared/delete.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-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
-
- it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
- -> do
- Dir.send @method, DirSpecs.mock_rmdir("nonempty")
- end.should.raise(Errno::ENOTEMPTY)
- end
-
- it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
- -> do
- Dir.send @method, DirSpecs.nonexistent
- end.should.raise(Errno::ENOENT)
- end
-
- it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
- file = DirSpecs.mock_rmdir("nonempty/regular")
- touch(file)
- -> do
- Dir.send @method, file
- end.should.raise(Errno::ENOTDIR)
- end
-
- # this won't work on Windows, since chmod(0000) does not remove all permissions
- platform_is_not :windows do
- as_user 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)
- -> do
- Dir.send @method, child
- end.should.raise(Errno::EACCES)
- end
- end
- end
-end
diff --git a/spec/ruby/core/dir/tell_spec.rb b/spec/ruby/core/dir/tell_spec.rb
index dcbb40438f..04f92a8ade 100644
--- a/spec/ruby/core/dir/tell_spec.rb
+++ b/spec/ruby/core/dir/tell_spec.rb
@@ -1,41 +1,9 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
-require_relative 'shared/closed'
require_relative 'shared/pos'
describe "Dir#tell" do
- before :all do
- DirSpecs.create_mock_dirs
- end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_closed, :tell
-
- before :each do
- @dir = Dir.open DirSpecs.mock_dir
- end
-
- after :each do
- @dir.close rescue nil
- end
-
- it "returns an Integer representing the current position in the directory" do
- @dir.tell.should.is_a?(Integer)
- @dir.tell.should.is_a?(Integer)
- @dir.tell.should.is_a?(Integer)
- end
-
- it "returns a different Integer if moved from previous position" do
- a = @dir.tell
- @dir.read
- b = @dir.tell
-
- a.should.is_a?(Integer)
- b.should.is_a?(Integer)
-
- a.should_not == b
+ it "is an alias of Dir#pos" do
+ Dir.instance_method(:tell).should == Dir.instance_method(:pos)
end
end
diff --git a/spec/ruby/core/dir/to_path_spec.rb b/spec/ruby/core/dir/to_path_spec.rb
index 2ed533e757..43e349c50e 100644
--- a/spec/ruby/core/dir/to_path_spec.rb
+++ b/spec/ruby/core/dir/to_path_spec.rb
@@ -1,7 +1,37 @@
require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir#to_path" do
- it "is an alias of Dir#path" do
- Dir.instance_method(:to_path).should == Dir.instance_method(:path)
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ it "returns the to_path that was supplied to .new or .open" do
+ dir = Dir.open DirSpecs.mock_dir
+ begin
+ dir.to_path.should == DirSpecs.mock_dir
+ ensure
+ dir.close rescue nil
+ end
+ end
+
+ it "returns the to_path even when called on a closed Dir instance" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir.close
+ dir.to_path.should == DirSpecs.mock_dir
+ end
+
+ it "returns a String with the same encoding as the argument to .open" do
+ to_path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
+ dir = Dir.open to_path
+ begin
+ dir.to_path.encoding.should.equal?(Encoding::IBM866)
+ ensure
+ dir.close
+ end
end
end
diff --git a/spec/ruby/core/dir/unlink_spec.rb b/spec/ruby/core/dir/unlink_spec.rb
index 79027e020c..d9cd1b1a87 100644
--- a/spec/ruby/core/dir/unlink_spec.rb
+++ b/spec/ruby/core/dir/unlink_spec.rb
@@ -1,15 +1,7 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/common'
-require_relative 'shared/delete'
describe "Dir.unlink" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir.delete" do
+ Dir.method(:unlink).should == Dir.method(:delete)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_delete, :unlink
end