@@ -476,6 +476,56 @@ module CodeOwnership
476476 end
477477 end
478478
479+ context 'in an application with an unsorted CODEOWNERS file' do
480+ before { create_non_empty_application }
481+
482+ it 'prints out the diff' do
483+ FileUtils . mkdir ( '.github' )
484+ codeowners_path . write <<~CODEOWNERS
485+ # STOP! - DO NOT EDIT THIS FILE MANUALLY
486+ # This file was automatically generated by "bin/codeownership validate".
487+ #
488+ # CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub
489+ # teams. This is useful when developers create Pull Requests since the
490+ # code/file owner is notified. Reference GitHub docs for more details:
491+ # https://help.github.com/en/articles/about-code-owners
492+
493+
494+ # Annotations at the top of file
495+ /packs/my_pack/owned_file.rb @MyOrg/bar-team
496+ /frontend/javascripts/packages/my_package/owned_file.jsx @MyOrg/bar-team
497+
498+ # Owner metadata key in package.yml
499+ /packs/my_other_package/**/** @MyOrg/bar-team
500+
501+ # Team-specific owned globs
502+ /app/services/bar_stuff/** @MyOrg/bar-team
503+ /frontend/javascripts/bar_stuff/** @MyOrg/bar-team
504+
505+ # Owner metadata key in package.json
506+ /frontend/javascripts/packages/my_other_package/**/** @MyOrg/bar-team
507+
508+ # Team YML ownership
509+ /config/teams/bar.yml @MyOrg/bar-team
510+ CODEOWNERS
511+
512+ expect_any_instance_of ( codeowners_validation ) . to_not receive ( :` ) # rubocop:disable RSpec/AnyInstance
513+ expect { CodeOwnership . validate! ( autocorrect : false ) } . to raise_error do |e |
514+ expect ( e ) . to be_a CodeOwnership ::InvalidCodeOwnershipConfigurationError
515+ expect ( e . message ) . to eq <<~EXPECTED . chomp
516+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
517+
518+ There may be extra lines, or lines are out of order.
519+ You can try to regenerate the CODEOWNERS file from scratch:
520+ 1) `rm .github/CODEOWNERS`
521+ 2) `bin/codeownership validate`
522+
523+ See https://github.com/rubyatscale/code_ownership#README.md for more details
524+ EXPECTED
525+ end
526+ end
527+ end
528+
479529 context 'in an application with a CODEOWNERS file that has a reference to a github team that no longer exists' do
480530 before do
481531 write_configuration
@@ -656,6 +706,7 @@ module CodeOwnership
656706 # code/file owner is notified. Reference GitHub docs for more details:
657707 # https://help.github.com/en/articles/about-code-owners
658708
709+
659710 # Annotations at the top of file
660711 /packs/my_pack/had_annotation_file.rb @MyOrg/bar-team
661712
0 commit comments