Skip to content

Commit

Permalink
Skip a new spec for Dir#chdir on Windows when original directory is r…
Browse files Browse the repository at this point in the history
…emoved

The following error is raised:

```
Dir#chdir does not raise an Errno::ENOENT if the original directory no longer exists ERROR
Errno::ENOENT: No such file or directory @ dir_chdir0 - D:/a/spec/spec/rubyspec_temp/5588_0/27-testdir1
D:/a/spec/spec/core/dir/chdir_spec.rb:192:in `chdir'
D:/a/spec/spec/core/dir/chdir_spec.rb:192:in `block (4 levels) in <top (required)>'
D:/a/spec/spec/core/dir/chdir_spec.rb:191:in `chdir'
D:/a/spec/spec/core/dir/chdir_spec.rb:191:in `block (3 levels) in <top (required)>'
D:/a/spec/spec/core/dir/chdir_spec.rb:129:in `block in <top (required)>'
D:/a/spec/spec/core/dir/chdir_spec.rb:128:in `<top (required)>'
```
  • Loading branch information
andrykonchin committed Jan 30, 2025
1 parent ccc72c7 commit cbbb3c8
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions core/dir/chdir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,29 @@ def to_str; DirSpecs.mock_dir; end
dir.close
end

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 }
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)
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.close
end
ensure
dir2.close
end

it "always returns to the original directory when given a block" do
Expand Down

0 comments on commit cbbb3c8

Please sign in to comment.