@@ -526,6 +526,57 @@ module CodeOwnership
526
526
end
527
527
end
528
528
end
529
+
530
+ context 'in an application with a CODEOWNERS file that has a reference to a file that no longer exists' do
531
+ before do
532
+ write_configuration
533
+
534
+ write_file ( 'packs/my_pack/owned_file.rb' , <<~CONTENTS )
535
+ # @team Bar
536
+ CONTENTS
537
+
538
+ write_file ( 'config/teams/bar.yml' , <<~CONTENTS )
539
+ name: Bar
540
+ github:
541
+ team: '@MyOrg/bar-team'
542
+ CONTENTS
543
+ end
544
+
545
+ it 'prints out the diff' do
546
+ FileUtils . mkdir ( '.github' )
547
+ codeowners_path . write <<~CODEOWNERS
548
+ # STOP! - DO NOT EDIT THIS FILE MANUALLY
549
+ # This file was automatically generated by "bin/codeownership validate".
550
+ #
551
+ # CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub
552
+ # teams. This is useful when developers create Pull Requests since the
553
+ # code/file owner is notified. Reference GitHub docs for more details:
554
+ # https://help.github.com/en/articles/about-code-owners
555
+
556
+
557
+ # Annotations at the top of file
558
+ /packs/my_pack/owned_file.rb @MyOrg/bar-team
559
+ /packs/my_pack/deleted_file.rb @MyOrg/bar-team
560
+ CODEOWNERS
561
+
562
+ expect_any_instance_of ( codeowners_validation ) . to_not receive ( :` ) # rubocop:disable RSpec/AnyInstance
563
+ expect { CodeOwnership . validate! ( autocorrect : false ) } . to raise_error do |e |
564
+ expect ( e ) . to be_a CodeOwnership ::InvalidCodeOwnershipConfigurationError
565
+ expect ( e . message ) . to eq <<~EXPECTED . chomp
566
+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
567
+
568
+ CODEOWNERS should contain the following lines, but does not:
569
+ - "# Team YML ownership"
570
+ - "/config/teams/bar.yml @MyOrg/bar-team"
571
+
572
+ CODEOWNERS should not contain the following lines, but it does:
573
+ - "/packs/my_pack/deleted_file.rb @MyOrg/bar-team"
574
+
575
+ See https://github.com/rubyatscale/code_ownership#README.md for more details
576
+ EXPECTED
577
+ end
578
+ end
579
+ end
529
580
end
530
581
531
582
context 'code_ownership.yml has skip_codeowners_validation set' do
0 commit comments