maid 0.10.0.pre.alpha.1 → 0.10.0.pre.alpha.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.
@@ -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, :fakefs => true do
9
+ describe Tools, fakefs: true do
11
10
  before do
12
11
  @home = File.expand_path('~')
13
12
  @now = Time.now
@@ -15,7 +14,7 @@ module Maid
15
14
  expect(Maid.ancestors).to include(Tools)
16
15
 
17
16
  @logger = double('Logger').as_null_object
18
- @maid = Maid.new(:logger => @logger)
17
+ @maid = Maid.new(logger: @logger)
19
18
 
20
19
  # Prevent warnings from showing when testing deprecated methods:
21
20
  allow(@maid).to receive(:__deprecated_run_action__)
@@ -47,7 +46,8 @@ module Maid
47
46
  @maid.move(@src_file, @dst_dir)
48
47
  end
49
48
 
50
- it 'handles multiple from paths' do
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 = "#@src_file.1"
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 = "#@home/Source/foo.zip"
83
+ @expanded_src_name = "#{@home}/Source/foo.zip"
84
84
 
85
85
  @dst_name = '~/Destination/bar.zip'
86
- @expanded_dst_dir = "#@home/Destination/"
87
- @expanded_dst_name = "#@home/Destination/bar.zip"
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
@@ -157,14 +157,14 @@ module Maid
157
157
 
158
158
  it 'removes files greater then the remove option size' do
159
159
  allow(@maid).to receive(:disk_usage).and_return(1025)
160
- @maid.trash(@src_file, :remove_over => 1.mb)
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
166
  allow(@maid).to receive(:disk_usage).and_return(1023)
