diff options
Diffstat (limited to 'spec/ruby/core/dir/chdir_spec.rb')
| -rw-r--r-- | spec/ruby/core/dir/chdir_spec.rb | 153 |
1 files changed, 76 insertions, 77 deletions
diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb index 69a8b40415..2dc598e2a9 100644 --- a/spec/ruby/core/dir/chdir_spec.rb +++ b/spec/ruby/core/dir/chdir_spec.rb @@ -90,15 +90,15 @@ describe "Dir.chdir" do end it "raises an Errno::ENOENT if the directory does not exist" do - -> { Dir.chdir DirSpecs.nonexistent }.should raise_error(Errno::ENOENT) - -> { Dir.chdir(DirSpecs.nonexistent) { } }.should raise_error(Errno::ENOENT) + -> { Dir.chdir DirSpecs.nonexistent }.should.raise(Errno::ENOENT) + -> { Dir.chdir(DirSpecs.nonexistent) { } }.should.raise(Errno::ENOENT) end it "raises an Errno::ENOENT if the original directory no longer exists" do - dir1 = tmp('/testdir1') - dir2 = tmp('/testdir2') - File.should_not.exist?(dir1) - File.should_not.exist?(dir2) + dir1 = tmp('testdir1') + dir2 = tmp('testdir2') + Dir.should_not.exist?(dir1) + Dir.should_not.exist?(dir2) Dir.mkdir dir1 Dir.mkdir dir2 begin @@ -106,10 +106,10 @@ describe "Dir.chdir" do Dir.chdir dir1 do Dir.chdir(dir2) { Dir.unlink dir1 } end - }.should raise_error(Errno::ENOENT) + }.should.raise(Errno::ENOENT) ensure - Dir.unlink dir1 if File.exist?(dir1) - Dir.unlink dir2 if File.exist?(dir2) + Dir.unlink dir1 if Dir.exist?(dir1) + Dir.unlink dir2 if Dir.exist?(dir2) end end @@ -125,95 +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 - - after :all do - DirSpecs.delete_mock_dirs - end +describe "Dir#chdir" do + before :all do + DirSpecs.create_mock_dirs + end - before :each do - @original = Dir.pwd - end + after :all do + DirSpecs.delete_mock_dirs + end - after :each do - Dir.chdir(@original) - end + before :each do + @original = Dir.pwd + 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 + after :each do + Dir.chdir(@original) + 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" do + dir = Dir.new(DirSpecs.mock_dir) + dir.chdir + Dir.pwd.should == DirSpecs.mock_dir + ensure + dir.close + end - dir.chdir { pwd_in_block = Dir.pwd } + 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 - pwd_in_block.should == DirSpecs.mock_dir - Dir.pwd.should == @original - ensure - dir.close - end + dir.chdir { pwd_in_block = Dir.pwd } - it "returns 0 when successfully changing directory" do - dir = Dir.new(DirSpecs.mock_dir) - dir.chdir.should == 0 - ensure - dir.close - end + pwd_in_block.should == DirSpecs.mock_dir + Dir.pwd.should == @original + 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 0 when successfully changing directory" do + dir = Dir.new(DirSpecs.mock_dir) + dir.chdir.should == 0 + ensure + dir.close + end - it "raises an Errno::ENOENT if the original directory no longer exists" do - dir_name1 = tmp('/testdir1') - dir_name2 = tmp('/testdir2') - File.should_not.exist?(dir_name1) - File.should_not.exist?(dir_name2) + 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 - dir1 = Dir.new(dir_name1) + dir2 = Dir.new(dir_name2) begin - -> { - dir1.chdir do - Dir.chdir(dir_name2) { Dir.unlink dir_name1 } - end - }.should raise_error(Errno::ENOENT) + Dir.chdir(dir_name1) do + dir2.chdir { Dir.unlink dir_name1 } + end + Dir.pwd.should == @original ensure - Dir.unlink dir_name1 if File.exist?(dir_name1) - Dir.unlink dir_name2 if File.exist?(dir_name2) + Dir.unlink dir_name1 if Dir.exist?(dir_name1) + Dir.unlink dir_name2 if Dir.exist?(dir_name2) end ensure - dir1.close + 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 |
