rubypath 0.3.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +5 -55
- data/CHANGELOG.md +0 -24
- data/LICENSE.txt +0 -165
- data/README.md +0 -102
- data/doc/file.README.html +0 -175
- data/lib/rubypath.rb +0 -29
- data/lib/rubypath/backend.rb +0 -92
- data/lib/rubypath/backend/mock.rb +0 -356
- data/lib/rubypath/backend/sys.rb +0 -161
- data/lib/rubypath/comparison.rb +0 -19
- data/lib/rubypath/construction.rb +0 -109
- data/lib/rubypath/dir_operations.rb +0 -160
- data/lib/rubypath/extensions.rb +0 -157
- data/lib/rubypath/file_operations.rb +0 -192
- data/lib/rubypath/file_predicates.rb +0 -32
- data/lib/rubypath/identity.rb +0 -59
- data/lib/rubypath/io_operations.rb +0 -82
- data/lib/rubypath/mock.rb +0 -42
- data/lib/rubypath/path_operations.rb +0 -311
- data/lib/rubypath/path_predicates.rb +0 -61
- data/lib/rubypath/version.rb +0 -11
- data/rubypath.gemspec +0 -22
- data/spec/README_spec.rb +0 -27
- data/spec/rubypath/comparison_spec.rb +0 -77
- data/spec/rubypath/construction_spec.rb +0 -101
- data/spec/rubypath/dir_operations_spec.rb +0 -225
- data/spec/rubypath/extensions_spec.rb +0 -270
- data/spec/rubypath/file_operations_spec.rb +0 -428
- data/spec/rubypath/file_predicates_spec.rb +0 -66
- data/spec/rubypath/identity_spec.rb +0 -21
- data/spec/rubypath/io_operations_spec.rb +0 -128
- data/spec/rubypath/path_operations_spec.rb +0 -483
- data/spec/rubypath/path_predicates_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -42
- data/spec/support/describe_method.rb +0 -18
- data/spec/support/with_backend.rb +0 -37
@@ -1,428 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Path do
|
4
|
-
let(:delta) { 1.0 }
|
5
|
-
|
6
|
-
describe 'File Operations' do
|
7
|
-
with_backends :mock, :sys do
|
8
|
-
let(:path) { Path('/path/to/file.txt') }
|
9
|
-
|
10
|
-
describe_method :name, aliases: [:basename] do
|
11
|
-
subject { path.send described_method }
|
12
|
-
|
13
|
-
it 'should return file name' do
|
14
|
-
should eq 'file.txt'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe_method :unlink do
|
19
|
-
subject { path.send described_method }
|
20
|
-
|
21
|
-
context 'on non-existent file' do
|
22
|
-
it { expect{ subject }.to raise_error Errno::ENOENT }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'on existent file' do
|
26
|
-
before { path.mkfile }
|
27
|
-
|
28
|
-
it 'should unlink file' do
|
29
|
-
expect{ subject }.to change(path, :exist?).from(true).to(false)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'on existent directory' do
|
34
|
-
before { path.mkpath }
|
35
|
-
|
36
|
-
it { expect{ subject }.to raise_error Errno::EISDIR }
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with args' do
|
40
|
-
subject { path.send(described_method, 'file') }
|
41
|
-
|
42
|
-
context 'on non-existent file' do
|
43
|
-
it { expect{ subject }.to raise_error Errno::ENOENT }
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'on existent file' do
|
47
|
-
before { path.mkfile('file') }
|
48
|
-
|
49
|
-
it 'should unlink file' do
|
50
|
-
expect{ subject }
|
51
|
-
.to change(path.join('file'), :exist?).from(true).to(false)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe_method :touch do
|
58
|
-
let(:path) { Path '/rubypath' }
|
59
|
-
let(:args) { Array.new }
|
60
|
-
let(:expected_path) { path }
|
61
|
-
subject { path.touch(*args) }
|
62
|
-
before { expect(path).to_not be_existent }
|
63
|
-
|
64
|
-
shared_examples '#touch' do
|
65
|
-
it 'should create file' do
|
66
|
-
subject
|
67
|
-
expect(expected_path).to be_existent
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should update modification time' do
|
71
|
-
subject
|
72
|
-
expect(expected_path.mtime).to be_within(delta).of(Time.now)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
shared_examples '#touch with existing file' do
|
77
|
-
before do
|
78
|
-
expected_path.write 'ABC'
|
79
|
-
expected_path.mtime = Time.now - 3600
|
80
|
-
end
|
81
|
-
before { expect(expected_path.mtime).to be < (Time.now - 30) }
|
82
|
-
|
83
|
-
it_behaves_like '#touch'
|
84
|
-
|
85
|
-
it 'should not change content' do
|
86
|
-
subject
|
87
|
-
expect(expected_path.read).to eq 'ABC'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it_behaves_like '#touch with existing file'
|
92
|
-
|
93
|
-
context 'with args' do
|
94
|
-
let(:args) { '../file' }
|
95
|
-
let(:expected_path) { Path '/file' }
|
96
|
-
|
97
|
-
it_behaves_like '#touch with existing file'
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'with existing file in path' do
|
101
|
-
let(:path) { super().join('file') }
|
102
|
-
before { path.parent.write 'ABC' }
|
103
|
-
|
104
|
-
it 'should raise ENOTDIR error' do
|
105
|
-
expect{ subject }.to raise_error(
|
106
|
-
Errno::ENOTDIR, 'Not a directory - /rubypath/file')
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'with existing directory' do
|
111
|
-
before do
|
112
|
-
path.mkdir
|
113
|
-
path.mtime = Time.now - 3600
|
114
|
-
end
|
115
|
-
before { expect(path).to be_directory }
|
116
|
-
before { expect(path.mtime).to be < (Time.now - 30) }
|
117
|
-
|
118
|
-
it 'should should update modification time' do
|
119
|
-
subject
|
120
|
-
expect(path.mtime).to be_within(delta).of(Time.now)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'with file in non-existent directory' do
|
125
|
-
let(:path) { Path '/dir/file' }
|
126
|
-
|
127
|
-
it 'should raise ENOENT error' do
|
128
|
-
expect{ subject }.to raise_error(
|
129
|
-
Errno::ENOENT, 'No such file or directory - /dir/file')
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe_method :mkfile do
|
135
|
-
let(:path) { Path '/path/to/file.txt' }
|
136
|
-
let(:args) { Array.new }
|
137
|
-
let(:expected_path) { path.dup }
|
138
|
-
subject { path.send described_method, *args }
|
139
|
-
|
140
|
-
shared_examples '#mkfile' do
|
141
|
-
it 'should create all missing directories' do
|
142
|
-
expect{ subject }.to change{ expected_path.parent.directory? }
|
143
|
-
.from(false).to(true)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should create file' do
|
147
|
-
expect{ subject }.to change{ expected_path.file? }
|
148
|
-
.from(false).to(true)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it_behaves_like '#mkfile'
|
153
|
-
|
154
|
-
context 'with args' do
|
155
|
-
let(:args) { %w(sub file) }
|
156
|
-
let(:expected_path) { Path '/path/to/file.txt/sub/file' }
|
157
|
-
|
158
|
-
it_behaves_like '#mkfile'
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'with existing directory' do
|
162
|
-
before { path.mkpath }
|
163
|
-
|
164
|
-
it 'should raise ENOENT error' do
|
165
|
-
expect{ subject }.to raise_error(
|
166
|
-
Errno::ENOENT, 'No such file or directory - /path/to/file.txt')
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'with existing file in path' do
|
171
|
-
before do
|
172
|
-
path.parent.parent.mkpath
|
173
|
-
path.parent.touch
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'should raise EISDIR error' do
|
177
|
-
expect{ subject }.to raise_error(
|
178
|
-
Errno::ENOTDIR, 'Not a directory - /path/to/file.txt')
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context 'with absolute root dir as path' do
|
183
|
-
let(:path) { Path '/' }
|
184
|
-
|
185
|
-
it 'should raise EISDIR error' do
|
186
|
-
expect{ subject }.to raise_error(
|
187
|
-
Errno::ENOENT, 'No such file or directory - /')
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe_method :lookup do
|
193
|
-
let(:path) { Path('~') }
|
194
|
-
before do
|
195
|
-
Path.mock do |r|
|
196
|
-
path.mkpath 'a/b/c/d'
|
197
|
-
path.touch 'a/test.txt'
|
198
|
-
path.touch 'a/b/c/config.yaml'
|
199
|
-
path.touch 'a/b/.config.yml'
|
200
|
-
path.touch 'a/config.yml'
|
201
|
-
end
|
202
|
-
end
|
203
|
-
before { expect(path.join('a/b/c/d')).to be_directory }
|
204
|
-
|
205
|
-
context 'with filename' do
|
206
|
-
it 'should find file in current directory' do
|
207
|
-
expect(path.join('a').send(described_method, 'test.txt'))
|
208
|
-
.to eq path.join('a/test.txt').expand
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should find file in parent directory' do
|
212
|
-
expect(path.join(%w(a b)).send(described_method, 'test.txt'))
|
213
|
-
.to eq path.join('a/test.txt').expand
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'should find file in ancestor directory' do
|
217
|
-
expect(path.join('a/b/c/d').send(described_method, 'test.txt'))
|
218
|
-
.to eq path.join('a/test.txt').expand
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'should find first file in ancestor directory' do
|
222
|
-
expect(path.join('a/b/c/d').send(described_method, 'config.yaml'))
|
223
|
-
.to eq path.join('a/b/c/config.yaml').expand
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context 'with glob' do
|
228
|
-
it 'should find file in current directory' do
|
229
|
-
expect(path.join('a').send(described_method, 'test.*'))
|
230
|
-
.to eq path.join('a/test.txt').expand
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'should find file in parent directory' do
|
234
|
-
expect(path.join('a/b').send(described_method, 'test.*'))
|
235
|
-
.to eq path.join('a/test.txt').expand
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'should find file in ancestor directory' do
|
239
|
-
expect(path.join('a/b/c/d').send(described_method, 'test.*'))
|
240
|
-
.to eq path.join('a/test.txt').expand
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'should find first file in ancestor directory' do
|
244
|
-
expect(path.join('a/b/c/d').send(described_method, 'config.*'))
|
245
|
-
.to eq path.join('a/b/c/config.yaml').expand
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'should find first file that match (I)' do
|
249
|
-
expect(path.join('a/b').send(described_method, '*.yml'))
|
250
|
-
.to eq path.join('a/config.yml').expand
|
251
|
-
end
|
252
|
-
|
253
|
-
if defined?(::File::FNM_EXTGLOB)
|
254
|
-
it 'should find first file that match (II)' do
|
255
|
-
expect(path.join('a/b')
|
256
|
-
.send(described_method, 'config.{yml,yaml}'))
|
257
|
-
.to eq path.join('a/config.yml').expand
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should find first file that dotmatch' do
|
262
|
-
expect(path.join('a/b')
|
263
|
-
.send(described_method, '*.yml', ::File::FNM_DOTMATCH))
|
264
|
-
.to eq path.join('a/b/.config.yml').expand
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
context 'with regexp' do
|
269
|
-
it 'should find file in current directory' do
|
270
|
-
expect(path.join('a').send(described_method, /^test\.txt$/))
|
271
|
-
.to eq path.join('a/test.txt').expand
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'should find file in parent directory' do
|
275
|
-
expect(path.join('a/b').send(described_method, /^test\.txt$/))
|
276
|
-
.to eq path.join('a/test.txt').expand
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'should find file in ancestor directory' do
|
280
|
-
expect(path.join('a/b/c/d').send(described_method, /^test\.txt$/))
|
281
|
-
.to eq path.join('a/test.txt').expand
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'should find first file in ancestor directory' do
|
285
|
-
expect(path.join('a/b/c/d')
|
286
|
-
.send(described_method, /^config\.yaml$/))
|
287
|
-
.to eq path.join('a/b/c/config.yaml').expand
|
288
|
-
end
|
289
|
-
|
290
|
-
it 'should find first file that match' do
|
291
|
-
expect(path.join('a/b').send(described_method, /^config\.ya?ml$/))
|
292
|
-
.to eq path.join('a/config.yml').expand
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
describe_method :mtime do
|
298
|
-
let(:path) { Path '/file.txt' }
|
299
|
-
before { path.touch }
|
300
|
-
subject { path.send described_method }
|
301
|
-
|
302
|
-
it 'should return file modification time' do
|
303
|
-
should be_within(delta).of(Time.now)
|
304
|
-
end
|
305
|
-
|
306
|
-
context 'with modification time changed' do
|
307
|
-
before { path.mtime = Time.new(2175, 12, 24, 18, 00, 30) }
|
308
|
-
|
309
|
-
it 'should return file modification time' do
|
310
|
-
should eq Time.new(2175, 12, 24, 18, 00, 30)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe_method :mtime= do
|
316
|
-
let(:path) { Path '/file.txt' }
|
317
|
-
before { path.touch }
|
318
|
-
subject { path.send described_method, Time.new(2175, 12, 24, 18, 00, 30) }
|
319
|
-
|
320
|
-
it 'should change file modification time' do
|
321
|
-
expect{ subject }.to change{ path.mtime }.to Time.new(2175, 12, 24, 18, 00, 30)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
describe_method :atime do
|
326
|
-
let(:path) { Path '/file.txt' }
|
327
|
-
subject { path.send described_method }
|
328
|
-
|
329
|
-
context 'new create file' do
|
330
|
-
before { path.touch }
|
331
|
-
|
332
|
-
it { should be_within(delta).of(Time.now) }
|
333
|
-
end
|
334
|
-
|
335
|
-
context 'with existing file' do
|
336
|
-
before { path.touch }
|
337
|
-
|
338
|
-
context 'older file' do
|
339
|
-
before { path.touch }
|
340
|
-
before { sleep 0.3 }
|
341
|
-
|
342
|
-
it { should be_within(delta).of(Time.now - 0.3) }
|
343
|
-
end
|
344
|
-
|
345
|
-
context 'and changed access time' do
|
346
|
-
before { path.atime = Time.new(2175, 12, 24, 18, 00, 30) }
|
347
|
-
|
348
|
-
it 'should return file access time' do
|
349
|
-
should eq Time.new(2175, 12, 24, 18, 00, 30)
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe_method :atime= do
|
356
|
-
let(:path) { Path '/file.txt' }
|
357
|
-
before { path.touch }
|
358
|
-
subject { path.send described_method, Time.new(2175, 12, 24, 18, 00, 30) }
|
359
|
-
|
360
|
-
it 'should change file access time' do
|
361
|
-
expect{ subject }.to change{ path.atime }.to Time.new(2175, 12, 24, 18, 00, 30)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
describe_method :mode do
|
366
|
-
let(:path) { Path '/file' }
|
367
|
-
subject { path.send described_method }
|
368
|
-
|
369
|
-
context 'with file' do
|
370
|
-
before { path.touch }
|
371
|
-
it { should eq 0666 - Path.umask }
|
372
|
-
end
|
373
|
-
|
374
|
-
context 'with directory' do
|
375
|
-
before { path.mkpath }
|
376
|
-
it { should eq 0777 - Path.umask }
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
describe 'umask' do
|
382
|
-
shared_examples 'umask setter' do
|
383
|
-
with_backend :sys do
|
384
|
-
it 'should set umask' do
|
385
|
-
subject
|
386
|
-
expect(File.umask).to eq 0077
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
with_backend :mock do
|
391
|
-
it 'should set umask' do
|
392
|
-
expect{ subject }.to change{ Path.umask }.from(0022).to(0077)
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
describe_method :umask do
|
398
|
-
let(:args) { Array.new }
|
399
|
-
subject { Path.send described_method, *args }
|
400
|
-
|
401
|
-
context 'as getter' do
|
402
|
-
with_backend :sys do
|
403
|
-
it 'should return umask' do
|
404
|
-
should eq File.umask
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
with_backend :mock do
|
409
|
-
it 'should return umask' do
|
410
|
-
should eq 0022
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
context 'as setter' do
|
416
|
-
let(:args) { [0077] }
|
417
|
-
it_behaves_like 'umask setter'
|
418
|
-
end
|
419
|
-
end
|
420
|
-
|
421
|
-
describe_method :umask= do
|
422
|
-
let(:args) { [0077] }
|
423
|
-
subject { Path.send described_method, *args }
|
424
|
-
it_behaves_like 'umask setter'
|
425
|
-
end
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Path do
|
4
|
-
describe 'File Predicates' do
|
5
|
-
with_backends :mock, :sys do
|
6
|
-
describe_method :file? do
|
7
|
-
let(:path) { Path '/file.txt' }
|
8
|
-
before { expect(path).to_not be_existent }
|
9
|
-
subject { path.send(described_method) }
|
10
|
-
|
11
|
-
context 'with existing file' do
|
12
|
-
before { path.touch }
|
13
|
-
it { should eq true }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'with existing but wrong node (dir)' do
|
17
|
-
before { path.mkdir }
|
18
|
-
it { should eq false }
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with not existent file' do
|
22
|
-
it { should eq false }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe_method :directory? do
|
27
|
-
let(:dir) { Path '/dir' }
|
28
|
-
before { expect(dir).to_not be_existent }
|
29
|
-
subject { dir.send(described_method) }
|
30
|
-
|
31
|
-
context 'with existing directory' do
|
32
|
-
before { dir.mkdir }
|
33
|
-
it { should eq true }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with existing but wrong node (file)' do
|
37
|
-
before { dir.touch }
|
38
|
-
it { should eq false }
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with not existent directory' do
|
42
|
-
it { should eq false }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe_method :exists?, aliases: [:exist?, :existent?] do
|
47
|
-
let(:path) { Path '/file' }
|
48
|
-
subject { path.send described_method }
|
49
|
-
|
50
|
-
context 'with existing directory' do
|
51
|
-
before { path.mkdir }
|
52
|
-
it { should eq true }
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with existing file' do
|
56
|
-
before { path.touch }
|
57
|
-
it { should eq true }
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with non-existing node' do
|
61
|
-
it { should eq false }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|