@@ -436,5 +436,108 @@ def fake_embedded_bin(name)
436
436
expect ( File . symlink? ( "#{ destination } /file_b" ) ) . to be_truthy
437
437
end
438
438
end
439
+
440
+ describe '#sync' do
441
+ let ( :source ) do
442
+ source = File . join ( tmp_path , 'source' )
443
+ FileUtils . mkdir_p ( source )
444
+
445
+ FileUtils . touch ( File . join ( source , 'file_a' ) )
446
+ FileUtils . touch ( File . join ( source , 'file_b' ) )
447
+ FileUtils . touch ( File . join ( source , 'file_c' ) )
448
+
449
+ FileUtils . mkdir_p ( File . join ( source , 'folder' ) )
450
+ FileUtils . touch ( File . join ( source , 'folder' , 'file_d' ) )
451
+ FileUtils . touch ( File . join ( source , 'folder' , 'file_e' ) )
452
+
453
+ FileUtils . mkdir_p ( File . join ( source , '.dot_folder' ) )
454
+ FileUtils . touch ( File . join ( source , '.dot_folder' , 'file_f' ) )
455
+
456
+ FileUtils . touch ( File . join ( source , '.file_g' ) )
457
+ source
458
+ end
459
+
460
+ let ( :destination ) { File . join ( tmp_path , 'destination' ) }
461
+
462
+ context 'when the destination is empty' do
463
+ it 'syncs the directories' do
464
+ subject . sync ( source , destination )
465
+ subject . build
466
+
467
+ expect ( File . file? ( "#{ destination } /file_a" ) ) . to be_truthy
468
+ expect ( File . file? ( "#{ destination } /file_b" ) ) . to be_truthy
469
+ expect ( File . file? ( "#{ destination } /file_c" ) ) . to be_truthy
470
+ expect ( File . file? ( "#{ destination } /folder/file_d" ) ) . to be_truthy
471
+ expect ( File . file? ( "#{ destination } /folder/file_e" ) ) . to be_truthy
472
+ expect ( File . file? ( "#{ destination } /.dot_folder/file_f" ) ) . to be_truthy
473
+ expect ( File . file? ( "#{ destination } /.file_g" ) ) . to be_truthy
474
+ end
475
+ end
476
+
477
+ context 'when the directory exists' do
478
+ before { FileUtils . mkdir_p ( destination ) }
479
+
480
+ it 'deletes existing files and folders' do
481
+ FileUtils . mkdir_p ( "#{ destination } /existing_folder" )
482
+ FileUtils . mkdir_p ( "#{ destination } /.existing_folder" )
483
+ FileUtils . touch ( "#{ destination } /existing_file" )
484
+ FileUtils . touch ( "#{ destination } /.existing_file" )
485
+
486
+ subject . sync ( source , destination )
487
+ subject . build
488
+
489
+ expect ( File . file? ( "#{ destination } /file_a" ) ) . to be_truthy
490
+ expect ( File . file? ( "#{ destination } /file_b" ) ) . to be_truthy
491
+ expect ( File . file? ( "#{ destination } /file_c" ) ) . to be_truthy
492
+ expect ( File . file? ( "#{ destination } /folder/file_d" ) ) . to be_truthy
493
+ expect ( File . file? ( "#{ destination } /folder/file_e" ) ) . to be_truthy
494
+ expect ( File . file? ( "#{ destination } /.dot_folder/file_f" ) ) . to be_truthy
495
+ expect ( File . file? ( "#{ destination } /.file_g" ) ) . to be_truthy
496
+
497
+ expect ( File . exist? ( "#{ destination } /existing_folder" ) ) . to be_falsey
498
+ expect ( File . exist? ( "#{ destination } /.existing_folder" ) ) . to be_falsey
499
+ expect ( File . exist? ( "#{ destination } /existing_file" ) ) . to be_falsey
500
+ expect ( File . exist? ( "#{ destination } /.existing_file" ) ) . to be_falsey
501
+ end
502
+ end
503
+
504
+ context 'when :exclude is given' do
505
+ it 'does not copy files and folders that match the pattern' do
506
+ subject . sync ( source , destination , exclude : '.dot_folder' )
507
+ subject . build
508
+
509
+ expect ( File . file? ( "#{ destination } /file_a" ) ) . to be_truthy
510
+ expect ( File . file? ( "#{ destination } /file_b" ) ) . to be_truthy
511
+ expect ( File . file? ( "#{ destination } /file_c" ) ) . to be_truthy
512
+ expect ( File . file? ( "#{ destination } /folder/file_d" ) ) . to be_truthy
513
+ expect ( File . file? ( "#{ destination } /folder/file_e" ) ) . to be_truthy
514
+ expect ( File . exist? ( "#{ destination } /.dot_folder" ) ) . to be_falsey
515
+ expect ( File . file? ( "#{ destination } /.dot_folder/file_f" ) ) . to be_falsey
516
+ expect ( File . file? ( "#{ destination } /.file_g" ) ) . to be_truthy
517
+ end
518
+
519
+ it 'removes existing files and folders in destination' do
520
+ FileUtils . mkdir_p ( "#{ destination } /existing_folder" )
521
+ FileUtils . touch ( "#{ destination } /existing_file" )
522
+ FileUtils . mkdir_p ( "#{ destination } /.dot_folder" )
523
+ FileUtils . touch ( "#{ destination } /.dot_folder/file_f" )
524
+
525
+ subject . sync ( source , destination , exclude : '.dot_folder' )
526
+ subject . build
527
+
528
+ expect ( File . file? ( "#{ destination } /file_a" ) ) . to be_truthy
529
+ expect ( File . file? ( "#{ destination } /file_b" ) ) . to be_truthy
530
+ expect ( File . file? ( "#{ destination } /file_c" ) ) . to be_truthy
531
+ expect ( File . file? ( "#{ destination } /folder/file_d" ) ) . to be_truthy
532
+ expect ( File . file? ( "#{ destination } /folder/file_e" ) ) . to be_truthy
533
+ expect ( File . exist? ( "#{ destination } /.dot_folder" ) ) . to be_falsey
534
+ expect ( File . file? ( "#{ destination } /.dot_folder/file_f" ) ) . to be_falsey
535
+ expect ( File . file? ( "#{ destination } /.file_g" ) ) . to be_truthy
536
+
537
+ expect ( File . exist? ( "#{ destination } /existing_folder" ) ) . to be_falsey
538
+ expect ( File . exist? ( "#{ destination } /existing_file" ) ) . to be_falsey
539
+ end
540
+ end
541
+ end
439
542
end
440
543
end
0 commit comments