file-find 0.5.0 → 0.5.2
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
- checksums.yaml.gz.sig +3 -2
- data/CHANGES.md +16 -0
- data/Gemfile +2 -3
- data/MANIFEST.md +1 -1
- data/README.md +14 -1
- data/Rakefile +12 -3
- data/file-find.gemspec +14 -8
- data/lib/file/find.rb +46 -84
- data/lib/file-find.rb +2 -0
- data/spec/file_find_spec.rb +191 -163
- data.tar.gz.sig +0 -0
- metadata +56 -18
- metadata.gz.sig +0 -0
data/spec/file_find_spec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
######################################################################
|
|
2
4
|
# file_find_spec.rb
|
|
3
5
|
#
|
|
@@ -7,136 +9,138 @@
|
|
|
7
9
|
require 'rspec'
|
|
8
10
|
require 'file-find'
|
|
9
11
|
require 'sys-admin'
|
|
10
|
-
require '
|
|
12
|
+
require 'sys-uname'
|
|
11
13
|
require 'tmpdir'
|
|
14
|
+
require 'pp' # Goofy workaround for FakeFS bug
|
|
12
15
|
require 'fakefs/spec_helpers'
|
|
13
16
|
|
|
14
17
|
RSpec.describe File::Find do
|
|
15
18
|
include FakeFS::SpecHelpers
|
|
16
19
|
|
|
17
|
-
let(:windows)
|
|
18
|
-
let(:
|
|
19
|
-
let(:
|
|
20
|
-
let(:
|
|
21
|
-
let(:
|
|
20
|
+
let(:windows) { Sys::Platform.windows? }
|
|
21
|
+
let(:macos) { Sys::Platform.mac? }
|
|
22
|
+
let(:elevated) { windows and Win32::Security.elevated_security? }
|
|
23
|
+
let(:ruby_file) { 'file_find_test.rb' }
|
|
24
|
+
let(:doc_file) { 'file_find_test.doc' }
|
|
22
25
|
|
|
23
|
-
let(:rule) {
|
|
24
|
-
let(:txt_rule) {
|
|
26
|
+
let(:rule) { described_class.new }
|
|
27
|
+
let(:txt_rule) { described_class.new(:name => '*.txt') }
|
|
25
28
|
|
|
26
29
|
before(:all) do
|
|
27
30
|
@loguser = Sys::Admin.get_user(Sys::Admin.get_login)
|
|
28
|
-
|
|
31
|
+
group = Sys::Platform.windows? ? 'Users' : @loguser.gid
|
|
32
|
+
@logroup = Sys::Admin.get_group(group)
|
|
29
33
|
end
|
|
30
34
|
|
|
31
|
-
context
|
|
32
|
-
example
|
|
33
|
-
expect(File::Find::VERSION).to eq('0.5.
|
|
35
|
+
context 'constants', :constants do
|
|
36
|
+
example 'version constant is set to expected value' do
|
|
37
|
+
expect(File::Find::VERSION).to eq('0.5.2')
|
|
34
38
|
expect(File::Find::VERSION).to be_frozen
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
|
|
38
|
-
context
|
|
39
|
-
example
|
|
42
|
+
context 'path', :path do
|
|
43
|
+
example 'path accessor basic functionality' do
|
|
40
44
|
expect(rule).to respond_to(:path)
|
|
41
45
|
expect(rule).to respond_to(:path=)
|
|
42
46
|
end
|
|
43
47
|
|
|
44
|
-
example
|
|
48
|
+
example 'path method returns expected value' do
|
|
45
49
|
expect(rule.path).to eq(Dir.pwd)
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
|
|
49
|
-
context
|
|
50
|
-
example
|
|
53
|
+
context 'options', :options do
|
|
54
|
+
example 'options accessor basic functionality' do
|
|
51
55
|
expect(rule).to respond_to(:options)
|
|
52
56
|
expect(rule).to respond_to(:options=)
|
|
53
57
|
end
|
|
54
58
|
|
|
55
|
-
example
|
|
59
|
+
example 'options method returns expected value' do
|
|
56
60
|
expect(txt_rule.options).to eq({:name => '*.txt'})
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
|
|
60
|
-
context
|
|
64
|
+
context 'atime', :atime do
|
|
61
65
|
before do
|
|
62
66
|
FileUtils.touch(ruby_file)
|
|
63
67
|
end
|
|
64
68
|
|
|
65
|
-
example
|
|
69
|
+
example 'atime accessor basic functionality' do
|
|
66
70
|
expect(rule).to respond_to(:atime)
|
|
67
71
|
expect(rule).to respond_to(:atime=)
|
|
68
72
|
end
|
|
69
73
|
|
|
70
|
-
example
|
|
74
|
+
example 'atime method returns expected default value' do
|
|
71
75
|
expect(rule.atime).to be_nil
|
|
72
76
|
end
|
|
73
77
|
|
|
74
|
-
example
|
|
75
|
-
rule1 =
|
|
76
|
-
rule2 =
|
|
78
|
+
example 'find with atime option works as expected' do
|
|
79
|
+
rule1 = described_class.new(:name => '*.rb', :atime => 0)
|
|
80
|
+
rule2 = described_class.new(:name => '*.rb', :atime => 1)
|
|
77
81
|
|
|
78
82
|
expect(rule1.find.empty?).to be false
|
|
79
83
|
expect(rule2.find.empty?).to be true
|
|
80
84
|
end
|
|
81
85
|
end
|
|
82
86
|
|
|
83
|
-
context
|
|
87
|
+
context 'ctime', :ctime do
|
|
84
88
|
before do
|
|
85
89
|
FileUtils.touch(ruby_file)
|
|
86
90
|
end
|
|
87
91
|
|
|
88
|
-
example
|
|
92
|
+
example 'ctime accessor basic functionality' do
|
|
89
93
|
expect(rule).to respond_to(:ctime)
|
|
90
94
|
expect(rule).to respond_to(:ctime=)
|
|
91
95
|
end
|
|
92
96
|
|
|
93
|
-
example
|
|
97
|
+
example 'ctime method returns expected default value' do
|
|
94
98
|
expect(rule.ctime).to be_nil
|
|
95
99
|
end
|
|
96
100
|
|
|
97
|
-
example
|
|
98
|
-
rule1 =
|
|
99
|
-
rule2 =
|
|
101
|
+
example 'find with ctime option works as expected' do
|
|
102
|
+
rule1 = described_class.new(:name => '*.rb', :ctime => 0)
|
|
103
|
+
rule2 = described_class.new(:name => '*.rb', :ctime => 1)
|
|
100
104
|
|
|
101
105
|
expect(rule1.find.empty?).to be false
|
|
102
106
|
expect(rule2.find.empty?).to be true
|
|
103
107
|
end
|
|
104
108
|
end
|
|
105
109
|
|
|
106
|
-
context
|
|
107
|
-
example
|
|
110
|
+
context 'find', :find do
|
|
111
|
+
example 'find method basic functionality' do
|
|
108
112
|
expect(rule).to respond_to(:find)
|
|
109
113
|
expect{ rule.find }.not_to raise_error
|
|
110
114
|
end
|
|
111
115
|
|
|
112
|
-
example
|
|
113
|
-
expect(rule.find).to
|
|
116
|
+
example 'find method returns expected value' do
|
|
117
|
+
expect(rule.find).to be_a(Array)
|
|
114
118
|
expect(rule.find{}).to be_nil
|
|
115
119
|
end
|
|
116
120
|
end
|
|
117
121
|
|
|
118
|
-
context
|
|
122
|
+
context 'filetest', :filetest do
|
|
119
123
|
before do
|
|
120
124
|
FileUtils.touch(doc_file, :mode => 0644)
|
|
121
125
|
end
|
|
122
126
|
|
|
123
|
-
example
|
|
127
|
+
example 'filetest accessor basic functionality' do
|
|
124
128
|
expect(rule).to respond_to(:filetest)
|
|
125
129
|
expect(rule).to respond_to(:filetest=)
|
|
126
130
|
expect{ rule.filetest }.not_to raise_error
|
|
127
131
|
end
|
|
128
132
|
|
|
129
|
-
example
|
|
130
|
-
expect(rule.filetest).to
|
|
133
|
+
example 'filetest method returns expected value' do
|
|
134
|
+
expect(rule.filetest).to be_a(Array)
|
|
131
135
|
end
|
|
132
136
|
|
|
133
|
-
example
|
|
134
|
-
expect{
|
|
135
|
-
expect{
|
|
137
|
+
example 'valid filetest options work as expected' do
|
|
138
|
+
expect{ described_class.new(:readable? => true) }.not_to raise_error
|
|
139
|
+
expect{ described_class.new(:writable? => true) }.not_to raise_error
|
|
136
140
|
end
|
|
137
141
|
|
|
138
|
-
example
|
|
139
|
-
rule =
|
|
142
|
+
example 'find method works with filetest option' do
|
|
143
|
+
rule = described_class.new(:name => '*.doc', :writable? => true)
|
|
140
144
|
|
|
141
145
|
expect(rule.find.map{ |f| File.basename(f) }).to eq([doc_file])
|
|
142
146
|
FileUtils.chmod(0444, doc_file)
|
|
@@ -144,165 +148,161 @@ RSpec.describe File::Find do
|
|
|
144
148
|
end
|
|
145
149
|
end
|
|
146
150
|
|
|
147
|
-
context
|
|
151
|
+
context 'mtime', :mtime do
|
|
148
152
|
before do
|
|
149
153
|
FileUtils.touch(ruby_file)
|
|
150
154
|
end
|
|
151
155
|
|
|
152
|
-
example
|
|
156
|
+
example 'mtime accessor basic functionality' do
|
|
153
157
|
expect(rule).to respond_to(:mtime)
|
|
154
158
|
expect(rule).to respond_to(:mtime=)
|
|
155
159
|
end
|
|
156
160
|
|
|
157
|
-
example
|
|
161
|
+
example 'mtime method returns expected default value' do
|
|
158
162
|
expect(rule.mtime).to be_nil
|
|
159
163
|
end
|
|
160
164
|
|
|
161
|
-
example
|
|
162
|
-
rule1 =
|
|
163
|
-
rule2 =
|
|
165
|
+
example 'find with mtime option works as expected' do
|
|
166
|
+
rule1 = described_class.new(:name => '*.rb', :mtime => 0)
|
|
167
|
+
rule2 = described_class.new(:name => '*.rb', :mtime => 1)
|
|
164
168
|
|
|
165
169
|
expect(rule1.find.empty?).to be false
|
|
166
170
|
expect(rule2.find.empty?).to be true
|
|
167
171
|
end
|
|
168
172
|
end
|
|
169
173
|
|
|
170
|
-
context
|
|
174
|
+
context 'ftype', :ftype do
|
|
171
175
|
before do
|
|
172
176
|
FileUtils.touch(ruby_file)
|
|
173
177
|
end
|
|
174
178
|
|
|
175
|
-
example
|
|
179
|
+
example 'ftype accessor basic functionality' do
|
|
176
180
|
expect(rule).to respond_to(:ftype)
|
|
177
181
|
expect(rule).to respond_to(:ftype=)
|
|
178
182
|
end
|
|
179
183
|
|
|
180
|
-
example
|
|
184
|
+
example 'ftype method returns expected default value' do
|
|
181
185
|
expect(rule.ftype).to be_nil
|
|
182
186
|
end
|
|
183
187
|
|
|
184
|
-
example
|
|
185
|
-
rule1 =
|
|
186
|
-
rule2 =
|
|
188
|
+
example 'ftype method works as expected' do
|
|
189
|
+
rule1 = described_class.new(:name => '*.rb', :ftype => 'file')
|
|
190
|
+
rule2 = described_class.new(:name => '*.rb', :ftype => 'characterSpecial')
|
|
187
191
|
|
|
188
192
|
expect(rule1.find.empty?).to be false
|
|
189
193
|
expect(rule2.find.empty?).to be true
|
|
190
194
|
end
|
|
191
195
|
end
|
|
192
196
|
|
|
193
|
-
context
|
|
197
|
+
context 'group', :group do
|
|
194
198
|
before do
|
|
195
199
|
FileUtils.touch(doc_file)
|
|
196
200
|
end
|
|
197
201
|
|
|
198
|
-
example
|
|
202
|
+
example 'group accessor basic functionality' do
|
|
199
203
|
expect(rule).to respond_to(:group)
|
|
200
204
|
expect(rule).to respond_to(:group=)
|
|
201
205
|
end
|
|
202
206
|
|
|
203
|
-
example
|
|
207
|
+
example 'group method returns expected default value' do
|
|
204
208
|
expect(rule.group).to be_nil
|
|
205
209
|
end
|
|
206
210
|
|
|
207
211
|
# TODO: Update example for Windows
|
|
208
|
-
example
|
|
212
|
+
example 'find with numeric group id works as expected' do
|
|
209
213
|
skip 'group example skipped on MS Windows' if windows
|
|
210
|
-
|
|
214
|
+
skip 'group example skipped on Mac in CI' if macos && ENV['CI']
|
|
215
|
+
|
|
216
|
+
rule = described_class.new(:name => '*.doc', :group => @loguser.gid)
|
|
211
217
|
expect(rule.find).to eq([File.expand_path(doc_file)])
|
|
212
218
|
end
|
|
213
219
|
|
|
214
220
|
# TODO: Update example for Windows
|
|
215
|
-
example
|
|
221
|
+
example 'find with string group id works as expected' do
|
|
216
222
|
skip 'group example skipped on MS Windows' if windows
|
|
223
|
+
skip 'group example skipped on Mac in CI' if macos && ENV['CI']
|
|
217
224
|
|
|
218
|
-
rule =
|
|
225
|
+
rule = described_class.new(:name => '*.doc', :group => @logroup.name)
|
|
219
226
|
expect(rule.find).to eq([File.expand_path(doc_file)])
|
|
220
227
|
end
|
|
221
228
|
|
|
222
|
-
example
|
|
229
|
+
example 'find with bogus group returns empty results' do
|
|
223
230
|
skip 'group test skipped on MS Windows' if windows
|
|
224
231
|
|
|
225
|
-
rule1 =
|
|
226
|
-
rule2 =
|
|
232
|
+
rule1 = described_class.new(:name => '*.doc', :group => 'totallybogus')
|
|
233
|
+
rule2 = described_class.new(:name => '*.doc', :group => 99999999)
|
|
227
234
|
expect(rule1.find).to eq([])
|
|
228
235
|
expect(rule2.find).to eq([])
|
|
229
236
|
end
|
|
230
237
|
end
|
|
231
238
|
|
|
232
|
-
context
|
|
233
|
-
example
|
|
239
|
+
context 'inum', :inum do
|
|
240
|
+
example 'inum accessor basic functionality' do
|
|
234
241
|
expect(rule).to respond_to(:inum)
|
|
235
242
|
expect(rule).to respond_to(:inum=)
|
|
236
243
|
end
|
|
237
244
|
|
|
238
|
-
example
|
|
245
|
+
example 'inum method returns expected default value' do
|
|
239
246
|
expect(rule.inum).to be_nil
|
|
240
247
|
end
|
|
241
248
|
end
|
|
242
249
|
|
|
243
|
-
context
|
|
244
|
-
example
|
|
250
|
+
context 'follow', :follow do
|
|
251
|
+
example 'follow accessor basic functionality' do
|
|
245
252
|
expect(rule).to respond_to(:follow)
|
|
246
253
|
expect(rule).to respond_to(:follow=)
|
|
247
254
|
end
|
|
248
255
|
|
|
249
|
-
example
|
|
256
|
+
example 'follow method returns expected default value' do
|
|
250
257
|
expect(rule.follow).to be true
|
|
251
258
|
end
|
|
252
259
|
end
|
|
253
260
|
|
|
254
|
-
context
|
|
261
|
+
context 'links', :links do
|
|
255
262
|
before do
|
|
256
263
|
FileUtils.touch(ruby_file)
|
|
257
264
|
FileUtils.touch(doc_file)
|
|
258
265
|
end
|
|
259
266
|
|
|
260
|
-
example
|
|
267
|
+
example 'links accessor basic functionality' do
|
|
261
268
|
expect(rule).to respond_to(:links)
|
|
262
269
|
expect(rule).to respond_to(:links=)
|
|
263
270
|
end
|
|
264
271
|
|
|
265
|
-
example
|
|
272
|
+
example 'links method returns expected default value' do
|
|
266
273
|
expect(rule.links).to be_nil
|
|
267
274
|
end
|
|
268
275
|
|
|
269
|
-
example
|
|
270
|
-
|
|
276
|
+
example 'links method returns expected result' do
|
|
277
|
+
skip if windows # && !elevated # TODO: Adjust for drive letter.
|
|
271
278
|
|
|
272
|
-
rule1 =
|
|
273
|
-
rule2 =
|
|
279
|
+
rule1 = described_class.new(:name => '*.rb', :links => 2)
|
|
280
|
+
rule2 = described_class.new(:name => '*.doc', :links => 1)
|
|
274
281
|
|
|
275
282
|
expect(rule1.find).to eq([])
|
|
276
283
|
expect(rule2.find).to eq([File.expand_path(doc_file)])
|
|
277
284
|
end
|
|
278
285
|
end
|
|
279
286
|
|
|
280
|
-
context
|
|
287
|
+
context 'brackets', :brackets do
|
|
288
|
+
let(:file_rule){ described_class.new(:ftype => 'file', :path => ['/bracket']) }
|
|
289
|
+
let(:dir_rule){ described_class.new(:ftype => 'directory', :path => ['/bracket']) }
|
|
290
|
+
|
|
281
291
|
before do
|
|
282
292
|
allow(FakeFS::FileSystem).to receive(:find).and_call_original
|
|
283
293
|
allow(FakeFS::FileSystem).to receive(:find).with(anything, 0, false)
|
|
284
294
|
end
|
|
285
295
|
|
|
286
|
-
example
|
|
296
|
+
example 'find method works on dirs that contain brackets' do
|
|
287
297
|
skip 'dirs with brackets example skipped on MS Windows' if windows
|
|
288
298
|
|
|
289
299
|
# We use absolute paths here because of fakefs, which converts it anyway
|
|
290
|
-
bracket_files = ['/bracket/a[1]/a.foo', '/bracket/a [2] /b.foo', '/bracket/[a] b [c]/d.foo'
|
|
291
|
-
bracket_paths = ['/bracket/a[1]', '/bracket/a [2] ', '/bracket/[a] b [c]', '/bracket/[z] x'
|
|
300
|
+
bracket_files = ['/bracket/a[1]/a.foo', '/bracket/a [2] /b.foo', '/bracket/[a] b [c]/d.foo']
|
|
301
|
+
bracket_paths = ['/bracket/a[1]', '/bracket/a [2] ', '/bracket/[a] b [c]', '/bracket/[z] x']
|
|
292
302
|
|
|
293
303
|
bracket_paths.each{ |e| FakeFS::FileSystem.add(e) }
|
|
294
304
|
bracket_files.each{ |e| FileUtils.touch(e) }
|
|
295
305
|
|
|
296
|
-
file_rule = File::Find.new(
|
|
297
|
-
:ftype => 'file',
|
|
298
|
-
:path => ['/bracket']
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
dir_rule = File::Find.new(
|
|
302
|
-
:ftype => 'directory',
|
|
303
|
-
:path => ['/bracket']
|
|
304
|
-
)
|
|
305
|
-
|
|
306
306
|
file_results = file_rule.find
|
|
307
307
|
dir_results = dir_rule.find
|
|
308
308
|
|
|
@@ -311,10 +311,10 @@ RSpec.describe File::Find do
|
|
|
311
311
|
end
|
|
312
312
|
end
|
|
313
313
|
|
|
314
|
-
context
|
|
314
|
+
context 'maxdepth', :maxdepth do
|
|
315
315
|
before do
|
|
316
|
-
|
|
317
|
-
rule.pattern =
|
|
316
|
+
FakeFS::FileSystem.add('a1/a2/a3')
|
|
317
|
+
rule.pattern = '*.foo'
|
|
318
318
|
|
|
319
319
|
FileUtils.touch('a1/a.foo')
|
|
320
320
|
FileUtils.touch('a1/a2/b.foo')
|
|
@@ -324,48 +324,60 @@ RSpec.describe File::Find do
|
|
|
324
324
|
FileUtils.touch('a1/a2/a3/f.foo')
|
|
325
325
|
end
|
|
326
326
|
|
|
327
|
-
example
|
|
327
|
+
example 'maxdepth_basic' do
|
|
328
328
|
expect(rule).to respond_to(:maxdepth)
|
|
329
329
|
expect(rule).to respond_to(:maxdepth=)
|
|
330
330
|
expect(rule.maxdepth).to be_nil
|
|
331
331
|
end
|
|
332
332
|
|
|
333
|
-
example
|
|
333
|
+
example 'find with maxdepth 1 returns expected results' do
|
|
334
334
|
rule.maxdepth = 1
|
|
335
|
-
|
|
336
335
|
expect(rule.find).to eq([])
|
|
336
|
+
end
|
|
337
337
|
|
|
338
|
+
example 'find with maxdepth 2 returns expected results' do
|
|
339
|
+
pending if windows
|
|
338
340
|
rule.maxdepth = 2
|
|
339
341
|
expect(rule.find.map{ |e| File.basename(e) }).to eq(['a.foo'])
|
|
342
|
+
end
|
|
340
343
|
|
|
344
|
+
example 'find with maxdepth 3 returns expected results' do
|
|
345
|
+
pending if windows
|
|
341
346
|
rule.maxdepth = 3
|
|
342
|
-
expect(rule.find.map{ |e| File.basename(e) }).to
|
|
347
|
+
expect(rule.find.map{ |e| File.basename(e) }).to contain_exactly('a.foo', 'b.foo', 'c.foo')
|
|
343
348
|
end
|
|
344
349
|
|
|
345
|
-
example
|
|
350
|
+
example 'find with nil maxdepth option returns everything' do
|
|
351
|
+
pending if windows
|
|
346
352
|
rule.maxdepth = nil
|
|
347
353
|
results = ['a.foo', 'b.foo', 'c.foo', 'd.foo', 'e.foo', 'f.foo']
|
|
348
354
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(results)
|
|
349
355
|
end
|
|
350
356
|
|
|
351
|
-
example
|
|
352
|
-
rule.pattern =
|
|
353
|
-
|
|
357
|
+
example 'find with maxdepth 1 returns expected results for directories' do
|
|
358
|
+
rule.pattern = 'a3'
|
|
354
359
|
rule.maxdepth = 1
|
|
355
360
|
expect(rule.find).to eq([])
|
|
361
|
+
end
|
|
356
362
|
|
|
363
|
+
example 'find with maxdepth 2 returns expected results for directories' do
|
|
364
|
+
rule.pattern = 'a3'
|
|
357
365
|
rule.maxdepth = 2
|
|
358
366
|
expect(rule.find).to eq([])
|
|
367
|
+
end
|
|
359
368
|
|
|
369
|
+
example 'find with maxdepth 3 returns expected results for directories' do
|
|
370
|
+
pending if windows
|
|
371
|
+
rule.pattern = 'a3'
|
|
360
372
|
rule.maxdepth = 3
|
|
361
373
|
expect(rule.find.map{ |e| File.basename(e) }).to eq(['a3'])
|
|
362
374
|
end
|
|
363
375
|
end
|
|
364
376
|
|
|
365
|
-
context
|
|
377
|
+
context 'mindepth', :mindepth do
|
|
366
378
|
before do
|
|
367
|
-
|
|
368
|
-
rule.pattern =
|
|
379
|
+
FakeFS::FileSystem.add('a1/a2/a3')
|
|
380
|
+
rule.pattern = '*.min'
|
|
369
381
|
|
|
370
382
|
FileUtils.touch('z.min')
|
|
371
383
|
FileUtils.touch('a1/a.min')
|
|
@@ -376,52 +388,57 @@ RSpec.describe File::Find do
|
|
|
376
388
|
FileUtils.touch('a1/a2/a3/f.min')
|
|
377
389
|
end
|
|
378
390
|
|
|
379
|
-
example
|
|
391
|
+
example 'mindepth accessor basic functionality' do
|
|
380
392
|
expect(rule).to respond_to(:mindepth)
|
|
381
393
|
expect(rule).to respond_to(:mindepth=)
|
|
382
394
|
expect(rule.mindepth).to be_nil
|
|
383
395
|
end
|
|
384
396
|
|
|
385
|
-
example
|
|
397
|
+
example 'mindepth method returns expected default value' do
|
|
386
398
|
expect(rule.mindepth).to be_nil
|
|
387
399
|
end
|
|
388
400
|
|
|
389
|
-
example
|
|
401
|
+
example 'find with mindepth option returns expected results at depth 0' do
|
|
402
|
+
pending if windows
|
|
390
403
|
rule.mindepth = 0
|
|
391
404
|
array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min']
|
|
392
405
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
|
|
393
406
|
end
|
|
394
407
|
|
|
395
|
-
example
|
|
408
|
+
example 'find with mindepth option returns expected results at depth 1' do
|
|
409
|
+
pending if windows
|
|
396
410
|
rule.mindepth = 1
|
|
397
411
|
array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min']
|
|
398
412
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
|
|
399
413
|
end
|
|
400
414
|
|
|
401
|
-
example
|
|
415
|
+
example 'find with mindepth option returns expected results at depth 2' do
|
|
416
|
+
pending if windows
|
|
402
417
|
rule.mindepth = 2
|
|
403
418
|
array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min']
|
|
404
419
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
|
|
405
420
|
end
|
|
406
421
|
|
|
407
|
-
example
|
|
422
|
+
example 'find with mindepth option returns expected results at depth 3' do
|
|
423
|
+
pending if windows
|
|
408
424
|
rule.mindepth = 3
|
|
409
425
|
array = ['b.min', 'c.min', 'd.min', 'e.min', 'f.min']
|
|
410
426
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
|
|
411
427
|
end
|
|
412
428
|
|
|
413
|
-
example
|
|
429
|
+
example 'find with mindepth option returns expected results at depth 4' do
|
|
430
|
+
pending if windows
|
|
414
431
|
rule.mindepth = 4
|
|
415
432
|
array = ['d.min', 'e.min', 'f.min']
|
|
416
433
|
expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
|
|
417
434
|
end
|
|
418
435
|
|
|
419
|
-
example
|
|
436
|
+
example 'find with mindepth option returns expected results at depth 5' do
|
|
420
437
|
rule.mindepth = 5
|
|
421
438
|
expect(rule.find.map{ |e| File.basename(e) }).to eq([])
|
|
422
439
|
end
|
|
423
440
|
|
|
424
|
-
example
|
|
441
|
+
example 'find with mindepth option returns expected results for directories' do
|
|
425
442
|
rule.pattern = 'a1'
|
|
426
443
|
rule.mindepth = 1
|
|
427
444
|
|
|
@@ -435,34 +452,37 @@ RSpec.describe File::Find do
|
|
|
435
452
|
end
|
|
436
453
|
end
|
|
437
454
|
|
|
438
|
-
context
|
|
439
|
-
example
|
|
455
|
+
context 'mount', :mount do
|
|
456
|
+
example 'mount accessor basic functionality' do
|
|
440
457
|
expect(rule).to respond_to(:mount)
|
|
441
458
|
expect(rule).to respond_to(:mount=)
|
|
442
459
|
end
|
|
443
460
|
|
|
444
|
-
example
|
|
461
|
+
example 'mount method returns expected default value' do
|
|
445
462
|
expect(rule.mount).to be_nil
|
|
446
463
|
end
|
|
447
464
|
end
|
|
448
465
|
|
|
449
|
-
context
|
|
450
|
-
example
|
|
466
|
+
context 'name', :name do
|
|
467
|
+
example 'name accessor basic functionality' do
|
|
451
468
|
expect(rule).to respond_to(:name)
|
|
452
469
|
expect(rule).to respond_to(:name=)
|
|
453
470
|
end
|
|
454
471
|
|
|
455
|
-
example
|
|
472
|
+
example 'name method returns expected default value' do
|
|
456
473
|
expect(txt_rule.name).to eq('*.txt')
|
|
457
474
|
end
|
|
458
475
|
|
|
459
|
-
example
|
|
476
|
+
example 'pattern is an alias for name' do
|
|
460
477
|
expect(rule.method(:name)).to eq(rule.method(:pattern))
|
|
461
478
|
expect(rule.method(:name=)).to eq(rule.method(:pattern=))
|
|
462
479
|
end
|
|
463
480
|
end
|
|
464
481
|
|
|
465
|
-
context
|
|
482
|
+
context 'perm', :perm do
|
|
483
|
+
let(:text_file1) { 'file_find_test1.txt' }
|
|
484
|
+
let(:text_file2) { 'file_find_test2.txt' }
|
|
485
|
+
|
|
466
486
|
before do
|
|
467
487
|
FileUtils.touch(ruby_file)
|
|
468
488
|
FileUtils.touch(text_file1)
|
|
@@ -472,27 +492,27 @@ RSpec.describe File::Find do
|
|
|
472
492
|
File.chmod(0644, text_file2)
|
|
473
493
|
end
|
|
474
494
|
|
|
475
|
-
example
|
|
495
|
+
example 'perm accessor basic functionality' do
|
|
476
496
|
expect(rule).to respond_to(:perm)
|
|
477
497
|
expect(rule).to respond_to(:perm=)
|
|
478
498
|
end
|
|
479
499
|
|
|
480
|
-
example
|
|
500
|
+
example 'perm method returns expected default value' do
|
|
481
501
|
expect(rule.perm).to be_nil
|
|
482
502
|
end
|
|
483
503
|
|
|
484
|
-
example
|
|
485
|
-
results =
|
|
504
|
+
example 'perm method returns expected results' do
|
|
505
|
+
results = described_class.new(:name => '*test1*', :perm => 0644).find
|
|
486
506
|
|
|
487
507
|
expect(results.length).to eq(1)
|
|
488
508
|
expect(File.basename(results.first)).to eq(text_file1)
|
|
489
509
|
end
|
|
490
510
|
|
|
491
|
-
example
|
|
511
|
+
example 'perm method works with symbolic permissions' do
|
|
492
512
|
skip 'symbolic perm spec skipped on MS Windows' if windows
|
|
493
513
|
|
|
494
|
-
results1 =
|
|
495
|
-
results2 =
|
|
514
|
+
results1 = described_class.new(:name => 'file*', :perm => 'g=rw').find
|
|
515
|
+
results2 = described_class.new(:name => 'file*', :perm => 'u=rw').find
|
|
496
516
|
|
|
497
517
|
expect(results1.length).to eq(1)
|
|
498
518
|
expect(results2.length).to eq(2)
|
|
@@ -501,97 +521,109 @@ RSpec.describe File::Find do
|
|
|
501
521
|
end
|
|
502
522
|
end
|
|
503
523
|
|
|
504
|
-
context
|
|
524
|
+
context 'prune', :prune do
|
|
525
|
+
let(:prune_file) { 'file_find_test_prune.txt' }
|
|
526
|
+
|
|
505
527
|
before do
|
|
506
|
-
FileUtils.touch(
|
|
528
|
+
FileUtils.touch(prune_file)
|
|
507
529
|
end
|
|
508
530
|
|
|
509
|
-
example
|
|
531
|
+
example 'prune accessor basic functionality' do
|
|
510
532
|
expect(rule).to respond_to(:prune)
|
|
511
533
|
expect(rule).to respond_to(:prune=)
|
|
512
534
|
end
|
|
513
535
|
|
|
514
|
-
example
|
|
536
|
+
example 'prune method returns expected default value' do
|
|
515
537
|
expect(rule.prune).to be_nil
|
|
516
538
|
end
|
|
517
539
|
|
|
518
|
-
example
|
|
519
|
-
rule =
|
|
520
|
-
expect(File.basename(rule.find.first)).to eq(
|
|
540
|
+
example 'find method with prune option works as expected' do
|
|
541
|
+
rule = described_class.new(:name => '*.txt', :prune => 'foo')
|
|
542
|
+
expect(File.basename(rule.find.first)).to eq(prune_file)
|
|
521
543
|
end
|
|
522
544
|
end
|
|
523
545
|
|
|
524
|
-
context
|
|
525
|
-
example
|
|
546
|
+
context 'size', :size do
|
|
547
|
+
example 'size accessor basic functionality' do
|
|
526
548
|
expect(rule).to respond_to(:size)
|
|
527
549
|
expect(rule).to respond_to(:size=)
|
|
528
550
|
end
|
|
529
551
|
|
|
530
|
-
example
|
|
552
|
+
example 'size method returns expected default value' do
|
|
531
553
|
expect(rule.size).to be_nil
|
|
532
554
|
end
|
|
533
555
|
end
|
|
534
556
|
|
|
535
|
-
context
|
|
557
|
+
context 'user', :user do
|
|
536
558
|
before do
|
|
537
559
|
FileUtils.touch(doc_file)
|
|
538
560
|
end
|
|
539
561
|
|
|
540
|
-
example
|
|
562
|
+
example 'user accessor basic functionality' do
|
|
541
563
|
expect(rule).to respond_to(:user)
|
|
542
564
|
expect(rule).to respond_to(:user=)
|
|
543
565
|
end
|
|
544
566
|
|
|
545
|
-
example
|
|
567
|
+
example 'user method returns expected default value' do
|
|
546
568
|
expect(rule.user).to be_nil
|
|
547
569
|
end
|
|
548
570
|
|
|
549
|
-
example
|
|
571
|
+
example 'user method works with numeric id as expected' do
|
|
572
|
+
pending if windows # TODO: Get this working on Windows
|
|
573
|
+
skip 'user example skipped on Mac in CI' if macos && ENV['CI']
|
|
574
|
+
|
|
550
575
|
if windows && elevated
|
|
551
576
|
uid = @loguser.gid # Windows assigns the group if any member is an admin
|
|
552
577
|
else
|
|
553
578
|
uid = @loguser.uid
|
|
554
579
|
end
|
|
555
580
|
|
|
556
|
-
rule =
|
|
581
|
+
rule = described_class.new(:name => '*.doc', :user => uid)
|
|
557
582
|
expect(rule.find).to eq([File.expand_path(doc_file)])
|
|
558
583
|
end
|
|
559
584
|
|
|
560
|
-
example
|
|
585
|
+
example 'user method works with string as expected' do
|
|
586
|
+
pending if windows # TODO: Get this working on Windows
|
|
587
|
+
skip 'user example skipped on Mac in CI' if macos && ENV['CI']
|
|
588
|
+
|
|
561
589
|
skip if windows && elevated
|
|
562
|
-
rule =
|
|
590
|
+
rule = described_class.new(:name => '*.doc', :user => @loguser.name)
|
|
563
591
|
expect(rule.find).to eq([File.expand_path(doc_file)])
|
|
564
592
|
end
|
|
565
593
|
|
|
566
|
-
example
|
|
567
|
-
rule1 =
|
|
568
|
-
rule2 =
|
|
594
|
+
example 'find method with user option using invalid user returns expected results' do
|
|
595
|
+
rule1 = described_class.new(:name => '*.doc', :user => 'totallybogus')
|
|
596
|
+
rule2 = described_class.new(:name => '*.doc', :user => 99999999)
|
|
569
597
|
expect(rule1.find).to eq([])
|
|
570
598
|
expect(rule2.find).to eq([])
|
|
571
599
|
end
|
|
572
600
|
end
|
|
573
601
|
|
|
574
|
-
context
|
|
575
|
-
example
|
|
602
|
+
context 'previous', :previous do
|
|
603
|
+
example 'previous method basic functionality' do
|
|
576
604
|
expect(rule).to respond_to(:previous)
|
|
577
605
|
end
|
|
578
606
|
end
|
|
579
607
|
|
|
580
|
-
example
|
|
581
|
-
expect{
|
|
608
|
+
example 'an error is raised if the path does not exist' do
|
|
609
|
+
expect{ described_class.new(:path => '/bogus/dir').find }.to raise_error(Errno::ENOENT)
|
|
582
610
|
end
|
|
583
611
|
|
|
584
|
-
example
|
|
585
|
-
expect{
|
|
586
|
-
expect{
|
|
612
|
+
example 'an error is raised if an invalid option is passed' do
|
|
613
|
+
expect{ described_class.new(:bogus => 1) }.to raise_error(ArgumentError)
|
|
614
|
+
expect{ described_class.new(:bogus? => true) }.to raise_error(ArgumentError)
|
|
587
615
|
end
|
|
588
616
|
|
|
589
|
-
context
|
|
617
|
+
context 'eloop', :eloop do
|
|
590
618
|
# Have to disable fakefs for this test because of bug: https://github.com/fakefs/fakefs/issues/459
|
|
591
619
|
before do
|
|
592
620
|
FakeFS.deactivate!
|
|
593
621
|
end
|
|
594
622
|
|
|
623
|
+
after do
|
|
624
|
+
FakeFS.activate!
|
|
625
|
+
end
|
|
626
|
+
|
|
595
627
|
# TODO: Update example for Windows
|
|
596
628
|
example 'eloop handling works as expected' do
|
|
597
629
|
skip 'eloop handling example skipped on MS Windows' if windows
|
|
@@ -601,13 +633,9 @@ RSpec.describe File::Find do
|
|
|
601
633
|
File.symlink('eloop1', 'eloop0')
|
|
602
634
|
expected = ['./eloop0', './eloop1']
|
|
603
635
|
|
|
604
|
-
results =
|
|
636
|
+
results = described_class.new(:path => '.', :follow => true).find
|
|
605
637
|
expect(results.sort).to eq(expected)
|
|
606
638
|
end
|
|
607
639
|
end
|
|
608
|
-
|
|
609
|
-
after do
|
|
610
|
-
FakeFS.activate!
|
|
611
|
-
end
|
|
612
640
|
end
|
|
613
641
|
end
|