Updated RubySpec source to d6754b35 except language/def_spec.rb.
[rbx.git] / spec / frozen / 1.8 / core / file / chown_spec.rb
blobd642dc918ee1cf0f6c8a8900ff797ff5f37fcef1
1 require File.dirname(__FILE__) + '/../../spec_helper'
3 as_superuser do
4   describe "File.chown" do
5     before :each do
6       @fname = tmp('file_chown_test')
7       File.open(@fname, 'w') { }
8     end
10     after :each do
11       File.delete @fname if File.exist? @fname
12     end
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
20       end
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
27       end
28     end
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
36       end
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
43       end
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
51       end
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
59       end
61       it "returns the number of files processed" do
62         File.chown(nil, nil, @fname, @fname).should == 2
63       end
64     end
65   end
67   describe "File#chown" do
68     before :each do
69       @fname = tmp('file_chown_test')
70       @file = File.open(@fname, 'w')
71     end
73     after :each do
74       @file.close unless @file.closed?
75       File.delete @fname if File.exist? @fname
76     end
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
84       end
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
91       end
92     end
94     platform_is_not :windows do
95       it "changes the owner id of the file" do
96         @file.chown 501, nil
97         @file.stat.uid.should == 501
98         @file.chown 0, nil
99         @file.stat.uid.should == 0
100       end
102       it "changes the group id of the file" do
103         @file.chown nil, 501
104         @file.stat.gid.should == 501
105         @file.chown nil, 0
106         @file.stat.uid.should == 0
107       end
109       it "does not modify the owner id of the file if passed nil or -1" do
110         @file.chown 501, nil
111         @file.chown nil, nil
112         @file.stat.uid.should == 501
113         @file.chown nil, -1
114         @file.stat.uid.should == 501
115       end
117       it "does not modify the group id of the file if passed nil or -1" do
118         @file.chown nil, 501
119         @file.chown nil, nil
120         @file.stat.gid.should == 501
121         @file.chown nil, -1
122         @file.stat.gid.should == 501
123       end
124     end
126     it "returns 0" do
127       @file.chown(nil, nil).should == 0
128     end
129   end