maid 0.9.0.alpha.2 → 0.10.0.pre.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.act-env +1 -0
- data/.act-secrets.example +2 -0
- data/.github/workflows/coverage.yml +29 -0
- data/.github/workflows/lint.yml +24 -0
- data/.github/workflows/release.yml +62 -0
- data/.github/workflows/test.yml +2 -2
- data/.gitignore +2 -0
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +35 -0
- data/.rubocop_todo.yml +372 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -1
- data/Guardfile +31 -4
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/Vagrantfile +2 -2
- data/lib/maid/app.rb +48 -51
- data/lib/maid/maid.rb +38 -38
- data/lib/maid/numeric_extensions.rb +26 -25
- data/lib/maid/platform.rb +1 -1
- data/lib/maid/rake/task.rb +1 -1
- data/lib/maid/repeat.rb +8 -8
- data/lib/maid/rule_container.rb +3 -3
- data/lib/maid/rules.sample.rb +17 -17
- data/lib/maid/tools.rb +142 -127
- data/lib/maid/trash_migration.rb +4 -4
- data/lib/maid/user_agent.rb +2 -2
- data/lib/maid/version.rb +5 -2
- data/lib/maid/watch.rb +10 -12
- data/maid.gemspec +36 -18
- data/spec/dependency_spec.rb +9 -8
- data/spec/lib/maid/app_spec.rb +31 -23
- data/spec/lib/maid/maid_spec.rb +74 -52
- data/spec/lib/maid/numeric_extensions_spec.rb +1 -1
- data/spec/lib/maid/platform_spec.rb +1 -1
- data/spec/lib/maid/rake/single_rule_spec.rb +11 -6
- data/spec/lib/maid/rake/task_spec.rb +3 -5
- data/spec/lib/maid/rule_spec.rb +1 -1
- data/spec/lib/maid/tools_spec.rb +94 -92
- data/spec/lib/maid/trash_migration_spec.rb +12 -11
- data/spec/lib/maid/user_agent_spec.rb +5 -4
- data/spec/lib/maid_spec.rb +1 -1
- data/spec/spec_helper.rb +19 -3
- metadata +177 -61
@@ -2,18 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Maid
|
4
4
|
module Rake
|
5
|
-
describe SingleRule do
|
5
|
+
describe SingleRule, fakefs: true do
|
6
6
|
subject(:single_rule) { described_class.new name, task }
|
7
7
|
let(:name) { double(:rule_description) }
|
8
|
-
let(:task) {
|
8
|
+
let(:task) { proc {} }
|
9
|
+
|
10
|
+
before do
|
11
|
+
logfile = File.join('~', '.maid', 'maid.log')
|
12
|
+
FileUtils.mkdir_p(File.expand_path(File.dirname(logfile)))
|
13
|
+
FileUtils.touch(File.expand_path(logfile))
|
14
|
+
end
|
9
15
|
|
10
16
|
describe '#initialize' do
|
11
17
|
it 'has a name' do
|
12
|
-
expect(single_rule.name).
|
18
|
+
expect(single_rule.name).to eq(name)
|
13
19
|
end
|
14
20
|
|
15
21
|
it 'has a task' do
|
16
|
-
expect(single_rule.task).
|
22
|
+
expect(single_rule.task).to eq(task)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
@@ -68,7 +74,7 @@ module Maid
|
|
68
74
|
describe '.perform' do
|
69
75
|
subject(:perform) { described_class.perform name, task }
|
70
76
|
let(:name) { double(:name) }
|
71
|
-
let(:task) {
|
77
|
+
let(:task) { proc {} }
|
72
78
|
|
73
79
|
it 'creates an instance' do
|
74
80
|
expect(described_class)
|
@@ -92,7 +98,6 @@ module Maid
|
|
92
98
|
end
|
93
99
|
end
|
94
100
|
end
|
95
|
-
|
96
101
|
end
|
97
102
|
end
|
98
103
|
end
|
@@ -3,11 +3,10 @@ require 'spec_helper'
|
|
3
3
|
module Maid
|
4
4
|
module Rake
|
5
5
|
describe Task do
|
6
|
-
|
7
6
|
before(:all) { ::Rake::TaskManager.record_task_metadata = true }
|
8
7
|
|
9
|
-
subject(:define_task) { described_class.new
|
10
|
-
let(:instructions) {
|
8
|
+
subject(:define_task) { described_class.new(*args, &instructions) }
|
9
|
+
let(:instructions) { proc {} }
|
11
10
|
|
12
11
|
describe '#initialize' do
|
13
12
|
before { ::Rake::Task.clear }
|
@@ -36,7 +35,7 @@ module Maid
|
|
36
35
|
end
|
37
36
|
|
38
37
|
context 'given a description argument' do
|
39
|
-
let(:args) { [:foobar, description: 'Custom description'] }
|
38
|
+
let(:args) { [:foobar, { description: 'Custom description' }] }
|
40
39
|
|
41
40
|
it 'defines a rake task with the description provided' do
|
42
41
|
define_task
|
@@ -45,7 +44,6 @@ module Maid
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
data/spec/lib/maid/rule_spec.rb
CHANGED
data/spec/lib/maid/tools_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
module Maid
|
@@ -7,7 +6,7 @@ module Maid
|
|
7
6
|
# More info:
|
8
7
|
#
|
9
8
|
# * [FakeFS](https://github.com/defunkt/fakefs)
|
10
|
-
describe Tools, :
|
9
|
+
describe Tools, fakefs: true do
|
11
10
|
before do
|
12
11
|
@home = File.expand_path('~')
|
13
12
|
@now = Time.now
|
@@ -15,13 +14,13 @@ module Maid
|
|
15
14
|
expect(Maid.ancestors).to include(Tools)
|
16
15
|
|
17
16
|
@logger = double('Logger').as_null_object
|
18
|
-
@maid = Maid.new(:
|
17
|
+
@maid = Maid.new(logger: @logger)
|
19
18
|
|
20
19
|
# Prevent warnings from showing when testing deprecated methods:
|
21
|
-
@maid.
|
20
|
+
allow(@maid).to receive(:__deprecated_run_action__)
|
22
21
|
|
23
22
|
# For safety, stub `cmd` to prevent running commands:
|
24
|
-
@maid.
|
23
|
+
allow(@maid).to receive(:cmd)
|
25
24
|
end
|
26
25
|
|
27
26
|
describe '#move' do
|
@@ -47,7 +46,8 @@ module Maid
|
|
47
46
|
@maid.move(@src_file, @dst_dir)
|
48
47
|
end
|
49
48
|
|
50
|
-
|
49
|
+
# FIXME: Example is too long, shouldn't need the rubocop::disable
|
50
|
+
it 'handles multiple from paths' do # rubocop:disable RSpec/ExampleLength
|
51
51
|
second_file_name = 'bar.zip'
|
52
52
|
second_src_file = File.join(@src_dir, second_file_name)
|
53
53
|
FileUtils.touch(File.expand_path(second_src_file))
|
@@ -69,7 +69,7 @@ module Maid
|
|
69
69
|
expect(FileUtils).not_to receive(:mv)
|
70
70
|
expect(@logger).to receive(:warn).once
|
71
71
|
|
72
|
-
another_file = "
|
72
|
+
another_file = "#{@src_file}.1"
|
73
73
|
@maid.move([@src_file, another_file], @dst_dir)
|
74
74
|
end
|
75
75
|
end
|
@@ -80,11 +80,11 @@ module Maid
|
|
80
80
|
@src_file = (@src_dir = '~/Source/') + (@file_name = 'foo.zip')
|
81
81
|
FileUtils.mkdir_p(File.expand_path(@src_dir))
|
82
82
|
FileUtils.touch(File.expand_path(@src_file))
|
83
|
-
@expanded_src_name = "
|
83
|
+
@expanded_src_name = "#{@home}/Source/foo.zip"
|
84
84
|
|
85
85
|
@dst_name = '~/Destination/bar.zip'
|
86
|
-
@expanded_dst_dir = "
|
87
|
-
@expanded_dst_name = "
|
86
|
+
@expanded_dst_dir = "#{@home}/Destination/"
|
87
|
+
@expanded_dst_name = "#{@home}/Destination/bar.zip"
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'creates needed directories' do
|
@@ -156,15 +156,15 @@ module Maid
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'removes files greater then the remove option size' do
|
159
|
-
@maid.
|
160
|
-
@maid.trash(@src_file, :
|
159
|
+
allow(@maid).to receive(:disk_usage).and_return(1025)
|
160
|
+
@maid.trash(@src_file, remove_over: 1.mb)
|
161
161
|
expect(File.exist?(@src_file)).not_to be(true)
|
162
162
|
expect(File.exist?(@trash_file)).not_to be(true)
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'trashes files less then the remove option size' do
|
166
|
-
@maid.
|
167
|
-
@maid.trash(@src_file, :
|
166
|
+
allow(@maid).to receive(:disk_usage).and_return(1023)
|
167
|
+
@maid.trash(@src_file, remove_over: 1.mb)
|
168
168
|
expect(File.exist?(@trash_file)).to be(true)
|
169
169
|
end
|
170
170
|
end
|
@@ -189,15 +189,15 @@ module Maid
|
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'sets the secure option' do
|
192
|
-
@options = @maid.file_options.merge(:
|
192
|
+
@options = @maid.file_options.merge(secure: true)
|
193
193
|
expect(FileUtils).to receive(:rm_r).with(File.expand_path(@src_file), @options)
|
194
|
-
@maid.remove(@src_file, :
|
194
|
+
@maid.remove(@src_file, secure: true)
|
195
195
|
end
|
196
196
|
|
197
197
|
it 'sets the force option' do
|
198
|
-
@options = @maid.file_options.merge(:
|
198
|
+
@options = @maid.file_options.merge(force: true)
|
199
199
|
expect(FileUtils).to receive(:rm_r).with(File.expand_path(@src_file), @options)
|
200
|
-
@maid.remove(@src_file, :
|
200
|
+
@maid.remove(@src_file, force: true)
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'handles multiple paths' do
|
@@ -213,7 +213,7 @@ module Maid
|
|
213
213
|
|
214
214
|
describe '#dir' do
|
215
215
|
before do
|
216
|
-
@file = (@dir = "
|
216
|
+
@file = (@dir = "#{@home}/Downloads") + '/foo.zip'
|
217
217
|
FileUtils.mkdir_p(@dir)
|
218
218
|
end
|
219
219
|
|
@@ -225,19 +225,19 @@ module Maid
|
|
225
225
|
it 'lists multiple files in alphabetical order' do
|
226
226
|
# It doesn't occur with `FakeFS` as far as I can tell, but Ubuntu (and possibly OS X) can give the results out
|
227
227
|
# of lexical order. That makes using the `dry-run` output difficult to use.
|
228
|
-
Dir.
|
229
|
-
expect(@maid.dir('~/Downloads/*.zip')).to eq(%w
|
228
|
+
allow(Dir).to receive(:glob).and_return(%w[/home/foo/b.zip /home/foo/a.zip /home/foo/c.zip])
|
229
|
+
expect(@maid.dir('~/Downloads/*.zip')).to eq(%w[/home/foo/a.zip /home/foo/b.zip /home/foo/c.zip])
|
230
230
|
end
|
231
231
|
|
232
232
|
context 'with multiple files' do
|
233
233
|
before do
|
234
|
-
@other_file = "
|
234
|
+
@other_file = "#{@dir}/qux.tgz"
|
235
235
|
FileUtils.touch(@file)
|
236
236
|
FileUtils.touch(@other_file)
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'list files in all provided globs' do
|
240
|
-
expect(@maid.dir(%w
|
240
|
+
expect(@maid.dir(%w[~/Downloads/*.tgz ~/Downloads/*.zip])).to eq([@file, @other_file])
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'lists files when using regexp-like glob patterns' do
|
@@ -247,7 +247,7 @@ module Maid
|
|
247
247
|
|
248
248
|
context 'with multiple directories' do
|
249
249
|
before do
|
250
|
-
@other_file = "
|
250
|
+
@other_file = "#{@home}/Desktop/bar.zip"
|
251
251
|
FileUtils.touch(@file)
|
252
252
|
FileUtils.mkdir_p(File.dirname(@other_file))
|
253
253
|
FileUtils.touch(@other_file)
|
@@ -265,7 +265,7 @@ module Maid
|
|
265
265
|
|
266
266
|
describe '#files' do
|
267
267
|
before do
|
268
|
-
@file = (@dir = "
|
268
|
+
@file = (@dir = "#{@home}/Downloads") + '/foo.zip'
|
269
269
|
FileUtils.mkdir_p(@dir)
|
270
270
|
FileUtils.mkdir(@dir + '/notfile')
|
271
271
|
end
|
@@ -278,19 +278,19 @@ module Maid
|
|
278
278
|
it 'lists multiple files in alphabetical order' do
|
279
279
|
# It doesn't occur with `FakeFS` as far as I can tell, but Ubuntu (and possibly OS X) can give the results out
|
280
280
|
# of lexical order. That makes using the `dry-run` output difficult to use.
|
281
|
-
Dir.
|
282
|
-
expect(@maid.dir('~/Downloads/*.zip')).to eq(%w
|
281
|
+
allow(Dir).to receive(:glob).and_return(%w[/home/foo/b.zip /home/foo/a.zip /home/foo/c.zip])
|
282
|
+
expect(@maid.dir('~/Downloads/*.zip')).to eq(%w[/home/foo/a.zip /home/foo/b.zip /home/foo/c.zip])
|
283
283
|
end
|
284
284
|
|
285
285
|
context 'with multiple files' do
|
286
286
|
before do
|
287
|
-
@other_file = "
|
287
|
+
@other_file = "#{@dir}/qux.tgz"
|
288
288
|
FileUtils.touch(@file)
|
289
289
|
FileUtils.touch(@other_file)
|
290
290
|
end
|
291
291
|
|
292
292
|
it 'list files in all provided globs' do
|
293
|
-
expect(@maid.dir(%w
|
293
|
+
expect(@maid.dir(%w[~/Downloads/*.tgz ~/Downloads/*.zip])).to eq([@file, @other_file])
|
294
294
|
end
|
295
295
|
|
296
296
|
it 'lists files when using regexp-like glob patterns' do
|
@@ -300,7 +300,7 @@ module Maid
|
|
300
300
|
|
301
301
|
context 'with multiple directories' do
|
302
302
|
before do
|
303
|
-
@other_file = "
|
303
|
+
@other_file = "#{@home}/Desktop/bar.zip"
|
304
304
|
FileUtils.touch(@file)
|
305
305
|
FileUtils.mkdir_p(File.dirname(@other_file))
|
306
306
|
FileUtils.mkdir(@home + '/Desktop/notfile')
|
@@ -322,7 +322,7 @@ module Maid
|
|
322
322
|
describe '#mkdir' do
|
323
323
|
it 'creates a directory successfully' do
|
324
324
|
@maid.mkdir('~/Downloads/Music/Pink.Floyd')
|
325
|
-
expect(File.exist?("
|
325
|
+
expect(File.exist?("#{@home}/Downloads/Music/Pink.Floyd")).to be(true)
|
326
326
|
end
|
327
327
|
|
328
328
|
it 'logs the creation of the directory' do
|
@@ -331,7 +331,7 @@ module Maid
|
|
331
331
|
end
|
332
332
|
|
333
333
|
it 'returns the path of the created directory' do
|
334
|
-
expect(@maid.mkdir('~/Reference/Foo')).to eq("
|
334
|
+
expect(@maid.mkdir('~/Reference/Foo')).to eq("#{@home}/Reference/Foo")
|
335
335
|
end
|
336
336
|
|
337
337
|
# FIXME: FakeFS doesn't seem to report `File.exist?` properly. However, this has been tested manually.
|
@@ -354,13 +354,13 @@ module Maid
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it 'delegates to Find.find with an expanded path' do
|
357
|
-
f =
|
357
|
+
f = ->(arg) {}
|
358
358
|
expect(Find).to receive(:find).with(@file_expand_path, &f)
|
359
359
|
@maid.find(@file, &f)
|
360
360
|
end
|
361
361
|
|
362
362
|
it "returns an array of all the files' names when no block is given" do
|
363
|
-
expect(@maid.find(@dir)).to
|
363
|
+
expect(@maid.find(@dir)).to contain_exactly(@dir_expand_path, @file_expand_path)
|
364
364
|
end
|
365
365
|
end
|
366
366
|
|
@@ -373,7 +373,7 @@ module Maid
|
|
373
373
|
|
374
374
|
describe '#downloaded_from' do
|
375
375
|
before do
|
376
|
-
Platform.
|
376
|
+
allow(Platform).to receive(:osx?).and_return(true)
|
377
377
|
end
|
378
378
|
|
379
379
|
it 'determines the download site' do
|
@@ -396,7 +396,7 @@ module Maid
|
|
396
396
|
end
|
397
397
|
|
398
398
|
it 'detects when downloading in Safari' do
|
399
|
-
expect(@maid.downloading?('foo.zip.download')).to be
|
399
|
+
expect(@maid.downloading?('foo.zip.download')).to be(true)
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
@@ -409,8 +409,8 @@ module Maid
|
|
409
409
|
|
410
410
|
describe '#zipfile_contents' do
|
411
411
|
it 'inspects the contents of a .zip file' do
|
412
|
-
entries = [double(:
|
413
|
-
Zip::File.
|
412
|
+
entries = [double(name: 'foo.exe'), double(name: 'README.txt'), double(name: 'subdir/anything.txt')]
|
413
|
+
allow(Zip::File).to receive(:open).and_yield(entries)
|
414
414
|
|
415
415
|
expect(@maid.zipfile_contents('foo.zip')).to eq(['README.txt', 'foo.exe', 'subdir/anything.txt'])
|
416
416
|
end
|
@@ -425,14 +425,14 @@ module Maid
|
|
425
425
|
context 'when the file does not exist' do
|
426
426
|
it 'raises an error' do
|
427
427
|
expect(@maid).to receive(:cmd).and_return('du: cannot access `foo.zip\': No such file or directory')
|
428
|
-
expect
|
428
|
+
expect { @maid.disk_usage('foo.zip') }.to raise_error(RuntimeError)
|
429
429
|
end
|
430
430
|
end
|
431
431
|
end
|
432
432
|
|
433
433
|
describe '#created_at' do
|
434
434
|
before do
|
435
|
-
@path =
|
435
|
+
@path = '~/test.txt'
|
436
436
|
end
|
437
437
|
|
438
438
|
it 'gives the created time of the file' do
|
@@ -446,12 +446,12 @@ module Maid
|
|
446
446
|
describe '#accessed_at' do
|
447
447
|
# FakeFS does not implement atime.
|
448
448
|
it 'gives the last accessed time of the file' do
|
449
|
-
expect(File).to receive(:atime).with("
|
449
|
+
expect(File).to receive(:atime).with("#{@home}/foo.zip").and_return(@now)
|
450
450
|
expect(@maid.accessed_at('~/foo.zip')).to eq(@now)
|
451
451
|
end
|
452
452
|
|
453
453
|
it 'triggers deprecation warning when last_accessed is used, but still run' do
|
454
|
-
expect(File).to receive(:atime).with("
|
454
|
+
expect(File).to receive(:atime).with("#{@home}/foo.zip").and_return(@now)
|
455
455
|
expect(@maid).to have_deprecated_method(:last_accessed)
|
456
456
|
expect(@maid.last_accessed('~/foo.zip')).to eq(@now)
|
457
457
|
end
|
@@ -465,7 +465,7 @@ module Maid
|
|
465
465
|
|
466
466
|
it 'gives the modified time of the file' do
|
467
467
|
Timecop.freeze(@now) do
|
468
|
-
File.
|
468
|
+
File.write(File.expand_path(@path), 'Test')
|
469
469
|
end
|
470
470
|
|
471
471
|
# use to_i to ignore milliseconds during test
|
@@ -502,7 +502,7 @@ module Maid
|
|
502
502
|
end
|
503
503
|
|
504
504
|
it 'ands pushes the given git repository, logging the action' do
|
505
|
-
expect(@maid).to receive(:cmd).with(%(cd
|
505
|
+
expect(@maid).to receive(:cmd).with(%(cd #{@home}/code/projectname && git pull && git push 2>&1))
|
506
506
|
expect(@logger).to receive(:info)
|
507
507
|
@maid.git_piston('~/code/projectname')
|
508
508
|
end
|
@@ -515,7 +515,7 @@ module Maid
|
|
515
515
|
end
|
516
516
|
|
517
517
|
it 'syncs the expanded paths, retaining backslash' do
|
518
|
-
expect(@maid).to receive(:cmd).with(%(rsync -a -u
|
518
|
+
expect(@maid).to receive(:cmd).with(%(rsync -a -u #{@home}/Downloads/ #{@home}/Reference 2>&1))
|
519
519
|
@maid.sync(@src_dir, @dst_dir)
|
520
520
|
end
|
521
521
|
|
@@ -525,19 +525,20 @@ module Maid
|
|
525
525
|
end
|
526
526
|
|
527
527
|
it 'has no options' do
|
528
|
-
expect(@maid).to receive(:cmd).with(%(rsync
|
529
|
-
@maid.sync(@src_dir, @dst_dir, :
|
528
|
+
expect(@maid).to receive(:cmd).with(%(rsync #{@home}/Downloads/ #{@home}/Reference 2>&1))
|
529
|
+
@maid.sync(@src_dir, @dst_dir, archive: false, update: false)
|
530
530
|
end
|
531
531
|
|
532
532
|
it 'adds all options' do
|
533
|
-
expect(@maid).to receive(:cmd).with(%(rsync -a -v -u -m --exclude=.git --delete
|
534
|
-
@maid.sync(@src_dir, @dst_dir, :
|
533
|
+
expect(@maid).to receive(:cmd).with(%(rsync -a -v -u -m --exclude=.git --delete #{@home}/Downloads/ #{@home}/Reference 2>&1)) # rubocop:disable Layout/LineLength
|
534
|
+
@maid.sync(@src_dir, @dst_dir, archive: true, update: true, delete: true, verbose: true,
|
535
|
+
prune_empty: true, exclude: '.git',)
|
535
536
|
end
|
536
537
|
|
537
538
|
it 'adds multiple exlcude options' do
|
538
|
-
expect(@maid).to receive(:cmd)
|
539
|
-
with(%(rsync -a -u --exclude=.git --exclude=.rvmrc
|
540
|
-
@maid.sync(@src_dir, @dst_dir, :
|
539
|
+
expect(@maid).to receive(:cmd)
|
540
|
+
.with(%(rsync -a -u --exclude=.git --exclude=.rvmrc #{@home}/Downloads/ #{@home}/Reference 2>&1))
|
541
|
+
@maid.sync(@src_dir, @dst_dir, exclude: ['.git', '.rvmrc'])
|
541
542
|
end
|
542
543
|
|
543
544
|
context 'when file_options[:noop] is true' do
|
@@ -552,7 +553,7 @@ module Maid
|
|
552
553
|
end
|
553
554
|
|
554
555
|
it 'adds noop option' do
|
555
|
-
expect(@maid).to receive(:cmd).with(%(rsync -a -u -n
|
556
|
+
expect(@maid).to receive(:cmd).with(%(rsync -a -u -n #{@home}/Downloads/ #{@home}/Reference 2>&1))
|
556
557
|
@maid.sync(@src_dir, @dst_dir)
|
557
558
|
end
|
558
559
|
end
|
@@ -606,24 +607,24 @@ module Maid
|
|
606
607
|
end
|
607
608
|
end
|
608
609
|
|
609
|
-
describe Tools, :
|
610
|
+
describe Tools, fakefs: false do
|
610
611
|
let(:file_fixtures_path) { File.expand_path(File.dirname(__FILE__) + '../../../fixtures/files/') }
|
611
|
-
let(:file_fixtures_glob) { "#{
|
612
|
+
let(:file_fixtures_glob) { "#{file_fixtures_path}/*" }
|
612
613
|
let(:image_path) { File.join(file_fixtures_path, 'ruby.jpg') }
|
613
614
|
let(:unknown_path) { File.join(file_fixtures_path, 'unknown.foo') }
|
614
615
|
|
615
616
|
before do
|
616
617
|
@logger = double('Logger').as_null_object
|
617
|
-
@maid = Maid.new(:
|
618
|
+
@maid = Maid.new(logger: @logger)
|
618
619
|
end
|
619
620
|
|
620
621
|
describe '#dupes_in' do
|
621
622
|
it 'lists duplicate files in arrays' do
|
622
623
|
dupes = @maid.dupes_in(file_fixtures_glob)
|
623
|
-
expect(dupes.first).to
|
624
|
+
expect(dupes.first).to be_a(Array)
|
624
625
|
|
625
626
|
basenames = dupes.flatten.map { |p| File.basename(p) }
|
626
|
-
expect(basenames).to eq(%w
|
627
|
+
expect(basenames).to eq(%w[1.zip bar.zip foo.zip])
|
627
628
|
end
|
628
629
|
end
|
629
630
|
|
@@ -632,7 +633,7 @@ module Maid
|
|
632
633
|
dupes = @maid.verbose_dupes_in(file_fixtures_glob)
|
633
634
|
|
634
635
|
basenames = dupes.flatten.map { |p| File.basename(p) }
|
635
|
-
expect(basenames).to eq(%w
|
636
|
+
expect(basenames).to eq(%w[bar.zip foo.zip])
|
636
637
|
end
|
637
638
|
end
|
638
639
|
|
@@ -649,7 +650,7 @@ module Maid
|
|
649
650
|
dupes = @maid.newest_dupes_in(file_fixtures_glob)
|
650
651
|
|
651
652
|
basenames = dupes.flatten.map { |p| File.basename(p) }
|
652
|
-
expect(basenames).to match_array(%w
|
653
|
+
expect(basenames).to match_array(%w[bar.zip 1.zip])
|
653
654
|
end
|
654
655
|
end
|
655
656
|
|
@@ -750,7 +751,8 @@ module Maid
|
|
750
751
|
end
|
751
752
|
|
752
753
|
describe '#ignore_child_dirs' do
|
753
|
-
|
754
|
+
# FIXME: Example is too long, shouldn't need the rubocop::disable
|
755
|
+
it 'filters out any child directory' do # rubocop:disable RSpec/ExampleLength
|
754
756
|
src = [
|
755
757
|
'a',
|
756
758
|
'b',
|
@@ -787,15 +789,15 @@ module Maid
|
|
787
789
|
end
|
788
790
|
end
|
789
791
|
|
790
|
-
describe 'OSX tag support', :
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
792
|
+
describe 'OSX tag support', fakefs: false do
|
793
|
+
let(:test_file) { '~/.maid/test/tag.zip' }
|
794
|
+
let(:test_dir) { File.dirname(test_file) }
|
795
|
+
let(:file_name) { File.basename(test_file) }
|
796
|
+
let(:original_file_options) { @maid.file_options.clone }
|
795
797
|
|
796
798
|
before do
|
797
799
|
@logger = double('Logger').as_null_object
|
798
|
-
@maid = Maid.new(:
|
800
|
+
@maid = Maid.new(logger: @logger)
|
799
801
|
|
800
802
|
FileUtils.mkdir_p(test_dir)
|
801
803
|
FileUtils.touch(test_file)
|
@@ -808,27 +810,27 @@ module Maid
|
|
808
810
|
end
|
809
811
|
|
810
812
|
describe '#tags' do
|
811
|
-
it 'returns tags from a file that has one' do
|
813
|
+
it 'returns tags from a file that has one' do
|
812
814
|
if Platform.has_tag_available?
|
813
815
|
@maid.file_options[:noop] = false
|
814
|
-
@maid.add_tag(test_file,
|
815
|
-
expect(@maid.tags(test_file)).to eq([
|
816
|
+
@maid.add_tag(test_file, 'Test')
|
817
|
+
expect(@maid.tags(test_file)).to eq(['Test'])
|
816
818
|
end
|
817
819
|
end
|
818
820
|
|
819
821
|
it 'returns tags from a file that has serveral tags' do
|
820
822
|
if Platform.has_tag_available?
|
821
823
|
@maid.file_options[:noop] = false
|
822
|
-
@maid.add_tag(test_file, [
|
823
|
-
expect(@maid.tags(test_file)).to eq([
|
824
|
+
@maid.add_tag(test_file, %w[Test Twice])
|
825
|
+
expect(@maid.tags(test_file)).to eq(%w[Test Twice])
|
824
826
|
end
|
825
827
|
end
|
826
828
|
end
|
827
829
|
|
828
830
|
describe '#has_tags?' do
|
829
|
-
it 'returns true for a file with tags' do
|
831
|
+
it 'returns true for a file with tags' do
|
830
832
|
if Platform.has_tag_available?
|
831
|
-
@maid.add_tag(test_file,
|
833
|
+
@maid.add_tag(test_file, 'Test')
|
832
834
|
expect(@maid.has_tags?(test_file)).to be(true)
|
833
835
|
end
|
834
836
|
end
|
@@ -839,43 +841,43 @@ module Maid
|
|
839
841
|
end
|
840
842
|
|
841
843
|
describe '#contains_tag?' do
|
842
|
-
it 'returns true a file with the given tag' do
|
844
|
+
it 'returns true a file with the given tag' do
|
843
845
|
if Platform.has_tag_available?
|
844
|
-
@maid.add_tag(test_file,
|
845
|
-
expect(@maid.contains_tag?(test_file,
|
846
|
-
expect(@maid.contains_tag?(test_file,
|
846
|
+
@maid.add_tag(test_file, 'Test')
|
847
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(true)
|
848
|
+
expect(@maid.contains_tag?(test_file, 'Not there')).to be(false)
|
847
849
|
end
|
848
850
|
end
|
849
851
|
end
|
850
852
|
|
851
853
|
describe '#add_tag' do
|
852
|
-
it 'adds the given tag to a file' do
|
854
|
+
it 'adds the given tag to a file' do
|
853
855
|
if Platform.has_tag_available?
|
854
|
-
@maid.add_tag(test_file,
|
855
|
-
expect(@maid.contains_tag?(test_file,
|
856
|
+
@maid.add_tag(test_file, 'Test')
|
857
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(true)
|
856
858
|
end
|
857
859
|
end
|
858
860
|
end
|
859
861
|
|
860
862
|
describe '#remove_tag' do
|
861
|
-
it 'removes the given tag from a file' do
|
863
|
+
it 'removes the given tag from a file' do
|
862
864
|
if Platform.has_tag_available?
|
863
|
-
@maid.add_tag(test_file,
|
864
|
-
expect(@maid.contains_tag?(test_file,
|
865
|
-
@maid.remove_tag(test_file,
|
866
|
-
expect(@maid.contains_tag?(test_file,
|
865
|
+
@maid.add_tag(test_file, 'Test')
|
866
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(true)
|
867
|
+
@maid.remove_tag(test_file, 'Test')
|
868
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(false)
|
867
869
|
end
|
868
870
|
end
|
869
871
|
end
|
870
872
|
|
871
873
|
describe '#set_tag' do
|
872
|
-
it 'sets the given tags on a file' do
|
874
|
+
it 'sets the given tags on a file' do
|
873
875
|
if Platform.has_tag_available?
|
874
|
-
@maid.set_tag(test_file,
|
875
|
-
expect(@maid.contains_tag?(test_file,
|
876
|
-
@maid.set_tag(test_file, [
|
877
|
-
expect(@maid.contains_tag?(test_file,
|
878
|
-
expect(@maid.contains_tag?(test_file,
|
876
|
+
@maid.set_tag(test_file, 'Test')
|
877
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(true)
|
878
|
+
@maid.set_tag(test_file, %w[Test Twice])
|
879
|
+
expect(@maid.contains_tag?(test_file, 'Test')).to be(true)
|
880
|
+
expect(@maid.contains_tag?(test_file, 'Twice')).to be(true)
|
879
881
|
end
|
880
882
|
end
|
881
883
|
end
|