1 require File.dirname(__FILE__) + '/../../spec_helper'
4 describe "File.chown" do
6 @fname = tmp('file_chown_test')
7 File.open(@fname, 'w') { }
11 File.delete @fname if File.exist? @fname
14 platform_is :windows do
15 it "does not modify the owner id of the file" do
16 File.chown 0, nil, @fname
17 File.stat(@fname).uid.should == 0
18 File.chown 501, nil, @fname
19 File.stat(@fname).uid.should == 0
22 it "does not modify the group id of the file" do
23 File.chown nil, 0, @fname
24 File.stat(@fname).gid.should == 0
25 File.chown nil, 501, @fname
26 File.stat(@fname).gid.should == 0
30 platform_is_not :windows do
31 it "changes the owner id of the file" do
32 File.chown 501, nil, @fname
33 File.stat(@fname).uid.should == 501
34 File.chown 0, nil, @fname
35 File.stat(@fname).uid.should == 0
38 it "changes the group id of the file" do
39 File.chown nil, 501, @fname
40 File.stat(@fname).gid.should == 501
41 File.chown nil, 0, @fname
42 File.stat(@fname).uid.should == 0
45 it "does not modify the owner id of the file if passed nil or -1" do
46 File.chown 501, nil, @fname
47 File.chown nil, nil, @fname
48 File.stat(@fname).uid.should == 501
49 File.chown nil, -1, @fname
50 File.stat(@fname).uid.should == 501
53 it "does not modify the group id of the file if passed nil or -1" do
54 File.chown nil, 501, @fname
55 File.chown nil, nil, @fname
56 File.stat(@fname).gid.should == 501
57 File.chown nil, -1, @fname
58 File.stat(@fname).gid.should == 501
61 it "returns the number of files processed" do
62 File.chown(nil, nil, @fname, @fname).should == 2
67 describe "File#chown" do
69 @fname = tmp('file_chown_test')
70 @file = File.open(@fname, 'w')
74 @file.close unless @file.closed?
75 File.delete @fname if File.exist? @fname
78 platform_is :windows do
79 it "does not modify the owner id of the file" do
80 File.chown 0, nil, @fname
81 File.stat(@fname).uid.should == 0
82 File.chown 501, nil, @fname
83 File.stat(@fname).uid.should == 0
86 it "does not modify the group id of the file" do
87 File.chown nil, 0, @fname
88 File.stat(@fname).gid.should == 0
89 File.chown nil, 501, @fname
90 File.stat(@fname).gid.should == 0
94 platform_is_not :windows do
95 it "changes the owner id of the file" do
97 @file.stat.uid.should == 501
99 @file.stat.uid.should == 0
102 it "changes the group id of the file" do
104 @file.stat.gid.should == 501
106 @file.stat.uid.should == 0
109 it "does not modify the owner id of the file if passed nil or -1" do
112 @file.stat.uid.should == 501
114 @file.stat.uid.should == 501
117 it "does not modify the group id of the file if passed nil or -1" do
120 @file.stat.gid.should == 501
122 @file.stat.gid.should == 501
127 @file.chown(nil, nil).should == 0