@@ -475,6 +475,57 @@ module CodeOwnership
475475 expect { CodeOwnership . validate! ( autocorrect : false ) } . to_not raise_error
476476 end
477477 end
478+
479+ context 'in an application with a CODEOWNERS file that has a reference to a github team that no longer exists' do
480+ before do
481+ write_configuration
482+
483+ write_file ( 'packs/my_pack/owned_file.rb' , <<~CONTENTS )
484+ # @team Bar
485+ CONTENTS
486+
487+ write_file ( 'config/teams/bar.yml' , <<~CONTENTS )
488+ name: Bar
489+ github:
490+ team: '@MyOrg/bar-team'
491+ CONTENTS
492+ end
493+
494+ it 'prints out the diff' do
495+ FileUtils . mkdir ( '.github' )
496+ codeowners_path . write <<~CODEOWNERS
497+ # STOP! - DO NOT EDIT THIS FILE MANUALLY
498+ # This file was automatically generated by "bin/codeownership validate".
499+ #
500+ # CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub
501+ # teams. This is useful when developers create Pull Requests since the
502+ # code/file owner is notified. Reference GitHub docs for more details:
503+ # https://help.github.com/en/articles/about-code-owners
504+
505+
506+ # Annotations at the top of file
507+ /packs/my_pack/owned_file.rb @MyOrg/this-team-does-not-exist
508+ CODEOWNERS
509+
510+ expect_any_instance_of ( codeowners_validation ) . to_not receive ( :` ) # rubocop:disable RSpec/AnyInstance
511+ expect { CodeOwnership . validate! ( autocorrect : false ) } . to raise_error do |e |
512+ expect ( e ) . to be_a CodeOwnership ::InvalidCodeOwnershipConfigurationError
513+ expect ( e . message ) . to eq <<~EXPECTED . chomp
514+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
515+
516+ CODEOWNERS should contain the following lines, but does not:
517+ - "/packs/my_pack/owned_file.rb @MyOrg/bar-team"
518+ - "# Team YML ownership"
519+ - "/config/teams/bar.yml @MyOrg/bar-team"
520+
521+ CODEOWNERS should not contain the following lines, but it does:
522+ - "/packs/my_pack/owned_file.rb @MyOrg/this-team-does-not-exist"
523+
524+ See https://github.com/rubyatscale/code_ownership#README.md for more details
525+ EXPECTED
526+ end
527+ end
528+ end
478529 end
479530
480531 context 'code_ownership.yml has skip_codeowners_validation set' do
0 commit comments