1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/spec] Temporary directories should be under the mock_dir

This commit is contained in:
Nobuyoshi Nakada 2020-04-29 14:38:03 +09:00
parent 56d6cfe88a
commit 32e7d9140e
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
4 changed files with 22 additions and 18 deletions

View file

@ -22,7 +22,7 @@ module DirSpecs
[0xe9].pack('U') [0xe9].pack('U')
].each do |dir| ].each do |dir|
begin begin
Dir.rmdir dir Dir.rmdir mock_dir(dir)
rescue rescue
end end
end end

View file

@ -13,29 +13,33 @@ describe "Dir.mkdir" do
it "creates the named directory with the given permissions" do it "creates the named directory with the given permissions" do
DirSpecs.clear_dirs DirSpecs.clear_dirs
nonexisting = DirSpecs.mock_dir('nonexisting')
default_perms = DirSpecs.mock_dir('default_perms')
reduced = DirSpecs.mock_dir('reduced')
begin begin
File.should_not.exist?('nonexisting') File.should_not.exist?(nonexisting)
Dir.mkdir 'nonexisting' Dir.mkdir nonexisting
File.should.exist?('nonexisting') File.should.exist?(nonexisting)
platform_is_not :windows do platform_is_not :windows do
Dir.mkdir 'default_perms' Dir.mkdir default_perms
a = File.stat('default_perms').mode a = File.stat(default_perms).mode
Dir.mkdir 'reduced', (a - 1) Dir.mkdir reduced, (a - 1)
File.stat('reduced').mode.should_not == a File.stat(reduced).mode.should_not == a
end end
platform_is :windows do platform_is :windows do
Dir.mkdir 'default_perms', 0666 Dir.mkdir default_perms, 0666
a = File.stat('default_perms').mode a = File.stat(default_perms).mode
Dir.mkdir 'reduced', 0444 Dir.mkdir reduced, 0444
File.stat('reduced').mode.should_not == a File.stat(reduced).mode.should_not == a
end end
Dir.mkdir('always_returns_0').should == 0 always_returns_0 = DirSpecs.mock_dir('always_returns_0')
Dir.mkdir(always_returns_0).should == 0
platform_is_not(:windows) do platform_is_not(:windows) do
File.chmod(0777, "nonexisting","default_perms","reduced","always_returns_0") File.chmod(0777, nonexisting, default_perms, reduced, always_returns_0)
end end
platform_is_not(:windows) do platform_is_not(:windows) do
File.chmod(0644, "nonexisting","default_perms","reduced","always_returns_0") File.chmod(0644, nonexisting, default_perms, reduced, always_returns_0)
end end
ensure ensure
DirSpecs.clear_dirs DirSpecs.clear_dirs
@ -45,7 +49,7 @@ describe "Dir.mkdir" do
it "calls #to_path on non-String arguments" do it "calls #to_path on non-String arguments" do
DirSpecs.clear_dirs DirSpecs.clear_dirs
p = mock('path') p = mock('path')
p.should_receive(:to_path).and_return('nonexisting') p.should_receive(:to_path).and_return(DirSpecs.mock_dir('nonexisting'))
Dir.mkdir(p) Dir.mkdir(p)
DirSpecs.clear_dirs DirSpecs.clear_dirs
end end

View file

@ -35,7 +35,7 @@ describe :file_world_readable, shared: true do
end end
it "returns a Fixnum if the file is a directory and chmod 644" do it "returns a Fixnum if the file is a directory and chmod 644" do
dir = rand().to_s + '-ww' dir = tmp(rand().to_s + '-ww')
Dir.mkdir(dir) Dir.mkdir(dir)
Dir.should.exist?(dir) Dir.should.exist?(dir)
File.chmod(0644, dir) File.chmod(0644, dir)

View file

@ -34,7 +34,7 @@ describe :file_world_writable, shared: true do
end end
it "returns a Fixnum if the file is a directory and chmod 777" do it "returns a Fixnum if the file is a directory and chmod 777" do
dir = rand().to_s + '-ww' dir = tmp(rand().to_s + '-ww')
Dir.mkdir(dir) Dir.mkdir(dir)
Dir.should.exist?(dir) Dir.should.exist?(dir)
File.chmod(0777, dir) File.chmod(0777, dir)