167
- @maid.trash(@src_file, :remove_over => 1.mb)
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(:secure => true)
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, :secure => true)
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(:force => true)
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, :force => true)
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 = "#@home/Downloads") + '/foo.zip'
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
- 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))
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 = "#@dir/qux.tgz"
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(~/Downloads/*.tgz ~/Downloads/*.zip))).to eq([@file, @other_file])
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 = "#@home/Desktop/bar.zip"
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 = "#@home/Downloads") + '/foo.zip'
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
- 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))
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 = "#@dir/qux.tgz"
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(~/Downloads/*.tgz ~/Downloads/*.zip))).to eq([@file, @other_file])
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 = "#@home/Desktop/bar.zip"
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?("#@home/Downloads/Music/Pink.Floyd")).to be(true)
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("#@home/Reference/Foo")
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 = lambda { |arg| }
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 match_array([@dir_expand_path, @file_expand_path])
363
+ expect(@maid.find(@dir)).to contain_exactly(@dir_expand_path, @file_expand_path)
364
364
  end
365
365
  end
366
366
 
@@ -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 (true)
399
+ expect(@maid.downloading?('foo.zip.download')).to be(true)
400
400
  end
401
401
  end
402
402
 
@@ -409,7 +409,7 @@ module Maid
409
409
 
410
410
  describe '#zipfile_contents' do
411
411
  it 'inspects the contents of a .zip file' do
412
- entries = [double(:name => 'foo.exe'), double(:name => 'README.txt'), double(:name => 'subdir/anything.txt')]
412
+ entries = [double(name: 'foo.exe'), double(name: 'README.txt'), double(name: 'subdir/anything.txt')]
413
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'])
@@ -432,7 +432,7 @@ module Maid
432
432
 
433
433
  describe '#created_at' do
434
434
  before do
435
- @path = "~/test.txt"
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("#@home/foo.zip").and_return(@now)
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("#@home/foo.zip").and_return(@now)
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.open(File.expand_path(@path), 'w') { |f| f.write('Test') }
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 #@home/code/projectname && git pull && git push 2>&1))
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 #@home/Downloads/ #@home/Reference 2>&1))
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 #@home/Downloads/ #@home/Reference 2>&1))
529
- @maid.sync(@src_dir, @dst_dir, :archive => false, :update => false)
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 #@home/Downloads/ #@home/Reference 2>&1))
534
- @maid.sync(@src_dir, @dst_dir, :archive => true, :update => true, :delete => true, :verbose => true, :prune_empty => true, :exclude => '.git')
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 #@home/Downloads/ #@home/Reference 2>&1))
540
- @maid.sync(@src_dir, @dst_dir, :exclude => ['.git', '.rvmrc'])
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 #@home/Downloads/ #@home/Reference 2>&1))
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, :fakefs => false do
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) { "#{ file_fixtures_path }/*" }
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(:logger => @logger)
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 be_kind_of(Array)
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(1.zip bar.zip foo.zip))
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(bar.zip foo.zip))
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(bar.zip 1.zip))
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
- it 'filters out any child directory' do
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', :fakefs => false do
791
- let(:test_file) { '~/.maid/test/tag.zip' }
792
- let(:test_dir) { File.dirname(test_file) }
793
- let(:file_name) { File.basename(test_file) }
794
- let(:original_file_options) { @maid.file_options.clone }
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(:logger => @logger)
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, "Test")
815
- expect(@maid.tags(test_file)).to eq(["Test"])
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, ["Test", "Twice"])
823
- expect(@maid.tags(test_file)).to eq(["Test", "Twice"])
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, "Test")
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, "Test")
845
- expect(@maid.contains_tag?(test_file, "Test")).to be(true)
846
- expect(@maid.contains_tag?(test_file, "Not there")).to be(false)
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, "Test")
855
- expect(@maid.contains_tag?(test_file, "Test")).to be(true)
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, "Test")
864
- expect(@maid.contains_tag?(test_file, "Test")).to be(true)
865
- @maid.remove_tag(test_file, "Test")
866
- expect(@maid.contains_tag?(test_file, "Test")).to be(false)
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, "Test")
875
- expect(@maid.contains_tag?(test_file, "Test")).to be(true)
876
- @maid.set_tag(test_file, ["Test", "Twice"])
877
- expect(@maid.contains_tag?(test_file, "Test")).to be(true)
878
- expect(@maid.contains_tag?(test_file, "Twice")).to be(true)
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
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  require 'spec_helper'
4
4
 
5
5
  module Maid
6
- describe TrashMigration, :fakefs => true do
6
+ describe TrashMigration, fakefs: true do
7
7
  context 'when running on Linux' do
8
8
  before do
9
9
  allow(Platform).to receive(:linux?).and_return(true)
@@ -53,8 +53,10 @@ module Maid
53
53
 
54
54
  context 'in Linux' do
55
55
  let(:filename) { 'foo.txt' }
56
- let(:trash_contents) { Dir.glob(File.join(subject.correct_trash, '*'),
57
- File::FNM_DOTMATCH) }
56
+ let(:trash_contents) do
57
+ Dir.glob(File.join(subject.correct_trash, '*'),
58
+ File::FNM_DOTMATCH,)
59
+ end
58
60
 
59
61
  before do
60
62
  allow(subject).to receive(:correct_trash).and_return(File.expand_path('~/.local/share/Trash/files/'))
@@ -66,15 +68,14 @@ module Maid
66
68
  subject.perform
67
69
  end
68
70
 
69
-
70
71
  it 'removes all files from incorrect trash directory' do
71
72
  expect(File.exist?(subject.incorrect_trash)).to be false
72
73
  end
73
74
 
74
75
  it 'moves all files to the correct trash directory' do
75
76
  expect(trash_contents.length).to eq(2)
76
- expect(trash_contents[0]).to match(/files\/\.Trash$/)
77
- expect(trash_contents[1]).to match(/files\/foo.txt$/)
77
+ expect(trash_contents[0]).to match(%r{files/\.Trash$})
78
+ expect(trash_contents[1]).to match(%r{files/foo.txt$})
78
79
  end
79
80
  end
80
81
  end
@@ -14,7 +14,7 @@ describe Maid, '.with_instance' do
14
14
  it 'temporarily sets the instance to the given argument and execute the block' do
15
15
  instance = double('instance')
16
16
  expect(Maid.with_instance(instance) { 0 }).to eq(0)
17
- expect(Maid.instance_eval { @instance }).to be(nil)
17
+ expect(Maid.instance_eval { @instance }).to be_nil
18
18
  end
19
19
  end
20
20
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['COVERAGE']
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ add_filter '/lib/maid/rules.sample.rb'
8
+ # as seen on ubuntu-latest on CI. macos reports a slightly lower number for
9
+ # some reason.
10
+ minimum_coverage 82.77
11
+ refuse_coverage_drop
12
+ end
13
+ end
1
14
  require 'rubygems'
2
15
  require 'rspec'
3
16
  require 'timecop'
@@ -7,13 +20,15 @@ require 'pry-byebug'
7
20
  require 'maid'
8
21
 
9
22
  RSpec.configure do |config|
10
- config.mock_with(:rspec)
11
- config.include(FakeFS::SpecHelpers, :fakefs => true)
23
+ config.mock_with(:rspec) do |mocks|
24
+ mocks.allow_message_expectations_on_nil = false
25
+ end
26
+ config.include(FakeFS::SpecHelpers, fakefs: true)
12
27
  config.raise_errors_for_deprecations!
13
28
  end
14
29
 
15
30
  RSpec::Matchers.define :have_deprecated_method do |expected|
16
31
  match do |actual|
17
- expect(actual).to receive(:__deprecated_run_action__).with(expected, anything)
32
+ expect(actual).to receive(:__deprecated_run_action__).with(expected, anything) # rubocop:disable RSpec/MessageSpies
18
33
  end
19
34
  end