memfs 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +3 -2
- data/lib/memfs/dir.rb +2 -2
- data/lib/memfs/file_system.rb +4 -2
- data/lib/memfs/version.rb +1 -1
- data/spec/fileutils_spec.rb +229 -191
- data/spec/memfs/dir_spec.rb +109 -95
- data/spec/memfs/fake/directory_spec.rb +8 -8
- data/spec/memfs/fake/entry_spec.rb +3 -3
- data/spec/memfs/fake/file/content_spec.rb +3 -5
- data/spec/memfs/fake/symlink_spec.rb +11 -11
- data/spec/memfs/file/stat_spec.rb +14 -14
- data/spec/memfs/file_spec.rb +269 -269
- data/spec/memfs/file_system_spec.rb +12 -0
- data/spec/memfs_spec.rb +18 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d538c6d82cd4bab8b5771b26592034f441692420
|
4
|
+
data.tar.gz: ef508f4172de7d3ab3c263dc147f70648178b0a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96938d69ddeac5089c3524d7981d32f318df8dac36d60d74c79936588e1f6be79a3c17975c2f853fb604395115248329a269b9b86c0fbd2c3671523637f8e630
|
7
|
+
data.tar.gz: e7858942b018d861c17b6c15b680409f86e247b14242f38ffad7a7b89f5a17e8fa3fc1dfc1c09579e54fa706016f1169945ca28622c355c76556d480a1a4cf10
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -165,8 +165,9 @@ end
|
|
165
165
|
|
166
166
|
## Known issues
|
167
167
|
|
168
|
-
* MemFs doesn't implement IO so FileUtils.copy_stream
|
169
|
-
*
|
168
|
+
* MemFs doesn't implement IO so methods like `FileUtils.copy_stream` and `IO.write` are still the originals.
|
169
|
+
* Similarly, MemFs doesn't implement Kernel, so don't use a naked `open()` call. This uses the `Kernel` class via `method_missing`, which MemFs will not intercept.
|
170
|
+
* Pipes and Sockets are not handled for now.
|
170
171
|
|
171
172
|
## TODO
|
172
173
|
|
data/lib/memfs/dir.rb
CHANGED
data/lib/memfs/file_system.rb
CHANGED
@@ -96,9 +96,11 @@ module MemFs
|
|
96
96
|
find_parent!(new_name).add_entry link
|
97
97
|
end
|
98
98
|
|
99
|
-
def mkdir(path)
|
99
|
+
def mkdir(path, mode = 0777)
|
100
100
|
fail Errno::EEXIST, path if find(path)
|
101
|
-
|
101
|
+
directory = Fake::Directory.new(path)
|
102
|
+
directory.mode = mode
|
103
|
+
find_parent!(path).add_entry directory
|
102
104
|
end
|
103
105
|
|
104
106
|
def paths
|
data/lib/memfs/version.rb
CHANGED
data/spec/fileutils_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe FileUtils do
|
|
7
7
|
MemFs::File.umask(0020)
|
8
8
|
MemFs.activate!
|
9
9
|
|
10
|
-
|
10
|
+
described_class.mkdir '/test'
|
11
11
|
end
|
12
12
|
|
13
13
|
after :each do
|
@@ -16,100 +16,100 @@ describe FileUtils do
|
|
16
16
|
|
17
17
|
describe '.cd' do
|
18
18
|
it 'changes the current working directory' do
|
19
|
-
|
20
|
-
expect(
|
19
|
+
described_class.cd '/test'
|
20
|
+
expect(described_class.pwd).to eq('/test')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'returns nil' do
|
24
|
-
expect(
|
24
|
+
expect(described_class.cd('/test')).to be_nil
|
25
25
|
end
|
26
26
|
|
27
27
|
it "raises an error when the given path doesn't exist" do
|
28
|
-
expect {
|
28
|
+
expect { described_class.cd('/nowhere') }.to raise_specific_error(Errno::ENOENT)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'raises an error when the given path is not a directory' do
|
32
|
-
|
33
|
-
expect {
|
32
|
+
described_class.touch('/test-file')
|
33
|
+
expect { described_class.cd('/test-file') }.to raise_specific_error(Errno::ENOTDIR)
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'when called with a block' do
|
37
37
|
it 'changes current working directory for the block execution' do
|
38
|
-
|
39
|
-
expect(
|
38
|
+
described_class.cd '/test' do
|
39
|
+
expect(described_class.pwd).to eq('/test')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'resumes to the old working directory after the block execution finished' do
|
44
|
-
|
45
|
-
expect {
|
44
|
+
described_class.cd '/'
|
45
|
+
expect { described_class.cd('/test') {} }.to_not change { described_class.pwd }
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'when the destination is a symlink' do
|
50
50
|
before :each do
|
51
|
-
|
51
|
+
described_class.symlink('/test', '/test-link')
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'changes directory to the last target of the link chain' do
|
55
|
-
|
56
|
-
expect(
|
55
|
+
described_class.cd('/test-link')
|
56
|
+
expect(described_class.pwd).to eq('/test')
|
57
57
|
end
|
58
58
|
|
59
59
|
it "raises an error if the last target of the link chain doesn't exist" do
|
60
|
-
expect {
|
60
|
+
expect { described_class.cd('/nowhere-link') }.to raise_specific_error(Errno::ENOENT)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe '.chmod' do
|
66
66
|
it 'changes permission bits on the named file to the bit pattern represented by mode' do
|
67
|
-
|
68
|
-
|
67
|
+
described_class.touch '/test-file'
|
68
|
+
described_class.chmod 0777, '/test-file'
|
69
69
|
expect(File.stat('/test-file').mode).to eq(0100777)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'changes permission bits on the named files (in list) to the bit pattern represented by mode' do
|
73
|
-
|
74
|
-
|
73
|
+
described_class.touch ['/test-file', '/test-file2']
|
74
|
+
described_class.chmod 0777, ['/test-file', '/test-file2']
|
75
75
|
expect(File.stat('/test-file2').mode).to eq(0100777)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns an array containing the file names' do
|
79
79
|
file_names = %w[/test-file /test-file2]
|
80
|
-
|
81
|
-
expect(
|
80
|
+
described_class.touch file_names
|
81
|
+
expect(described_class.chmod(0777, file_names)).to eq(file_names)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'raises an error if an entry does not exist' do
|
85
|
-
expect {
|
85
|
+
expect { described_class.chmod(0777, '/test-file') }.to raise_specific_error(Errno::ENOENT)
|
86
86
|
end
|
87
87
|
|
88
88
|
context 'when the named file is a symlink' do
|
89
89
|
before :each do
|
90
|
-
|
91
|
-
|
90
|
+
described_class.touch '/test-file'
|
91
|
+
described_class.symlink '/test-file', '/test-link'
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'when File responds to lchmod' do
|
95
95
|
it 'changes the mode on the link' do
|
96
|
-
|
96
|
+
described_class.chmod(0777, '/test-link')
|
97
97
|
expect(File.lstat('/test-link').mode).to eq(0100777)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "doesn't change the mode of the link's target" do
|
101
101
|
mode = File.lstat('/test-file').mode
|
102
|
-
|
102
|
+
described_class.chmod(0777, '/test-link')
|
103
103
|
expect(File.lstat('/test-file').mode).to eq(mode)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
context "when File doesn't respond to lchmod" do
|
108
108
|
it 'does nothing' do
|
109
|
-
allow_any_instance_of(
|
109
|
+
allow_any_instance_of(described_class::Entry_).to \
|
110
110
|
receive_messages(have_lchmod?: false)
|
111
111
|
mode = File.lstat('/test-link').mode
|
112
|
-
|
112
|
+
described_class.chmod(0777, '/test-link')
|
113
113
|
expect(File.lstat('/test-link').mode).to eq(mode)
|
114
114
|
end
|
115
115
|
end
|
@@ -118,81 +118,81 @@ describe FileUtils do
|
|
118
118
|
|
119
119
|
describe '.chmod_R' do
|
120
120
|
before :each do
|
121
|
-
|
121
|
+
described_class.touch '/test/test-file'
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'changes the permission bits on the named entry' do
|
125
|
-
|
125
|
+
described_class.chmod_R(0777, '/test')
|
126
126
|
expect(File.stat('/test').mode).to eq(0100777)
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'changes the permission bits on any sub-directory of the named entry' do
|
130
|
-
|
130
|
+
described_class.chmod_R(0777, '/')
|
131
131
|
expect(File.stat('/test').mode).to eq(0100777)
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'changes the permission bits on any descendant file of the named entry' do
|
135
|
-
|
135
|
+
described_class.chmod_R(0777, '/')
|
136
136
|
expect(File.stat('/test/test-file').mode).to eq(0100777)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
describe '.chown' do
|
141
141
|
it 'changes owner on the named file' do
|
142
|
-
|
142
|
+
described_class.chown(42, nil, '/test')
|
143
143
|
expect(File.stat('/test').uid).to eq(42)
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'changes owner on the named files (in list)' do
|
147
|
-
|
148
|
-
|
147
|
+
described_class.touch('/test-file')
|
148
|
+
described_class.chown(42, nil, ['/test', '/test-file'])
|
149
149
|
expect(File.stat('/test-file').uid).to eq(42)
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'changes group on the named entry' do
|
153
|
-
|
153
|
+
described_class.chown(nil, 42, '/test')
|
154
154
|
expect(File.stat('/test').gid).to eq(42)
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'changes group on the named entries in list' do
|
158
|
-
|
159
|
-
|
158
|
+
described_class.touch('/test-file')
|
159
|
+
described_class.chown(nil, 42, ['/test', '/test-file'])
|
160
160
|
expect(File.stat('/test-file').gid).to eq(42)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "doesn't change user if user is nil" do
|
164
|
-
|
164
|
+
described_class.chown(nil, 42, '/test')
|
165
165
|
expect(File.stat('/test').uid).not_to be(42)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "doesn't change group if group is nil" do
|
169
|
-
|
169
|
+
described_class.chown(42, nil, '/test')
|
170
170
|
expect(File.stat('/test').gid).not_to be(42)
|
171
171
|
end
|
172
172
|
|
173
173
|
context 'when the name entry is a symlink' do
|
174
174
|
before :each do
|
175
|
-
|
176
|
-
|
175
|
+
described_class.touch '/test-file'
|
176
|
+
described_class.symlink '/test-file', '/test-link'
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'changes the owner on the last target of the link chain' do
|
180
|
-
|
180
|
+
described_class.chown(42, nil, '/test-link')
|
181
181
|
expect(File.stat('/test-file').uid).to eq(42)
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'changes the group on the last target of the link chain' do
|
185
|
-
|
185
|
+
described_class.chown(nil, 42, '/test-link')
|
186
186
|
expect(File.stat('/test-file').gid).to eq(42)
|
187
187
|
end
|
188
188
|
|
189
189
|
it "doesn't change the owner of the symlink" do
|
190
|
-
|
190
|
+
described_class.chown(42, nil, '/test-link')
|
191
191
|
expect(File.lstat('/test-link').uid).not_to be(42)
|
192
192
|
end
|
193
193
|
|
194
194
|
it "doesn't change the group of the symlink" do
|
195
|
-
|
195
|
+
described_class.chown(nil, 42, '/test-link')
|
196
196
|
expect(File.lstat('/test-link').gid).not_to be(42)
|
197
197
|
end
|
198
198
|
end
|
@@ -200,36 +200,36 @@ describe FileUtils do
|
|
200
200
|
|
201
201
|
describe '.chown_R' do
|
202
202
|
before :each do
|
203
|
-
|
203
|
+
described_class.touch '/test/test-file'
|
204
204
|
end
|
205
205
|
|
206
206
|
it 'changes the owner on the named entry' do
|
207
|
-
|
207
|
+
described_class.chown_R(42, nil, '/test')
|
208
208
|
expect(File.stat('/test').uid).to eq(42)
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'changes the group on the named entry' do
|
212
|
-
|
212
|
+
described_class.chown_R(nil, 42, '/test')
|
213
213
|
expect(File.stat('/test').gid).to eq(42)
|
214
214
|
end
|
215
215
|
|
216
216
|
it 'changes the owner on any sub-directory of the named entry' do
|
217
|
-
|
217
|
+
described_class.chown_R(42, nil, '/')
|
218
218
|
expect(File.stat('/test').uid).to eq(42)
|
219
219
|
end
|
220
220
|
|
221
221
|
it 'changes the group on any sub-directory of the named entry' do
|
222
|
-
|
222
|
+
described_class.chown_R(nil, 42, '/')
|
223
223
|
expect(File.stat('/test').gid).to eq(42)
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'changes the owner on any descendant file of the named entry' do
|
227
|
-
|
227
|
+
described_class.chown_R(42, nil, '/')
|
228
228
|
expect(File.stat('/test/test-file').uid).to eq(42)
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'changes the group on any descendant file of the named entry' do
|
232
|
-
|
232
|
+
described_class.chown_R(nil, 42, '/')
|
233
233
|
expect(File.stat('/test/test-file').gid).to eq(42)
|
234
234
|
end
|
235
235
|
end
|
@@ -243,14 +243,14 @@ describe FileUtils do
|
|
243
243
|
File.open('/test-file', 'w') { |f| f.puts 'this is a test' }
|
244
244
|
File.open('/test-file2', 'w') { |f| f.puts 'this is a test' }
|
245
245
|
|
246
|
-
expect(
|
246
|
+
expect(described_class.compare_file('/test-file', '/test-file2')).to be true
|
247
247
|
end
|
248
248
|
|
249
249
|
it 'returns false if the contents of a file A and a file B are not identical' do
|
250
250
|
File.open('/test-file', 'w') { |f| f.puts 'this is a test' }
|
251
251
|
File.open('/test-file2', 'w') { |f| f.puts 'this is not a test' }
|
252
252
|
|
253
|
-
expect(
|
253
|
+
expect(described_class.compare_file('/test-file', '/test-file2')).to be false
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
@@ -262,7 +262,7 @@ describe FileUtils do
|
|
262
262
|
file1 = File.open('/test-file')
|
263
263
|
file2 = File.open('/test-file2')
|
264
264
|
|
265
|
-
expect(
|
265
|
+
expect(described_class.compare_stream(file1, file2)).to be true
|
266
266
|
end
|
267
267
|
|
268
268
|
it 'returns false if the contents of a stream A and stream B are not identical' do
|
@@ -272,7 +272,7 @@ describe FileUtils do
|
|
272
272
|
file1 = File.open('/test-file')
|
273
273
|
file2 = File.open('/test-file2')
|
274
274
|
|
275
|
-
expect(
|
275
|
+
expect(described_class.compare_stream(file1, file2)).to be false
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
@@ -283,21 +283,21 @@ describe FileUtils do
|
|
283
283
|
describe '.copy_entry' do
|
284
284
|
it 'copies a file system entry +src+ to +dest+' do
|
285
285
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
286
|
-
|
286
|
+
described_class.copy_entry('/test-file', '/test-copy')
|
287
287
|
expect(File.read('/test-copy')).to eq("test\n")
|
288
288
|
end
|
289
289
|
|
290
290
|
it 'preserves file types' do
|
291
|
-
|
292
|
-
|
293
|
-
|
291
|
+
described_class.touch('/test-file')
|
292
|
+
described_class.symlink('/test-file', '/test-link')
|
293
|
+
described_class.copy_entry('/test-link', '/test-copy')
|
294
294
|
expect(File.symlink?('/test-copy')).to be true
|
295
295
|
end
|
296
296
|
|
297
297
|
context 'when +src+ does not exist' do
|
298
298
|
it 'raises an exception' do
|
299
299
|
expect {
|
300
|
-
|
300
|
+
described_class.copy_entry('/test-file', '/test-copy')
|
301
301
|
}.to raise_specific_error(RuntimeError)
|
302
302
|
end
|
303
303
|
end
|
@@ -306,11 +306,11 @@ describe FileUtils do
|
|
306
306
|
let(:time) { Date.parse('2013-01-01') }
|
307
307
|
|
308
308
|
before :each do
|
309
|
-
|
310
|
-
|
311
|
-
|
309
|
+
described_class.touch('/test-file')
|
310
|
+
described_class.chown(1042, 1042, '/test-file')
|
311
|
+
described_class.chmod(0777, '/test-file')
|
312
312
|
_fs.find('/test-file').mtime = time
|
313
|
-
|
313
|
+
described_class.copy_entry('/test-file', '/test-copy', true)
|
314
314
|
end
|
315
315
|
|
316
316
|
it 'preserves owner' do
|
@@ -333,24 +333,24 @@ describe FileUtils do
|
|
333
333
|
context 'when +dest+ already exists' do
|
334
334
|
it 'overwrite it' do
|
335
335
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
336
|
-
|
337
|
-
|
336
|
+
described_class.touch('/test-copy')
|
337
|
+
described_class.copy_entry('/test-file', '/test-copy')
|
338
338
|
expect(File.read('/test-copy')).to eq("test\n")
|
339
339
|
end
|
340
340
|
end
|
341
341
|
|
342
342
|
context 'when +remove_destination+ is true' do
|
343
343
|
it 'removes each destination file before copy' do
|
344
|
-
|
344
|
+
described_class.touch(['/test-file', '/test-copy'])
|
345
345
|
expect(File).to receive(:unlink).with('/test-copy')
|
346
|
-
|
346
|
+
described_class.copy_entry('/test-file', '/test-copy', false, false, true)
|
347
347
|
end
|
348
348
|
end
|
349
349
|
|
350
350
|
context 'when +src+ is a directory' do
|
351
351
|
it 'copies its contents recursively' do
|
352
|
-
|
353
|
-
|
352
|
+
described_class.mkdir_p('/test-dir/test-sub-dir')
|
353
|
+
described_class.copy_entry('/test-dir', '/test-copy')
|
354
354
|
expect(Dir.exist?('/test-copy/test-sub-dir')).to be true
|
355
355
|
end
|
356
356
|
end
|
@@ -359,7 +359,7 @@ describe FileUtils do
|
|
359
359
|
describe '.copy_file' do
|
360
360
|
it 'copies file contents of src to dest' do
|
361
361
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
362
|
-
|
362
|
+
described_class.copy_file('/test-file', '/test-file2')
|
363
363
|
expect(File.read('/test-file2')).to eq("test\n")
|
364
364
|
end
|
365
365
|
end
|
@@ -374,22 +374,22 @@ describe FileUtils do
|
|
374
374
|
end
|
375
375
|
|
376
376
|
it 'copies a file content +src+ to +dest+' do
|
377
|
-
|
377
|
+
described_class.cp('/test-file', '/copy-file')
|
378
378
|
expect(File.read('/copy-file')).to eq("test\n")
|
379
379
|
end
|
380
380
|
|
381
381
|
context 'when +src+ and +dest+ are the same file' do
|
382
382
|
it 'raises an error' do
|
383
383
|
expect {
|
384
|
-
|
384
|
+
described_class.cp('/test-file', '/test-file')
|
385
385
|
}.to raise_specific_error(ArgumentError)
|
386
386
|
end
|
387
387
|
end
|
388
388
|
|
389
389
|
context 'when +dest+ is a directory' do
|
390
390
|
it 'copies +src+ to +dest/src+' do
|
391
|
-
|
392
|
-
|
391
|
+
described_class.mkdir('/dest')
|
392
|
+
described_class.cp('/test-file', '/dest/copy-file')
|
393
393
|
expect(File.read('/dest/copy-file')).to eq("test\n")
|
394
394
|
end
|
395
395
|
end
|
@@ -397,9 +397,9 @@ describe FileUtils do
|
|
397
397
|
context 'when src is a list of files' do
|
398
398
|
context 'when +dest+ is not a directory' do
|
399
399
|
it 'raises an error' do
|
400
|
-
|
400
|
+
described_class.touch(['/dest', '/test-file2'])
|
401
401
|
expect {
|
402
|
-
|
402
|
+
described_class.cp(['/test-file', '/test-file2'], '/dest')
|
403
403
|
}.to raise_specific_error(Errno::ENOTDIR)
|
404
404
|
end
|
405
405
|
end
|
@@ -410,36 +410,36 @@ describe FileUtils do
|
|
410
410
|
it 'copies +src+ to +dest+' do
|
411
411
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
412
412
|
|
413
|
-
|
413
|
+
described_class.cp_r('/test-file', '/copy-file')
|
414
414
|
expect(File.read('/copy-file')).to eq("test\n")
|
415
415
|
end
|
416
416
|
|
417
417
|
context 'when +src+ is a directory' do
|
418
418
|
it 'copies all its contents recursively' do
|
419
|
-
|
420
|
-
|
419
|
+
described_class.mkdir('/test/dir')
|
420
|
+
described_class.touch('/test/dir/file')
|
421
421
|
|
422
|
-
|
422
|
+
described_class.cp_r('/test', '/dest')
|
423
423
|
expect(File.exist?('/dest/dir/file')).to be true
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
427
427
|
context 'when +dest+ is a directory' do
|
428
428
|
it 'copies +src+ to +dest/src+' do
|
429
|
-
|
430
|
-
|
429
|
+
described_class.mkdir(['/test/dir', '/dest'])
|
430
|
+
described_class.touch('/test/dir/file')
|
431
431
|
|
432
|
-
|
432
|
+
described_class.cp_r('/test', '/dest')
|
433
433
|
expect(File.exist?('/dest/test/dir/file')).to be true
|
434
434
|
end
|
435
435
|
end
|
436
436
|
|
437
437
|
context 'when +src+ is a list of files' do
|
438
438
|
it 'copies each of them in +dest+' do
|
439
|
-
|
440
|
-
|
439
|
+
described_class.mkdir(['/test/dir', '/test/dir2', '/dest'])
|
440
|
+
described_class.touch(['/test/dir/file', '/test/dir2/file'])
|
441
441
|
|
442
|
-
|
442
|
+
described_class.cp_r(['/test/dir', '/test/dir2'], '/dest')
|
443
443
|
expect(File.exist?('/dest/dir2/file')).to be true
|
444
444
|
end
|
445
445
|
end
|
@@ -459,21 +459,21 @@ describe FileUtils do
|
|
459
459
|
end
|
460
460
|
|
461
461
|
it 'copies +src+ to +dest+' do
|
462
|
-
|
462
|
+
described_class.install('/test-file', '/test-file2')
|
463
463
|
expect(File.read('/test-file2')).to eq("test\n")
|
464
464
|
end
|
465
465
|
|
466
466
|
context 'when +:mode+ is set' do
|
467
467
|
it 'changes the permission mode to +mode+' do
|
468
468
|
expect(File).to receive(:chmod).with(0777, '/test-file2')
|
469
|
-
|
469
|
+
described_class.install('/test-file', '/test-file2', mode: 0777)
|
470
470
|
end
|
471
471
|
end
|
472
472
|
|
473
473
|
context 'when +src+ and +dest+ are the same file' do
|
474
474
|
it 'raises an exception' do
|
475
475
|
expect {
|
476
|
-
|
476
|
+
described_class.install('/test-file', '/test-file')
|
477
477
|
}.to raise_exception(ArgumentError)
|
478
478
|
end
|
479
479
|
end
|
@@ -481,13 +481,13 @@ describe FileUtils do
|
|
481
481
|
context 'when +dest+ already exists' do
|
482
482
|
it 'removes destination before copy' do
|
483
483
|
expect(File).to receive(:unlink).with('/test-file2')
|
484
|
-
|
484
|
+
described_class.install('/test-file', '/test-file2')
|
485
485
|
end
|
486
486
|
|
487
487
|
context 'and +dest+ is a directory' do
|
488
488
|
it 'installs +src+ in dest/src' do
|
489
|
-
|
490
|
-
|
489
|
+
described_class.mkdir('/test-dir')
|
490
|
+
described_class.install('/test-file', '/test-dir')
|
491
491
|
expect(File.read('/test-dir/test-file')).to eq("test\n")
|
492
492
|
end
|
493
493
|
end
|
@@ -504,36 +504,36 @@ describe FileUtils do
|
|
504
504
|
end
|
505
505
|
|
506
506
|
it 'creates a hard link +dest+ which points to +src+' do
|
507
|
-
|
507
|
+
described_class.ln('/test-file', '/test-file2')
|
508
508
|
expect(File.read('/test-file2')).to eq(File.read('/test-file'))
|
509
509
|
end
|
510
510
|
|
511
511
|
it 'creates a hard link, not a symlink' do
|
512
|
-
|
512
|
+
described_class.ln('/test-file', '/test-file2')
|
513
513
|
expect(File.symlink?('/test-file2')).to be false
|
514
514
|
end
|
515
515
|
|
516
516
|
context 'when +dest+ already exists' do
|
517
517
|
context 'and is a directory' do
|
518
518
|
it 'creates a link dest/src' do
|
519
|
-
|
520
|
-
|
519
|
+
described_class.mkdir('/test-dir')
|
520
|
+
described_class.ln('/test-file', '/test-dir')
|
521
521
|
expect(File.read('/test-dir/test-file')).to eq(File.read('/test-file'))
|
522
522
|
end
|
523
523
|
end
|
524
524
|
|
525
525
|
context 'and it is not a directory' do
|
526
526
|
it 'raises an exception' do
|
527
|
-
|
527
|
+
described_class.touch('/test-file2')
|
528
528
|
expect {
|
529
|
-
|
529
|
+
described_class.ln('/test-file', '/test-file2')
|
530
530
|
}.to raise_specific_error(SystemCallError)
|
531
531
|
end
|
532
532
|
|
533
533
|
context 'and +:force+ is set' do
|
534
534
|
it 'overwrites +dest+' do
|
535
|
-
|
536
|
-
|
535
|
+
described_class.touch('/test-file2')
|
536
|
+
described_class.ln('/test-file', '/test-file2', force: true)
|
537
537
|
expect(File.read('/test-file2')).to eq(File.read('/test-file'))
|
538
538
|
end
|
539
539
|
end
|
@@ -542,16 +542,16 @@ describe FileUtils do
|
|
542
542
|
|
543
543
|
context 'when passing a list of paths' do
|
544
544
|
it 'creates a link for each path in +destdir+' do
|
545
|
-
|
546
|
-
|
547
|
-
|
545
|
+
described_class.touch('/test-file2')
|
546
|
+
described_class.mkdir('/test-dir')
|
547
|
+
described_class.ln(['/test-file', '/test-file2'], '/test-dir')
|
548
548
|
end
|
549
549
|
|
550
550
|
context 'and +destdir+ is not a directory' do
|
551
551
|
it 'raises an exception' do
|
552
|
-
|
552
|
+
described_class.touch(['/test-file2', '/not-a-dir'])
|
553
553
|
expect {
|
554
|
-
|
554
|
+
described_class.ln(['/test-file', '/test-file2'], '/not-a-dir')
|
555
555
|
}.to raise_specific_error(Errno::ENOTDIR)
|
556
556
|
end
|
557
557
|
end
|
@@ -561,24 +561,24 @@ describe FileUtils do
|
|
561
561
|
describe '.ln_s' do
|
562
562
|
before :each do
|
563
563
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
564
|
-
|
565
|
-
|
564
|
+
described_class.touch('/not-a-dir')
|
565
|
+
described_class.mkdir('/test-dir')
|
566
566
|
end
|
567
567
|
|
568
568
|
it 'creates a symbolic link +new+' do
|
569
|
-
|
569
|
+
described_class.ln_s('/test-file', '/test-link')
|
570
570
|
expect(File.symlink?('/test-link')).to be true
|
571
571
|
end
|
572
572
|
|
573
573
|
it 'creates a symbolic link which points to +old+' do
|
574
|
-
|
574
|
+
described_class.ln_s('/test-file', '/test-link')
|
575
575
|
expect(File.read('/test-link')).to eq(File.read('/test-file'))
|
576
576
|
end
|
577
577
|
|
578
578
|
context 'when +new+ already exists' do
|
579
579
|
context 'and it is a directory' do
|
580
580
|
it 'creates a symbolic link +new/old+' do
|
581
|
-
|
581
|
+
described_class.ln_s('/test-file', '/test-dir')
|
582
582
|
expect(File.symlink?('/test-dir/test-file')).to be true
|
583
583
|
end
|
584
584
|
end
|
@@ -586,13 +586,13 @@ describe FileUtils do
|
|
586
586
|
context 'and it is not a directory' do
|
587
587
|
it 'raises an exeption' do
|
588
588
|
expect {
|
589
|
-
|
589
|
+
described_class.ln_s('/test-file', '/not-a-dir')
|
590
590
|
}.to raise_specific_error(Errno::EEXIST)
|
591
591
|
end
|
592
592
|
|
593
593
|
context 'and +:force+ is set' do
|
594
594
|
it 'overwrites +new+' do
|
595
|
-
|
595
|
+
described_class.ln_s('/test-file', '/not-a-dir', force: true)
|
596
596
|
expect(File.symlink?('/not-a-dir')).to be true
|
597
597
|
end
|
598
598
|
end
|
@@ -605,19 +605,19 @@ describe FileUtils do
|
|
605
605
|
end
|
606
606
|
|
607
607
|
it 'creates several symbolic links in +destdir+' do
|
608
|
-
|
608
|
+
described_class.ln_s(['/test-file', '/test-file2'], '/test-dir')
|
609
609
|
expect(File.exist?('/test-dir/test-file2')).to be true
|
610
610
|
end
|
611
611
|
|
612
612
|
it 'creates symbolic links pointing to each item in the list' do
|
613
|
-
|
613
|
+
described_class.ln_s(['/test-file', '/test-file2'], '/test-dir')
|
614
614
|
expect(File.read('/test-dir/test-file2')).to eq(File.read('/test-file2'))
|
615
615
|
end
|
616
616
|
|
617
617
|
context 'when +destdir+ is not a directory' do
|
618
618
|
it 'raises an error' do
|
619
619
|
expect {
|
620
|
-
|
620
|
+
described_class.ln_s(['/test-file', '/test-file2'], '/not-a-dir')
|
621
621
|
}.to raise_specific_error(Errno::ENOTDIR)
|
622
622
|
end
|
623
623
|
end
|
@@ -628,7 +628,7 @@ describe FileUtils do
|
|
628
628
|
it 'calls ln_s with +:force+ set to true' do
|
629
629
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
630
630
|
File.open('/test-file2', 'w') { |f| f.puts 'test2' }
|
631
|
-
|
631
|
+
described_class.ln_sf('/test-file', '/test-file2')
|
632
632
|
expect(File.read('/test-file2')).to eq(File.read('/test-file'))
|
633
633
|
end
|
634
634
|
end
|
@@ -639,40 +639,78 @@ describe FileUtils do
|
|
639
639
|
|
640
640
|
describe '.mkdir' do
|
641
641
|
it 'creates one directory' do
|
642
|
-
|
642
|
+
described_class.mkdir('/test-dir')
|
643
643
|
expect(File.directory?('/test-dir')).to be true
|
644
644
|
end
|
645
645
|
|
646
646
|
context 'when passing a list of paths' do
|
647
647
|
it 'creates several directories' do
|
648
|
-
|
648
|
+
described_class.mkdir(['/test-dir', '/test-dir2'])
|
649
649
|
expect(File.directory?('/test-dir2')).to be true
|
650
650
|
end
|
651
651
|
end
|
652
|
+
|
653
|
+
context 'when passing options' do
|
654
|
+
context 'when passing mode parameter' do
|
655
|
+
it 'creates directory with specified permissions' do
|
656
|
+
described_class.mkdir('/test-dir', mode: 0654)
|
657
|
+
expect(File.exist?('/test-dir')).to be true
|
658
|
+
expect(File.stat('/test-dir').mode).to eq(0100654)
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
662
|
+
context 'when passing noop parameter' do
|
663
|
+
it 'does not create any directories' do
|
664
|
+
described_class.mkdir(['/test-dir', '/another-dir'], noop: true)
|
665
|
+
expect(File.directory?('/test-dir')).to be false
|
666
|
+
expect(File.directory?('/another-dir')).to be false
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
|
652
672
|
end
|
653
673
|
|
654
674
|
describe '.mkdir_p' do
|
655
675
|
it 'creates a directory' do
|
656
|
-
|
676
|
+
described_class.mkdir_p('/test-dir')
|
657
677
|
expect(File.directory?('/test-dir')).to be true
|
658
678
|
end
|
659
679
|
|
660
680
|
it 'creates all the parent directories' do
|
661
|
-
|
681
|
+
described_class.mkdir_p('/path/to/some/test-dir')
|
662
682
|
expect(File.directory?('/path/to/some')).to be true
|
663
683
|
end
|
664
684
|
|
665
685
|
context 'when passing a list of paths' do
|
666
686
|
it 'creates each directory' do
|
667
|
-
|
687
|
+
described_class.mkdir_p(['/test-dir', '/test-dir'])
|
668
688
|
expect(File.directory?('/test-dir')).to be true
|
669
689
|
end
|
670
690
|
|
671
691
|
it "creates each directory's parents" do
|
672
|
-
|
692
|
+
described_class.mkdir_p(['/test-dir', '/path/to/some/test-dir'])
|
673
693
|
expect(File.directory?('/path/to/some')).to be true
|
674
694
|
end
|
675
695
|
end
|
696
|
+
|
697
|
+
context 'when passing options' do
|
698
|
+
context 'when passing mode parameter' do
|
699
|
+
it 'creates directory with specified permissions' do
|
700
|
+
described_class.mkdir_p('/test-dir', mode: 0654)
|
701
|
+
expect(File.exist?('/test-dir')).to be true
|
702
|
+
expect(File.stat('/test-dir').mode).to eq(0100654)
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
context 'when passing noop parameter' do
|
707
|
+
it 'does not create any directories' do
|
708
|
+
described_class.mkdir_p(['/test-dir', '/another-dir'], noop: true)
|
709
|
+
expect(File.directory?('/test-dir')).to be false
|
710
|
+
expect(File.directory?('/another-dir')).to be false
|
711
|
+
end
|
712
|
+
end
|
713
|
+
end
|
676
714
|
end
|
677
715
|
|
678
716
|
describe '.mkpath' do
|
@@ -685,23 +723,23 @@ describe FileUtils do
|
|
685
723
|
|
686
724
|
describe '.mv' do
|
687
725
|
it 'moves +src+ to +dest+' do
|
688
|
-
|
689
|
-
|
726
|
+
described_class.touch('/test-file')
|
727
|
+
described_class.mv('/test-file', '/test-file2')
|
690
728
|
expect(File.exist?('/test-file2')).to be true
|
691
729
|
end
|
692
730
|
|
693
731
|
it 'removes +src+' do
|
694
|
-
|
695
|
-
|
732
|
+
described_class.touch('/test-file')
|
733
|
+
described_class.mv('/test-file', '/test-file2')
|
696
734
|
expect(File.exist?('/test-file')).to be false
|
697
735
|
end
|
698
736
|
|
699
737
|
context 'when +dest+ already exists' do
|
700
738
|
context 'and is a directory' do
|
701
739
|
it 'moves +src+ to dest/src' do
|
702
|
-
|
703
|
-
|
704
|
-
|
740
|
+
described_class.touch('/test-file')
|
741
|
+
described_class.mkdir('/test-dir')
|
742
|
+
described_class.mv('/test-file', '/test-dir')
|
705
743
|
expect(File.exist?('/test-dir/test-file')).to be true
|
706
744
|
end
|
707
745
|
end
|
@@ -709,8 +747,8 @@ describe FileUtils do
|
|
709
747
|
context 'and +dest+ is not a directory' do
|
710
748
|
it 'it overwrites +dest+' do
|
711
749
|
File.open('/test-file', 'w') { |f| f.puts 'test' }
|
712
|
-
|
713
|
-
|
750
|
+
described_class.touch('/test-file2')
|
751
|
+
described_class.mv('/test-file', '/test-file2')
|
714
752
|
expect(File.read('/test-file2')).to eq("test\n")
|
715
753
|
end
|
716
754
|
end
|
@@ -719,8 +757,8 @@ describe FileUtils do
|
|
719
757
|
|
720
758
|
describe '.pwd' do
|
721
759
|
it 'returns the name of the current directory' do
|
722
|
-
|
723
|
-
expect(
|
760
|
+
described_class.cd '/test'
|
761
|
+
expect(described_class.pwd).to eq('/test')
|
724
762
|
end
|
725
763
|
end
|
726
764
|
|
@@ -730,35 +768,35 @@ describe FileUtils do
|
|
730
768
|
|
731
769
|
describe '.remove_dir' do
|
732
770
|
it 'removes the given directory +dir+' do
|
733
|
-
|
734
|
-
|
771
|
+
described_class.mkdir('/test-dir')
|
772
|
+
described_class.remove_dir('/test-dir')
|
735
773
|
expect(File.exist?('/test-dir')).to be false
|
736
774
|
end
|
737
775
|
|
738
776
|
it 'removes the contents of the given directory +dir+' do
|
739
|
-
|
740
|
-
|
777
|
+
described_class.mkdir_p('/test-dir/test-sub-dir')
|
778
|
+
described_class.remove_dir('/test-dir')
|
741
779
|
expect(File.exist?('/test-dir/test-sub-dir')).to be false
|
742
780
|
end
|
743
781
|
|
744
782
|
context 'when +force+ is set' do
|
745
783
|
it 'ignores standard errors' do
|
746
|
-
expect {
|
784
|
+
expect { described_class.remove_dir('/test-dir', true) }.not_to raise_error
|
747
785
|
end
|
748
786
|
end
|
749
787
|
end
|
750
788
|
|
751
789
|
describe '.remove_entry' do
|
752
790
|
it 'removes a file system entry +path+' do
|
753
|
-
|
754
|
-
|
791
|
+
described_class.touch('/test-file')
|
792
|
+
described_class.remove_entry('/test-file')
|
755
793
|
expect(File.exist?('/test-file')).to be false
|
756
794
|
end
|
757
795
|
|
758
796
|
context 'when +path+ is a directory' do
|
759
797
|
it 'removes it recursively' do
|
760
|
-
|
761
|
-
|
798
|
+
described_class.mkdir_p('/test-dir/test-sub-dir')
|
799
|
+
described_class.remove_entry('/test-dir')
|
762
800
|
expect(Dir.exist?('/test-dir')).to be false
|
763
801
|
end
|
764
802
|
end
|
@@ -766,35 +804,35 @@ describe FileUtils do
|
|
766
804
|
|
767
805
|
describe '.remove_entry_secure' do
|
768
806
|
before :each do
|
769
|
-
|
807
|
+
described_class.mkdir_p('/test-dir/test-sub-dir')
|
770
808
|
end
|
771
809
|
|
772
810
|
it 'removes a file system entry +path+' do
|
773
|
-
|
774
|
-
|
811
|
+
described_class.chmod(0755, '/')
|
812
|
+
described_class.remove_entry_secure('/test-dir')
|
775
813
|
expect(Dir.exist?('/test-dir')).to be false
|
776
814
|
end
|
777
815
|
|
778
816
|
context 'when +path+ is a directory' do
|
779
817
|
it 'removes it recursively' do
|
780
|
-
|
781
|
-
|
818
|
+
described_class.chmod(0755, '/')
|
819
|
+
described_class.remove_entry_secure('/test-dir')
|
782
820
|
expect(Dir.exist?('/test-dir/test-sub-dir')).to be false
|
783
821
|
end
|
784
822
|
|
785
823
|
context 'and is word writable' do
|
786
824
|
it 'calls chown(2) on it' do
|
787
|
-
|
825
|
+
described_class.chmod(01777, '/')
|
788
826
|
directory = _fs.find('/test-dir')
|
789
827
|
expect(directory).to receive(:uid=).at_least(:once)
|
790
|
-
|
828
|
+
described_class.remove_entry_secure('/test-dir')
|
791
829
|
end
|
792
830
|
|
793
831
|
it 'calls chmod(2) on all sub directories' do
|
794
|
-
|
832
|
+
described_class.chmod(01777, '/')
|
795
833
|
directory = _fs.find('/test-dir')
|
796
834
|
expect(directory).to receive(:mode=).at_least(:once)
|
797
|
-
|
835
|
+
described_class.remove_entry_secure('/test-dir')
|
798
836
|
end
|
799
837
|
end
|
800
838
|
end
|
@@ -802,41 +840,41 @@ describe FileUtils do
|
|
802
840
|
|
803
841
|
describe '.remove_file' do
|
804
842
|
it 'removes a file path' do
|
805
|
-
|
806
|
-
|
843
|
+
described_class.touch('/test-file')
|
844
|
+
described_class.remove_file('/test-file')
|
807
845
|
expect(File.exist?('/test-file')).to be false
|
808
846
|
end
|
809
847
|
|
810
848
|
context 'when +force+ is set' do
|
811
849
|
it 'ignores StandardError' do
|
812
|
-
expect {
|
850
|
+
expect { described_class.remove_file('/no-file', true) }.not_to raise_error
|
813
851
|
end
|
814
852
|
end
|
815
853
|
end
|
816
854
|
|
817
855
|
describe '.rm' do
|
818
856
|
it 'removes the specified file' do
|
819
|
-
|
820
|
-
|
857
|
+
described_class.touch('/test-file')
|
858
|
+
described_class.rm('/test-file')
|
821
859
|
expect(File.exist?('/test-file')).to be false
|
822
860
|
end
|
823
861
|
|
824
862
|
it 'removes files specified in list' do
|
825
|
-
|
826
|
-
|
863
|
+
described_class.touch(['/test-file', '/test-file2'])
|
864
|
+
described_class.rm(['/test-file', '/test-file2'])
|
827
865
|
expect(File.exist?('/test-file2')).to be false
|
828
866
|
end
|
829
867
|
|
830
868
|
it 'cannot remove a directory' do
|
831
|
-
|
832
|
-
expect {
|
869
|
+
described_class.mkdir('/test-dir')
|
870
|
+
expect { described_class.rm('/test-dir') }.to raise_specific_error(Errno::EPERM)
|
833
871
|
end
|
834
872
|
|
835
873
|
context 'when +:force+ is set' do
|
836
874
|
it 'ignores StandardError' do
|
837
|
-
|
875
|
+
described_class.mkdir('/test-dir')
|
838
876
|
expect {
|
839
|
-
|
877
|
+
described_class.rm('/test-dir', force: true)
|
840
878
|
}.not_to raise_error
|
841
879
|
end
|
842
880
|
end
|
@@ -844,26 +882,26 @@ describe FileUtils do
|
|
844
882
|
|
845
883
|
describe '.rm_f' do
|
846
884
|
it 'calls rm with +:force+ set to true' do
|
847
|
-
expect(
|
848
|
-
|
885
|
+
expect(described_class).to receive(:rm).with('test', force: true)
|
886
|
+
described_class.rm_f('test')
|
849
887
|
end
|
850
888
|
end
|
851
889
|
|
852
890
|
describe '.rm_r' do
|
853
891
|
before :each do
|
854
|
-
|
892
|
+
described_class.touch(['/test-file', '/test-file2'])
|
855
893
|
end
|
856
894
|
|
857
895
|
it 'removes a list of files' do
|
858
|
-
|
896
|
+
described_class.rm_r(['/test-file', '/test-file2'])
|
859
897
|
expect(File.exist?('/test-file2')).to be false
|
860
898
|
end
|
861
899
|
|
862
900
|
context 'when an item of the list is a directory' do
|
863
901
|
it 'removes all its contents recursively' do
|
864
|
-
|
865
|
-
|
866
|
-
|
902
|
+
described_class.mkdir('/test-dir')
|
903
|
+
described_class.touch('/test-dir/test-file')
|
904
|
+
described_class.rm_r(['/test-file', '/test-file2', '/test-dir'])
|
867
905
|
expect(File.exist?('/test-dir/test-file')).to be false
|
868
906
|
end
|
869
907
|
end
|
@@ -871,7 +909,7 @@ describe FileUtils do
|
|
871
909
|
context 'when +:force+ is set' do
|
872
910
|
it 'ignores StandardError' do
|
873
911
|
expect {
|
874
|
-
|
912
|
+
described_class.rm_r(['/no-file'], force: true)
|
875
913
|
}.not_to raise_error
|
876
914
|
end
|
877
915
|
end
|
@@ -879,37 +917,37 @@ describe FileUtils do
|
|
879
917
|
|
880
918
|
describe '.rm_rf' do
|
881
919
|
it 'calls rm with +:force+ set to true' do
|
882
|
-
expect(
|
883
|
-
|
920
|
+
expect(described_class).to receive(:rm_r).with('test', force: true)
|
921
|
+
described_class.rm_rf('test')
|
884
922
|
end
|
885
923
|
end
|
886
924
|
|
887
925
|
describe '.rmdir' do
|
888
926
|
it 'Removes a directory' do
|
889
|
-
|
890
|
-
|
927
|
+
described_class.mkdir('/test-dir')
|
928
|
+
described_class.rmdir('/test-dir')
|
891
929
|
expect(Dir.exist?('/test-dir')).to be false
|
892
930
|
end
|
893
931
|
|
894
932
|
it 'Removes a list of directories' do
|
895
|
-
|
896
|
-
|
897
|
-
|
933
|
+
described_class.mkdir('/test-dir')
|
934
|
+
described_class.mkdir('/test-dir2')
|
935
|
+
described_class.rmdir(['/test-dir', '/test-dir2'])
|
898
936
|
expect(Dir.exist?('/test-dir2')).to be false
|
899
937
|
end
|
900
938
|
|
901
939
|
context 'when a directory is not empty' do
|
902
940
|
before :each do
|
903
|
-
|
904
|
-
|
941
|
+
described_class.mkdir('/test-dir')
|
942
|
+
described_class.touch('/test-dir/test-file')
|
905
943
|
end
|
906
944
|
|
907
945
|
it 'ignores errors' do
|
908
|
-
expect {
|
946
|
+
expect { described_class.rmdir('/test-dir') }.not_to raise_error
|
909
947
|
end
|
910
948
|
|
911
949
|
it "doesn't remove the directory" do
|
912
|
-
|
950
|
+
described_class.rmdir('/test-dir')
|
913
951
|
expect(Dir.exist?('/test-dir')).to be true
|
914
952
|
end
|
915
953
|
end
|
@@ -929,36 +967,36 @@ describe FileUtils do
|
|
929
967
|
|
930
968
|
describe '.touch' do
|
931
969
|
it "creates a file if it doesn't exist" do
|
932
|
-
|
970
|
+
described_class.touch('/test-file')
|
933
971
|
expect(_fs.find('/test-file')).not_to be_nil
|
934
972
|
end
|
935
973
|
|
936
974
|
it "creates a list of files if they don't exist" do
|
937
|
-
|
975
|
+
described_class.touch(['/test-file', '/test-file2'])
|
938
976
|
expect(_fs.find('/test-file2')).not_to be_nil
|
939
977
|
end
|
940
978
|
end
|
941
979
|
|
942
980
|
describe '.uptodate?' do
|
943
981
|
before :each do
|
944
|
-
|
945
|
-
|
982
|
+
described_class.touch('/test-file')
|
983
|
+
described_class.touch('/old-file')
|
946
984
|
_fs.find!('/old-file').mtime = Time.now - 3600
|
947
985
|
end
|
948
986
|
|
949
987
|
it 'returns true if +newer+ is newer than all +old_list+' do
|
950
|
-
expect(
|
988
|
+
expect(described_class.uptodate?('/test-file', ['/old-file'])).to be true
|
951
989
|
end
|
952
990
|
|
953
991
|
context 'when +newer+ does not exist' do
|
954
992
|
it 'consideres it as older' do
|
955
|
-
expect(
|
993
|
+
expect(described_class.uptodate?('/no-file', ['/old-file'])).to be false
|
956
994
|
end
|
957
995
|
end
|
958
996
|
|
959
997
|
context 'when a item of +old_list+ does not exist' do
|
960
998
|
it 'consideres it as older than +newer+' do
|
961
|
-
uptodate =
|
999
|
+
uptodate = described_class.uptodate?('/test-file', ['/old-file', '/no-file'])
|
962
1000
|
expect(uptodate).to be true
|
963
1001
|
end
|
964
1002
|
end
|