11# frozen_string_literal: true
22
33RSpec . describe "bundle commands" do
4- it "expects all commands to have a man page" do
5- Bundler ::CLI . all_commands . each_key do |command_name |
6- next if command_name == "cli_help"
4+ it "expects all commands to have all options and subcommands documented" do
5+ check_commands! ( Bundler ::CLI )
76
8- expect ( man_page ( command_name ) ) . to exist
7+ Bundler ::CLI . subcommand_classes . each_value do |klass |
8+ check_commands! ( klass )
99 end
1010 end
1111
12- it "expects all commands to have all options documented" do
13- Bundler ::CLI . all_commands . each do |command_name , command |
14- next if command_name == "cli_help"
12+ private
13+
14+ def check_commands! ( command_class )
15+ command_class . commands . each do |command_name , command |
16+ next if command . is_a? ( Bundler ::Thor ::HiddenCommand )
17+
18+ if command_class == Bundler ::CLI
19+ man_page = man_page ( command_name )
20+ expect ( man_page ) . to exist
21+
22+ check_options! ( command , man_page )
23+ else
24+ man_page = man_page ( command . ancestor_name )
25+ expect ( man_page ) . to exist
1526
16- man_page_content = man_page ( command_name ) . read
27+ check_options! ( command , man_page )
28+ check_subcommand! ( command_name , man_page )
29+ end
30+ end
31+ end
1732
18- command . options . each do |_ , option |
19- aliases = option . aliases
20- formatted_aliases = aliases . sort . map { |name | "`#{ name } `" } . join ( ", " ) if aliases
33+ def check_options! ( command , man_page )
34+ command . options . each do |_ , option |
35+ check_option! ( option , man_page )
36+ end
37+ end
2138
22- help = if option . type == :boolean
23- "* #{ append_aliases ( "`#{ option . switch_name } `" , formatted_aliases ) } :"
24- elsif option . enum
25- formatted_aliases = "`#{ option . switch_name } `" if aliases . empty? && option . lazy_default
26- "* #{ prepend_aliases ( option . enum . sort . map { |enum | "`#{ option . switch_name } =#{ enum } `" } . join ( ", " ) , formatted_aliases ) } :"
27- else
28- names = [ option . switch_name , *aliases ]
29- value =
30- case option . type
31- when :array then "<list>"
32- when :numeric then "<number>"
33- else option . name . upcase
34- end
39+ def check_option! ( option , man_page )
40+ man_page_content = man_page . read
3541
36- value = option . type != :numeric && option . lazy_default ? "[=#{ value } ]" : "=#{ value } "
42+ aliases = option . aliases
43+ formatted_aliases = aliases . sort . map { |name | "`#{ name } `" } . join ( ", " ) if aliases
3744
38- "* #{ names . map { |name | "`#{ name } #{ value } `" } . join ( ", " ) } :"
45+ help = if option . type == :boolean
46+ "* #{ append_aliases ( "`#{ option . switch_name } `" , formatted_aliases ) } :"
47+ elsif option . enum
48+ formatted_aliases = "`#{ option . switch_name } `" if aliases . empty? && option . lazy_default
49+ "* #{ prepend_aliases ( option . enum . sort . map { |enum | "`#{ option . switch_name } =#{ enum } `" } . join ( ", " ) , formatted_aliases ) } :"
50+ else
51+ names = [ option . switch_name , *aliases ]
52+ value =
53+ case option . type
54+ when :array then "<list>"
55+ when :numeric then "<number>"
56+ else option . name . upcase
3957 end
4058
41- expect ( man_page_content ) . to include ( help )
42- end
59+ value = option . type != :numeric && option . lazy_default ? "[=#{ value } ]" : "=#{ value } "
60+
61+ "* #{ names . map { |name | "`#{ name } #{ value } `" } . join ( ", " ) } :"
4362 end
63+
64+ expect ( man_page_content ) . to include ( help )
4465 end
4566
46- private
67+ def check_subcommand! ( name , man_page )
68+ expect ( man_page . read ) . to match ( name )
69+ end
4770
4871 def append_aliases ( text , aliases )
4972 return text if aliases . empty?
@@ -57,6 +80,10 @@ def prepend_aliases(text, aliases)
5780 "#{ aliases } , #{ text } "
5881 end
5982
83+ def man_page_content ( command_name )
84+ man_page ( command_name ) . read
85+ end
86+
6087 def man_page ( command_name )
6188 source_root . join ( "lib/bundler/man/bundle-#{ command_name } .1.ronn" )
6289 end
0 commit comments