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/chdir_spec.rb144
-rw-r--r--spec/ruby/core/dir/close_spec.rb2
-rw-r--r--spec/ruby/core/dir/fchdir_spec.rb108
-rw-r--r--spec/ruby/core/dir/for_fd_spec.rb110
4 files changed, 179 insertions, 185 deletions
diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb
index 015386a902..fd277e4e1d 100644
--- a/spec/ruby/core/dir/chdir_spec.rb
+++ b/spec/ruby/core/dir/chdir_spec.rb
@@ -125,96 +125,94 @@ describe "Dir.chdir" do
end
end
-ruby_version_is '3.3' do
- describe "Dir#chdir" do
- before :all do
- DirSpecs.create_mock_dirs
- end
+describe "Dir#chdir" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
- after :all do
- DirSpecs.delete_mock_dirs
- end
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
- before :each do
- @original = Dir.pwd
- end
+ before :each do
+ @original = Dir.pwd
+ end
- after :each do
- Dir.chdir(@original)
- end
+ after :each do
+ Dir.chdir(@original)
+ end
- it "changes the current working directory to self" do
- dir = Dir.new(DirSpecs.mock_dir)
- dir.chdir
- Dir.pwd.should == DirSpecs.mock_dir
- ensure
- dir.close
- end
+ it "changes the current working directory to self" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir
+ Dir.pwd.should == DirSpecs.mock_dir
+ ensure
+ dir.close
+ end
- it "changes the current working directory to self for duration of the block when a block is given" do
- dir = Dir.new(DirSpecs.mock_dir)
- pwd_in_block = nil
+ it "changes the current working directory to self for duration of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ pwd_in_block = nil
- dir.chdir { pwd_in_block = Dir.pwd }
+ dir.chdir { pwd_in_block = Dir.pwd }
- pwd_in_block.should == DirSpecs.mock_dir
- Dir.pwd.should == @original
- ensure
- dir.close
- end
+ pwd_in_block.should == DirSpecs.mock_dir
+ Dir.pwd.should == @original
+ ensure
+ dir.close
+ end
- it "returns 0 when successfully changing directory" do
- dir = Dir.new(DirSpecs.mock_dir)
- dir.chdir.should == 0
- ensure
- dir.close
- end
+ it "returns 0 when successfully changing directory" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir.should == 0
+ ensure
+ dir.close
+ end
- it "returns the value of the block when a block is given" do
- dir = Dir.new(DirSpecs.mock_dir)
- dir.chdir { :block_value }.should == :block_value
- ensure
- dir.close
- end
+ it "returns the value of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir { :block_value }.should == :block_value
+ ensure
+ dir.close
+ end
+
+ platform_is_not :windows do
+ it "does not raise an Errno::ENOENT if the original directory no longer exists" do
+ dir_name1 = tmp('testdir1')
+ dir_name2 = tmp('testdir2')
+ Dir.should_not.exist?(dir_name1)
+ Dir.should_not.exist?(dir_name2)
+ Dir.mkdir dir_name1
+ Dir.mkdir dir_name2
- platform_is_not :windows do
- it "does not raise an Errno::ENOENT if the original directory no longer exists" do
- dir_name1 = tmp('testdir1')
- dir_name2 = tmp('testdir2')
- Dir.should_not.exist?(dir_name1)
- Dir.should_not.exist?(dir_name2)
- Dir.mkdir dir_name1
- Dir.mkdir dir_name2
-
- dir2 = Dir.new(dir_name2)
-
- begin
- Dir.chdir(dir_name1) do
- dir2.chdir { Dir.unlink dir_name1 }
- end
- Dir.pwd.should == @original
- ensure
- Dir.unlink dir_name1 if Dir.exist?(dir_name1)
- Dir.unlink dir_name2 if Dir.exist?(dir_name2)
+ dir2 = Dir.new(dir_name2)
+
+ begin
+ Dir.chdir(dir_name1) do
+ dir2.chdir { Dir.unlink dir_name1 }
end
+ Dir.pwd.should == @original
ensure
- dir2.close
+ Dir.unlink dir_name1 if Dir.exist?(dir_name1)
+ Dir.unlink dir_name2 if Dir.exist?(dir_name2)
end
+ ensure
+ dir2.close
end
+ end
- it "always returns to the original directory when given a block" do
- dir = Dir.new(DirSpecs.mock_dir)
+ it "always returns to the original directory when given a block" do
+ dir = Dir.new(DirSpecs.mock_dir)
- begin
- dir.chdir do
- raise StandardError, "something bad happened"
- end
- rescue StandardError
+ begin
+ dir.chdir do
+ raise StandardError, "something bad happened"
end
-
- Dir.pwd.should == @original
- ensure
- dir.close
+ rescue StandardError
end
+
+ Dir.pwd.should == @original
+ ensure
+ dir.close
end
end
diff --git a/spec/ruby/core/dir/close_spec.rb b/spec/ruby/core/dir/close_spec.rb
index f7cce318b8..10ad1369c8 100644
--- a/spec/ruby/core/dir/close_spec.rb
+++ b/spec/ruby/core/dir/close_spec.rb
@@ -24,7 +24,7 @@ describe "Dir#close" do
dir.close.should == nil
end
- ruby_version_is '3.3'...'3.4' do
+ ruby_version_is ''...'3.4' do
platform_is_not :windows do
it "does not raise an error even if the file descriptor is closed with another Dir instance" do
dir = Dir.open DirSpecs.mock_dir
diff --git a/spec/ruby/core/dir/fchdir_spec.rb b/spec/ruby/core/dir/fchdir_spec.rb
index 52600a95f2..d5e77f7f03 100644
--- a/spec/ruby/core/dir/fchdir_spec.rb
+++ b/spec/ruby/core/dir/fchdir_spec.rb
@@ -1,73 +1,71 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
-ruby_version_is '3.3' do
- platform_is_not :windows do
- describe "Dir.fchdir" do
- before :all do
- DirSpecs.create_mock_dirs
- end
+platform_is_not :windows do
+ describe "Dir.fchdir" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
- after :all do
- DirSpecs.delete_mock_dirs
- end
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
- before :each do
- @original = Dir.pwd
- end
+ before :each do
+ @original = Dir.pwd
+ end
- after :each do
- Dir.chdir(@original)
- end
+ after :each do
+ Dir.chdir(@original)
+ end
- it "changes the current working directory to the directory specified by the integer file descriptor" do
- dir = Dir.new(DirSpecs.mock_dir)
- Dir.fchdir dir.fileno
- Dir.pwd.should == DirSpecs.mock_dir
- ensure
- dir.close
- end
+ it "changes the current working directory to the directory specified by the integer file descriptor" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir dir.fileno
+ Dir.pwd.should == DirSpecs.mock_dir
+ ensure
+ dir.close
+ end
- it "returns 0 when successfully changing directory" do
- dir = Dir.new(DirSpecs.mock_dir)
- Dir.fchdir(dir.fileno).should == 0
- ensure
- dir.close
- end
+ it "returns 0 when successfully changing directory" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno).should == 0
+ ensure
+ dir.close
+ end
- it "returns the value of the block when a block is given" do
- dir = Dir.new(DirSpecs.mock_dir)
- Dir.fchdir(dir.fileno) { :block_value }.should == :block_value
- ensure
- dir.close
- end
+ it "returns the value of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno) { :block_value }.should == :block_value
+ ensure
+ dir.close
+ end
- it "changes to the specified directory for the duration of the block" do
- dir = Dir.new(DirSpecs.mock_dir)
- Dir.fchdir(dir.fileno) { Dir.pwd }.should == DirSpecs.mock_dir
- Dir.pwd.should == @original
- ensure
- dir.close
- end
+ it "changes to the specified directory for the duration of the block" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno) { Dir.pwd }.should == DirSpecs.mock_dir
+ Dir.pwd.should == @original
+ ensure
+ dir.close
+ end
- it "raises a SystemCallError if the file descriptor given is not valid" do
- -> { Dir.fchdir(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fchdir")
- -> { Dir.fchdir(-1) { } }.should raise_error(SystemCallError, "Bad file descriptor - fchdir")
- end
+ it "raises a SystemCallError if the file descriptor given is not valid" do
+ -> { Dir.fchdir(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fchdir")
+ -> { Dir.fchdir(-1) { } }.should raise_error(SystemCallError, "Bad file descriptor - fchdir")
+ end
- it "raises a SystemCallError if the file descriptor given is not for a directory" do
- -> { Dir.fchdir $stdout.fileno }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
- -> { Dir.fchdir($stdout.fileno) { } }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
- end
+ it "raises a SystemCallError if the file descriptor given is not for a directory" do
+ -> { Dir.fchdir $stdout.fileno }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
+ -> { Dir.fchdir($stdout.fileno) { } }.should raise_error(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
end
end
+end
- platform_is :windows do
- describe "Dir.fchdir" do
- it "raises NotImplementedError" do
- -> { Dir.fchdir 1 }.should raise_error(NotImplementedError)
- -> { Dir.fchdir(1) { } }.should raise_error(NotImplementedError)
- end
+platform_is :windows do
+ describe "Dir.fchdir" do
+ it "raises NotImplementedError" do
+ -> { Dir.fchdir 1 }.should raise_error(NotImplementedError)
+ -> { Dir.fchdir(1) { } }.should raise_error(NotImplementedError)
end
end
end
diff --git a/spec/ruby/core/dir/for_fd_spec.rb b/spec/ruby/core/dir/for_fd_spec.rb
index ba467f2f86..1559e1baa4 100644
--- a/spec/ruby/core/dir/for_fd_spec.rb
+++ b/spec/ruby/core/dir/for_fd_spec.rb
@@ -2,77 +2,75 @@ require_relative '../../spec_helper'
require_relative 'fixtures/common'
quarantine! do # leads to "Errno::EBADF: Bad file descriptor - closedir" in DirSpecs.delete_mock_dirs
-ruby_version_is '3.3' do
- platform_is_not :windows do
- describe "Dir.for_fd" do
- before :all do
- DirSpecs.create_mock_dirs
- end
+platform_is_not :windows do
+ describe "Dir.for_fd" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
- after :all do
- DirSpecs.delete_mock_dirs
- end
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
- before :each do
- @original = Dir.pwd
- end
+ before :each do
+ @original = Dir.pwd
+ end
- after :each do
- Dir.chdir(@original)
- end
+ after :each do
+ Dir.chdir(@original)
+ end
- it "returns a new Dir object representing the directory specified by the given integer directory file descriptor" do
- dir = Dir.new(DirSpecs.mock_dir)
- dir_new = Dir.for_fd(dir.fileno)
+ it "returns a new Dir object representing the directory specified by the given integer directory file descriptor" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir_new = Dir.for_fd(dir.fileno)
- dir_new.should.instance_of?(Dir)
- dir_new.children.should == dir.children
- dir_new.fileno.should == dir.fileno
- ensure
- dir.close
- end
+ dir_new.should.instance_of?(Dir)
+ dir_new.children.should == dir.children
+ dir_new.fileno.should == dir.fileno
+ ensure
+ dir.close
+ end
- it "returns a new Dir object without associated path" do
- dir = Dir.new(DirSpecs.mock_dir)
- dir_new = Dir.for_fd(dir.fileno)
+ it "returns a new Dir object without associated path" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir_new = Dir.for_fd(dir.fileno)
- dir_new.path.should == nil
- ensure
- dir.close
- end
+ dir_new.path.should == nil
+ ensure
+ dir.close
+ end
- it "calls #to_int to convert a value to an Integer" do
- dir = Dir.new(DirSpecs.mock_dir)
- obj = mock("fd")
- obj.should_receive(:to_int).and_return(dir.fileno)
+ it "calls #to_int to convert a value to an Integer" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ obj = mock("fd")
+ obj.should_receive(:to_int).and_return(dir.fileno)
- dir_new = Dir.for_fd(obj)
- dir_new.fileno.should == dir.fileno
- ensure
- dir.close
- end
+ dir_new = Dir.for_fd(obj)
+ dir_new.fileno.should == dir.fileno
+ ensure
+ dir.close
+ end
- it "raises TypeError when value cannot be converted to Integer" do
- -> {
- Dir.for_fd(nil)
- }.should raise_error(TypeError, "no implicit conversion from nil to integer")
- end
+ it "raises TypeError when value cannot be converted to Integer" do
+ -> {
+ Dir.for_fd(nil)
+ }.should raise_error(TypeError, "no implicit conversion from nil to integer")
+ end
- it "raises a SystemCallError if the file descriptor given is not valid" do
- -> { Dir.for_fd(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fdopendir")
- end
+ it "raises a SystemCallError if the file descriptor given is not valid" do
+ -> { Dir.for_fd(-1) }.should raise_error(SystemCallError, "Bad file descriptor - fdopendir")
+ end
- it "raises a SystemCallError if the file descriptor given is not for a directory" do
- -> { Dir.for_fd $stdout.fileno }.should raise_error(SystemCallError, "Not a directory - fdopendir")
- end
+ it "raises a SystemCallError if the file descriptor given is not for a directory" do
+ -> { Dir.for_fd $stdout.fileno }.should raise_error(SystemCallError, "Not a directory - fdopendir")
end
end
+end
- platform_is :windows do
- describe "Dir.for_fd" do
- it "raises NotImplementedError" do
- -> { Dir.for_fd 1 }.should raise_error(NotImplementedError)
- end
+platform_is :windows do
+ describe "Dir.for_fd" do
+ it "raises NotImplementedError" do
+ -> { Dir.for_fd 1 }.should raise_error(NotImplementedError)
end
end
end