yard 0.9.18 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (567) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +26 -26
  3. data/CHANGELOG.md +742 -728
  4. data/LEGAL +66 -66
  5. data/LICENSE +22 -22
  6. data/README.md +328 -328
  7. data/Rakefile +42 -53
  8. data/benchmarks/builtins_vs_eval.rb +24 -24
  9. data/benchmarks/concat_vs_join.rb +13 -13
  10. data/benchmarks/erb_vs_erubis.rb +54 -54
  11. data/benchmarks/format_args.rb +47 -47
  12. data/benchmarks/generation.rb +38 -38
  13. data/benchmarks/marshal_vs_dbm.rb +64 -64
  14. data/benchmarks/parsing.rb +46 -46
  15. data/benchmarks/pathname_vs_string.rb +50 -50
  16. data/benchmarks/rdoc_vs_yardoc.rb +11 -11
  17. data/benchmarks/registry_store_types.rb +49 -49
  18. data/benchmarks/ri_vs_yri.rb +19 -19
  19. data/benchmarks/ripper_parser.rb +13 -13
  20. data/benchmarks/splat_vs_flatten.rb +13 -13
  21. data/benchmarks/template_erb.rb +23 -23
  22. data/benchmarks/template_format.rb +7 -7
  23. data/benchmarks/template_profile.rb +18 -18
  24. data/benchmarks/yri_cache.rb +20 -20
  25. data/bin/yard +13 -13
  26. data/bin/yardoc +13 -13
  27. data/bin/yri +13 -13
  28. data/docs/CodeObjects.md +115 -115
  29. data/docs/GettingStarted.md +679 -679
  30. data/docs/Handlers.md +152 -152
  31. data/docs/Overview.md +61 -61
  32. data/docs/Parser.md +191 -191
  33. data/docs/Tags.md +283 -283
  34. data/docs/TagsArch.md +123 -123
  35. data/docs/Templates.md +496 -496
  36. data/docs/WhatsNew.md +1245 -1245
  37. data/docs/templates/default/fulldoc/html/full_list_tag.erb +8 -8
  38. data/docs/templates/default/fulldoc/html/setup.rb +6 -6
  39. data/docs/templates/default/layout/html/setup.rb +9 -9
  40. data/docs/templates/default/layout/html/tag_list.erb +11 -11
  41. data/docs/templates/default/yard_tags/html/list.erb +18 -18
  42. data/docs/templates/default/yard_tags/html/setup.rb +26 -26
  43. data/docs/templates/plugin.rb +70 -70
  44. data/lib/rubygems_plugin.rb +9 -9
  45. data/lib/yard.rb +69 -69
  46. data/lib/yard/autoload.rb +308 -303
  47. data/lib/yard/cli/command.rb +85 -85
  48. data/lib/yard/cli/command_parser.rb +93 -93
  49. data/lib/yard/cli/config.rb +198 -198
  50. data/lib/yard/cli/diff.rb +270 -270
  51. data/lib/yard/cli/display.rb +69 -69
  52. data/lib/yard/cli/gems.rb +84 -84
  53. data/lib/yard/cli/graph.rb +125 -125
  54. data/lib/yard/cli/help.rb +20 -20
  55. data/lib/yard/cli/i18n.rb +70 -70
  56. data/lib/yard/cli/list.rb +23 -23
  57. data/lib/yard/cli/markup_types.rb +32 -32
  58. data/lib/yard/cli/server.rb +257 -257
  59. data/lib/yard/cli/stats.rb +231 -231
  60. data/lib/yard/cli/yardoc.rb +789 -788
  61. data/lib/yard/cli/yardopts_command.rb +110 -110
  62. data/lib/yard/cli/yri.rb +215 -215
  63. data/lib/yard/code_objects/base.rb +615 -615
  64. data/lib/yard/code_objects/class_object.rb +146 -146
  65. data/lib/yard/code_objects/class_variable_object.rb +11 -11
  66. data/lib/yard/code_objects/constant_object.rb +16 -16
  67. data/lib/yard/code_objects/extended_method_object.rb +24 -24
  68. data/lib/yard/code_objects/extra_file_object.rb +134 -131
  69. data/lib/yard/code_objects/macro_object.rb +172 -172
  70. data/lib/yard/code_objects/method_object.rb +196 -196
  71. data/lib/yard/code_objects/module_object.rb +21 -21
  72. data/lib/yard/code_objects/namespace_mapper.rb +114 -114
  73. data/lib/yard/code_objects/namespace_object.rb +200 -200
  74. data/lib/yard/code_objects/proxy.rb +240 -240
  75. data/lib/yard/code_objects/root_object.rb +19 -19
  76. data/lib/yard/config.rb +270 -270
  77. data/lib/yard/core_ext/array.rb +16 -16
  78. data/lib/yard/core_ext/file.rb +69 -69
  79. data/lib/yard/core_ext/hash.rb +16 -16
  80. data/lib/yard/core_ext/insertion.rb +63 -63
  81. data/lib/yard/core_ext/module.rb +11 -20
  82. data/lib/yard/core_ext/string.rb +68 -68
  83. data/lib/yard/core_ext/symbol_hash.rb +75 -75
  84. data/lib/yard/docstring.rb +386 -386
  85. data/lib/yard/docstring_parser.rb +345 -345
  86. data/lib/yard/gem_index.rb +29 -29
  87. data/lib/yard/globals.rb +22 -22
  88. data/lib/yard/handlers/base.rb +595 -595
  89. data/lib/yard/handlers/c/alias_handler.rb +16 -16
  90. data/lib/yard/handlers/c/attribute_handler.rb +13 -13
  91. data/lib/yard/handlers/c/base.rb +129 -129
  92. data/lib/yard/handlers/c/class_handler.rb +27 -27
  93. data/lib/yard/handlers/c/constant_handler.rb +13 -13
  94. data/lib/yard/handlers/c/handler_methods.rb +212 -211
  95. data/lib/yard/handlers/c/init_handler.rb +20 -20
  96. data/lib/yard/handlers/c/method_handler.rb +45 -45
  97. data/lib/yard/handlers/c/mixin_handler.rb +21 -21
  98. data/lib/yard/handlers/c/module_handler.rb +17 -17
  99. data/lib/yard/handlers/c/override_comment_handler.rb +31 -31
  100. data/lib/yard/handlers/c/path_handler.rb +11 -11
  101. data/lib/yard/handlers/c/struct_handler.rb +13 -13
  102. data/lib/yard/handlers/c/symbol_handler.rb +8 -8
  103. data/lib/yard/handlers/common/method_handler.rb +19 -0
  104. data/lib/yard/handlers/processor.rb +200 -200
  105. data/lib/yard/handlers/ruby/alias_handler.rb +44 -44
  106. data/lib/yard/handlers/ruby/attribute_handler.rb +87 -87
  107. data/lib/yard/handlers/ruby/base.rb +165 -165
  108. data/lib/yard/handlers/ruby/class_condition_handler.rb +92 -92
  109. data/lib/yard/handlers/ruby/class_handler.rb +119 -119
  110. data/lib/yard/handlers/ruby/class_variable_handler.rb +17 -17
  111. data/lib/yard/handlers/ruby/comment_handler.rb +10 -10
  112. data/lib/yard/handlers/ruby/constant_handler.rb +59 -59
  113. data/lib/yard/handlers/ruby/decorator_handler_methods.rb +123 -123
  114. data/lib/yard/handlers/ruby/dsl_handler.rb +15 -15
  115. data/lib/yard/handlers/ruby/dsl_handler_methods.rb +96 -96
  116. data/lib/yard/handlers/ruby/exception_handler.rb +27 -27
  117. data/lib/yard/handlers/ruby/extend_handler.rb +22 -22
  118. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +37 -37
  119. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +65 -65
  120. data/lib/yard/handlers/ruby/legacy/base.rb +245 -245
  121. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +83 -83
  122. data/lib/yard/handlers/ruby/legacy/class_handler.rb +113 -113
  123. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +15 -15
  124. data/lib/yard/handlers/ruby/legacy/comment_handler.rb +10 -10
  125. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +29 -29
  126. data/lib/yard/handlers/ruby/legacy/dsl_handler.rb +17 -17
  127. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +13 -13
  128. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +21 -21
  129. data/lib/yard/handlers/ruby/legacy/method_handler.rb +90 -90
  130. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +39 -39
  131. data/lib/yard/handlers/ruby/legacy/module_function_handler.rb +19 -19
  132. data/lib/yard/handlers/ruby/legacy/module_handler.rb +12 -12
  133. data/lib/yard/handlers/ruby/legacy/private_class_method_handler.rb +22 -22
  134. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +22 -22
  135. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +17 -17
  136. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +29 -29
  137. data/lib/yard/handlers/ruby/method_condition_handler.rb +9 -9
  138. data/lib/yard/handlers/ruby/method_handler.rb +114 -118
  139. data/lib/yard/handlers/ruby/mixin_handler.rb +37 -37
  140. data/lib/yard/handlers/ruby/module_function_handler.rb +27 -27
  141. data/lib/yard/handlers/ruby/module_handler.rb +12 -12
  142. data/lib/yard/handlers/ruby/private_class_method_handler.rb +14 -14
  143. data/lib/yard/handlers/ruby/private_constant_handler.rb +43 -43
  144. data/lib/yard/handlers/ruby/public_class_method_handler.rb +14 -14
  145. data/lib/yard/handlers/ruby/struct_handler_methods.rb +143 -143
  146. data/lib/yard/handlers/ruby/visibility_handler.rb +22 -22
  147. data/lib/yard/handlers/ruby/yield_handler.rb +31 -31
  148. data/lib/yard/i18n/locale.rb +67 -67
  149. data/lib/yard/i18n/message.rb +57 -57
  150. data/lib/yard/i18n/messages.rb +56 -56
  151. data/lib/yard/i18n/po_parser.rb +61 -61
  152. data/lib/yard/i18n/pot_generator.rb +290 -290
  153. data/lib/yard/i18n/text.rb +173 -173
  154. data/lib/yard/logging.rb +205 -205
  155. data/lib/yard/options.rb +217 -217
  156. data/lib/yard/parser/base.rb +57 -57
  157. data/lib/yard/parser/c/c_parser.rb +235 -235
  158. data/lib/yard/parser/c/comment_parser.rb +134 -134
  159. data/lib/yard/parser/c/statement.rb +64 -64
  160. data/lib/yard/parser/ruby/ast_node.rb +540 -540
  161. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +1354 -1354
  162. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +32 -32
  163. data/lib/yard/parser/ruby/legacy/statement.rb +66 -66
  164. data/lib/yard/parser/ruby/legacy/statement_list.rb +394 -394
  165. data/lib/yard/parser/ruby/legacy/token_list.rb +74 -74
  166. data/lib/yard/parser/ruby/ruby_parser.rb +687 -687
  167. data/lib/yard/parser/ruby/token_resolver.rb +156 -156
  168. data/lib/yard/parser/source_parser.rb +526 -526
  169. data/lib/yard/rake/yardoc_task.rb +81 -81
  170. data/lib/yard/registry.rb +439 -439
  171. data/lib/yard/registry_resolver.rb +189 -189
  172. data/lib/yard/registry_store.rb +337 -337
  173. data/lib/yard/rubygems/backports.rb +10 -10
  174. data/lib/yard/rubygems/backports/LICENSE.txt +57 -57
  175. data/lib/yard/rubygems/backports/MIT.txt +20 -20
  176. data/lib/yard/rubygems/backports/gem.rb +10 -10
  177. data/lib/yard/rubygems/backports/source_index.rb +365 -365
  178. data/lib/yard/rubygems/doc_manager.rb +90 -90
  179. data/lib/yard/rubygems/hook.rb +197 -197
  180. data/lib/yard/rubygems/specification.rb +50 -50
  181. data/lib/yard/serializers/base.rb +83 -83
  182. data/lib/yard/serializers/file_system_serializer.rb +123 -123
  183. data/lib/yard/serializers/process_serializer.rb +24 -24
  184. data/lib/yard/serializers/stdout_serializer.rb +34 -34
  185. data/lib/yard/serializers/yardoc_serializer.rb +152 -152
  186. data/lib/yard/server.rb +13 -13
  187. data/lib/yard/server/adapter.rb +100 -100
  188. data/lib/yard/server/commands/base.rb +209 -209
  189. data/lib/yard/server/commands/display_file_command.rb +29 -29
  190. data/lib/yard/server/commands/display_object_command.rb +65 -65
  191. data/lib/yard/server/commands/frames_command.rb +16 -16
  192. data/lib/yard/server/commands/library_command.rb +187 -187
  193. data/lib/yard/server/commands/library_index_command.rb +28 -28
  194. data/lib/yard/server/commands/list_command.rb +25 -25
  195. data/lib/yard/server/commands/root_request_command.rb +15 -15
  196. data/lib/yard/server/commands/search_command.rb +79 -79
  197. data/lib/yard/server/commands/static_file_command.rb +23 -23
  198. data/lib/yard/server/commands/static_file_helpers.rb +62 -62
  199. data/lib/yard/server/doc_server_helper.rb +91 -91
  200. data/lib/yard/server/doc_server_serializer.rb +39 -39
  201. data/lib/yard/server/library_version.rb +277 -277
  202. data/lib/yard/server/rack_adapter.rb +89 -89
  203. data/lib/yard/server/router.rb +187 -187
  204. data/lib/yard/server/static_caching.rb +46 -46
  205. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +127 -127
  206. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +11 -11
  207. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +37 -37
  208. data/lib/yard/server/templates/default/layout/html/script_setup.erb +7 -7
  209. data/lib/yard/server/templates/default/layout/html/setup.rb +8 -8
  210. data/lib/yard/server/templates/default/method_details/html/permalink.erb +4 -4
  211. data/lib/yard/server/templates/default/method_details/html/setup.rb +5 -5
  212. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +8 -8
  213. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +14 -14
  214. data/lib/yard/server/templates/doc_server/library_list/html/listing.erb +13 -13
  215. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +6 -6
  216. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -2
  217. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +52 -52
  218. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +4 -4
  219. data/lib/yard/server/templates/doc_server/search/html/search.erb +18 -18
  220. data/lib/yard/server/templates/doc_server/search/html/setup.rb +9 -9
  221. data/lib/yard/server/webrick_adapter.rb +45 -45
  222. data/lib/yard/tags/default_factory.rb +191 -191
  223. data/lib/yard/tags/default_tag.rb +13 -13
  224. data/lib/yard/tags/directives.rb +616 -616
  225. data/lib/yard/tags/library.rb +633 -633
  226. data/lib/yard/tags/option_tag.rb +13 -13
  227. data/lib/yard/tags/overload_tag.rb +71 -71
  228. data/lib/yard/tags/ref_tag.rb +8 -8
  229. data/lib/yard/tags/ref_tag_list.rb +28 -28
  230. data/lib/yard/tags/tag.rb +71 -71
  231. data/lib/yard/tags/tag_format_error.rb +7 -7
  232. data/lib/yard/tags/types_explainer.rb +162 -162
  233. data/lib/yard/templates/engine.rb +186 -186
  234. data/lib/yard/templates/erb_cache.rb +23 -23
  235. data/lib/yard/templates/helpers/base_helper.rb +215 -215
  236. data/lib/yard/templates/helpers/filter_helper.rb +27 -27
  237. data/lib/yard/templates/helpers/html_helper.rb +646 -646
  238. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +78 -78
  239. data/lib/yard/templates/helpers/markup/rdoc_markdown.rb +23 -23
  240. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +109 -109
  241. data/lib/yard/templates/helpers/markup_helper.rb +172 -172
  242. data/lib/yard/templates/helpers/method_helper.rb +75 -75
  243. data/lib/yard/templates/helpers/module_helper.rb +21 -21
  244. data/lib/yard/templates/helpers/text_helper.rb +112 -112
  245. data/lib/yard/templates/helpers/uml_helper.rb +47 -47
  246. data/lib/yard/templates/section.rb +105 -105
  247. data/lib/yard/templates/template.rb +418 -418
  248. data/lib/yard/templates/template_options.rb +92 -92
  249. data/lib/yard/verifier.rb +151 -151
  250. data/lib/yard/version.rb +6 -6
  251. data/spec/cli/command_parser_spec.rb +43 -43
  252. data/spec/cli/command_spec.rb +36 -36
  253. data/spec/cli/config_spec.rb +148 -148
  254. data/spec/cli/diff_spec.rb +254 -254
  255. data/spec/cli/display_spec.rb +30 -30
  256. data/spec/cli/gems_spec.rb +81 -81
  257. data/spec/cli/graph_spec.rb +18 -18
  258. data/spec/cli/help_spec.rb +22 -22
  259. data/spec/cli/i18n_spec.rb +107 -107
  260. data/spec/cli/list_spec.rb +8 -8
  261. data/spec/cli/markup_types_spec.rb +22 -22
  262. data/spec/cli/server_spec.rb +324 -324
  263. data/spec/cli/stats_spec.rb +96 -96
  264. data/spec/cli/yard_on_yard_spec.rb +38 -38
  265. data/spec/cli/yardoc_spec.rb +896 -862
  266. data/spec/cli/yri_spec.rb +101 -101
  267. data/spec/code_objects/base_spec.rb +470 -470
  268. data/spec/code_objects/class_object_spec.rb +226 -226
  269. data/spec/code_objects/code_object_list_spec.rb +36 -36
  270. data/spec/code_objects/constants_spec.rb +116 -116
  271. data/spec/code_objects/extra_file_object_spec.rb +160 -160
  272. data/spec/code_objects/macro_object_spec.rb +150 -150
  273. data/spec/code_objects/method_object_spec.rb +184 -184
  274. data/spec/code_objects/module_object_spec.rb +142 -142
  275. data/spec/code_objects/namespace_object_spec.rb +171 -171
  276. data/spec/code_objects/proxy_spec.rb +141 -141
  277. data/spec/code_objects/spec_helper.rb +3 -3
  278. data/spec/config_spec.rb +171 -171
  279. data/spec/core_ext/array_spec.rb +13 -13
  280. data/spec/core_ext/file_spec.rb +72 -72
  281. data/spec/core_ext/hash_spec.rb +14 -14
  282. data/spec/core_ext/insertion_spec.rb +37 -37
  283. data/spec/core_ext/module_spec.rb +9 -15
  284. data/spec/core_ext/string_spec.rb +42 -42
  285. data/spec/core_ext/symbol_hash_spec.rb +89 -89
  286. data/spec/docstring_parser_spec.rb +280 -280
  287. data/spec/docstring_spec.rb +373 -373
  288. data/spec/examples.txt +1883 -1875
  289. data/spec/handlers/alias_handler_spec.rb +82 -82
  290. data/spec/handlers/attribute_handler_spec.rb +96 -96
  291. data/spec/handlers/base_spec.rb +216 -216
  292. data/spec/handlers/c/alias_handler_spec.rb +34 -34
  293. data/spec/handlers/c/attribute_handler_spec.rb +41 -41
  294. data/spec/handlers/c/class_handler_spec.rb +78 -78
  295. data/spec/handlers/c/constant_handler_spec.rb +71 -71
  296. data/spec/handlers/c/init_handler_spec.rb +48 -48
  297. data/spec/handlers/c/method_handler_spec.rb +327 -325
  298. data/spec/handlers/c/mixin_handler_spec.rb +44 -44
  299. data/spec/handlers/c/module_handler_spec.rb +71 -71
  300. data/spec/handlers/c/override_comment_handler_spec.rb +47 -47
  301. data/spec/handlers/c/path_handler_spec.rb +36 -36
  302. data/spec/handlers/c/spec_helper.rb +23 -23
  303. data/spec/handlers/c/struct_handler_spec.rb +16 -16
  304. data/spec/handlers/class_condition_handler_spec.rb +87 -87
  305. data/spec/handlers/class_handler_spec.rb +247 -247
  306. data/spec/handlers/class_method_handler_shared_examples.rb +133 -133
  307. data/spec/handlers/class_variable_handler_spec.rb +12 -12
  308. data/spec/handlers/constant_handler_spec.rb +112 -112
  309. data/spec/handlers/decorator_handler_methods_spec.rb +393 -393
  310. data/spec/handlers/dsl_handler_spec.rb +219 -219
  311. data/spec/handlers/examples/alias_handler_001.rb.txt +45 -45
  312. data/spec/handlers/examples/attribute_handler_001.rb.txt +31 -31
  313. data/spec/handlers/examples/class_condition_handler_001.rb.txt +68 -68
  314. data/spec/handlers/examples/class_handler_001.rb.txt +120 -120
  315. data/spec/handlers/examples/class_variable_handler_001.rb.txt +9 -9
  316. data/spec/handlers/examples/constant_handler_001.rb.txt +35 -35
  317. data/spec/handlers/examples/dsl_handler_001.rb.txt +154 -154
  318. data/spec/handlers/examples/exception_handler_001.rb.txt +58 -58
  319. data/spec/handlers/examples/extend_handler_001.rb.txt +15 -15
  320. data/spec/handlers/examples/method_condition_handler_001.rb.txt +9 -9
  321. data/spec/handlers/examples/method_handler_001.rb.txt +128 -128
  322. data/spec/handlers/examples/mixin_handler_001.rb.txt +37 -37
  323. data/spec/handlers/examples/module_handler_001.rb.txt +29 -29
  324. data/spec/handlers/examples/private_constant_handler_001.rb.txt +8 -8
  325. data/spec/handlers/examples/process_handler_001.rb.txt +11 -11
  326. data/spec/handlers/examples/visibility_handler_001.rb.txt +35 -35
  327. data/spec/handlers/examples/yield_handler_001.rb.txt +54 -54
  328. data/spec/handlers/exception_handler_spec.rb +49 -49
  329. data/spec/handlers/extend_handler_spec.rb +24 -24
  330. data/spec/handlers/legacy_base_spec.rb +128 -128
  331. data/spec/handlers/method_condition_handler_spec.rb +15 -15
  332. data/spec/handlers/method_handler_spec.rb +190 -190
  333. data/spec/handlers/mixin_handler_spec.rb +56 -56
  334. data/spec/handlers/module_function_handler_spec.rb +106 -106
  335. data/spec/handlers/module_handler_spec.rb +35 -35
  336. data/spec/handlers/private_class_method_handler_spec.rb +11 -11
  337. data/spec/handlers/private_constant_handler_spec.rb +25 -25
  338. data/spec/handlers/processor_spec.rb +35 -35
  339. data/spec/handlers/public_class_method_handler_spec.rb +11 -11
  340. data/spec/handlers/ruby/base_spec.rb +95 -95
  341. data/spec/handlers/ruby/legacy/base_spec.rb +84 -84
  342. data/spec/handlers/spec_helper.rb +33 -33
  343. data/spec/handlers/visibility_handler_spec.rb +44 -44
  344. data/spec/handlers/yield_handler_spec.rb +52 -52
  345. data/spec/i18n/locale_spec.rb +81 -81
  346. data/spec/i18n/message_spec.rb +52 -52
  347. data/spec/i18n/messages_spec.rb +67 -67
  348. data/spec/i18n/pot_generator_spec.rb +295 -295
  349. data/spec/i18n/text_spec.rb +184 -184
  350. data/spec/logging_spec.rb +44 -44
  351. data/spec/options_spec.rb +171 -171
  352. data/spec/parser/base_spec.rb +24 -24
  353. data/spec/parser/c_parser_spec.rb +236 -236
  354. data/spec/parser/examples/array.c.txt +6267 -6267
  355. data/spec/parser/examples/example1.rb.txt +7 -7
  356. data/spec/parser/examples/extrafile.c.txt +8 -8
  357. data/spec/parser/examples/file.c.txt +28 -28
  358. data/spec/parser/examples/multifile.c.txt +22 -22
  359. data/spec/parser/examples/namespace.cpp.txt +68 -68
  360. data/spec/parser/examples/override.c.txt +424 -424
  361. data/spec/parser/examples/parse_in_order_001.rb.txt +2 -2
  362. data/spec/parser/examples/parse_in_order_002.rb.txt +1 -1
  363. data/spec/parser/examples/tag_handler_001.rb.txt +7 -7
  364. data/spec/parser/ruby/ast_node_spec.rb +33 -33
  365. data/spec/parser/ruby/legacy/statement_list_spec.rb +299 -299
  366. data/spec/parser/ruby/legacy/token_list_spec.rb +79 -79
  367. data/spec/parser/ruby/ruby_parser_spec.rb +508 -508
  368. data/spec/parser/ruby/token_resolver_spec.rb +165 -165
  369. data/spec/parser/source_parser_spec.rb +727 -727
  370. data/spec/parser/tag_parsing_spec.rb +17 -17
  371. data/spec/rake/yardoc_task_spec.rb +118 -118
  372. data/spec/registry_spec.rb +463 -463
  373. data/spec/registry_store_spec.rb +316 -316
  374. data/spec/rubygems/doc_manager_spec.rb +112 -112
  375. data/spec/serializers/data/serialized_yardoc/checksums +1 -1
  376. data/spec/serializers/file_system_serializer_spec.rb +145 -145
  377. data/spec/serializers/spec_helper.rb +2 -2
  378. data/spec/serializers/yardoc_serializer_spec.rb +78 -78
  379. data/spec/server/adapter_spec.rb +39 -39
  380. data/spec/server/commands/base_spec.rb +91 -91
  381. data/spec/server/commands/library_command_spec.rb +39 -39
  382. data/spec/server/doc_server_helper_spec.rb +72 -72
  383. data/spec/server/doc_server_serializer_spec.rb +60 -60
  384. data/spec/server/rack_adapter_spec.rb +21 -21
  385. data/spec/server/router_spec.rb +123 -123
  386. data/spec/server/spec_helper.rb +22 -22
  387. data/spec/server/static_caching_spec.rb +47 -47
  388. data/spec/server/webrick_servlet_spec.rb +20 -20
  389. data/spec/server_spec.rb +19 -19
  390. data/spec/spec_helper.rb +212 -212
  391. data/spec/tags/default_factory_spec.rb +168 -168
  392. data/spec/tags/default_tag_spec.rb +11 -11
  393. data/spec/tags/directives_spec.rb +463 -463
  394. data/spec/tags/library_spec.rb +48 -48
  395. data/spec/tags/overload_tag_spec.rb +53 -53
  396. data/spec/tags/ref_tag_list_spec.rb +53 -53
  397. data/spec/tags/types_explainer_spec.rb +203 -203
  398. data/spec/templates/class_spec.rb +45 -45
  399. data/spec/templates/constant_spec.rb +41 -41
  400. data/spec/templates/engine_spec.rb +131 -131
  401. data/spec/templates/examples/class001.html +308 -308
  402. data/spec/templates/examples/class001.txt +36 -36
  403. data/spec/templates/examples/class002.html +39 -39
  404. data/spec/templates/examples/constant001.txt +24 -24
  405. data/spec/templates/examples/constant002.txt +6 -6
  406. data/spec/templates/examples/constant003.txt +10 -10
  407. data/spec/templates/examples/method001.html +137 -137
  408. data/spec/templates/examples/method001.txt +35 -35
  409. data/spec/templates/examples/method002.html +91 -91
  410. data/spec/templates/examples/method002.txt +20 -20
  411. data/spec/templates/examples/method003.html +165 -165
  412. data/spec/templates/examples/method003.txt +45 -45
  413. data/spec/templates/examples/method004.html +48 -48
  414. data/spec/templates/examples/method004.txt +10 -10
  415. data/spec/templates/examples/method005.html +105 -105
  416. data/spec/templates/examples/method005.txt +33 -33
  417. data/spec/templates/examples/method006.html +107 -107
  418. data/spec/templates/examples/method006.txt +20 -20
  419. data/spec/templates/examples/module001.dot +33 -33
  420. data/spec/templates/examples/module001.html +833 -833
  421. data/spec/templates/examples/module001.txt +33 -33
  422. data/spec/templates/examples/module002.html +341 -341
  423. data/spec/templates/examples/module003.html +202 -202
  424. data/spec/templates/examples/module004.html +394 -394
  425. data/spec/templates/examples/module005.html +81 -81
  426. data/spec/templates/examples/tag001.txt +82 -82
  427. data/spec/templates/helpers/base_helper_spec.rb +171 -171
  428. data/spec/templates/helpers/html_helper_spec.rb +687 -668
  429. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +65 -65
  430. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +84 -84
  431. data/spec/templates/helpers/markup_helper_spec.rb +136 -136
  432. data/spec/templates/helpers/method_helper_spec.rb +107 -107
  433. data/spec/templates/helpers/module_helper_spec.rb +35 -35
  434. data/spec/templates/helpers/shared_signature_examples.rb +126 -126
  435. data/spec/templates/helpers/text_helper_spec.rb +65 -65
  436. data/spec/templates/method_spec.rb +118 -118
  437. data/spec/templates/module_spec.rb +203 -203
  438. data/spec/templates/onefile_spec.rb +66 -66
  439. data/spec/templates/section_spec.rb +144 -144
  440. data/spec/templates/spec_helper.rb +76 -76
  441. data/spec/templates/tag_spec.rb +52 -52
  442. data/spec/templates/template_spec.rb +410 -410
  443. data/spec/verifier_spec.rb +106 -106
  444. data/templates/default/class/dot/setup.rb +7 -7
  445. data/templates/default/class/dot/superklass.erb +2 -2
  446. data/templates/default/class/html/constructor_details.erb +8 -8
  447. data/templates/default/class/html/setup.rb +2 -2
  448. data/templates/default/class/html/subclasses.erb +4 -4
  449. data/templates/default/class/setup.rb +36 -36
  450. data/templates/default/class/text/setup.rb +12 -12
  451. data/templates/default/class/text/subclasses.erb +5 -5
  452. data/templates/default/constant/text/header.erb +11 -11
  453. data/templates/default/constant/text/setup.rb +4 -4
  454. data/templates/default/docstring/html/abstract.erb +4 -4
  455. data/templates/default/docstring/html/deprecated.erb +1 -1
  456. data/templates/default/docstring/html/index.erb +5 -5
  457. data/templates/default/docstring/html/note.erb +6 -6
  458. data/templates/default/docstring/html/private.erb +4 -4
  459. data/templates/default/docstring/html/text.erb +1 -1
  460. data/templates/default/docstring/html/todo.erb +6 -6
  461. data/templates/default/docstring/setup.rb +52 -52
  462. data/templates/default/docstring/text/abstract.erb +2 -2
  463. data/templates/default/docstring/text/deprecated.erb +2 -2
  464. data/templates/default/docstring/text/index.erb +2 -2
  465. data/templates/default/docstring/text/note.erb +3 -3
  466. data/templates/default/docstring/text/private.erb +2 -2
  467. data/templates/default/docstring/text/text.erb +1 -1
  468. data/templates/default/docstring/text/todo.erb +3 -3
  469. data/templates/default/fulldoc/html/css/full_list.css +58 -58
  470. data/templates/default/fulldoc/html/css/style.css +496 -496
  471. data/templates/default/fulldoc/html/frames.erb +17 -17
  472. data/templates/default/fulldoc/html/full_list.erb +37 -37
  473. data/templates/default/fulldoc/html/full_list_class.erb +2 -2
  474. data/templates/default/fulldoc/html/full_list_file.erb +7 -7
  475. data/templates/default/fulldoc/html/full_list_method.erb +10 -10
  476. data/templates/default/fulldoc/html/js/app.js +303 -292
  477. data/templates/default/fulldoc/html/js/full_list.js +216 -216
  478. data/templates/default/fulldoc/html/js/jquery.js +3 -3
  479. data/templates/default/fulldoc/html/setup.rb +241 -241
  480. data/templates/default/layout/dot/header.erb +5 -5
  481. data/templates/default/layout/dot/setup.rb +15 -15
  482. data/templates/default/layout/html/breadcrumb.erb +11 -11
  483. data/templates/default/layout/html/files.erb +11 -11
  484. data/templates/default/layout/html/footer.erb +5 -5
  485. data/templates/default/layout/html/headers.erb +15 -15
  486. data/templates/default/layout/html/index.erb +2 -2
  487. data/templates/default/layout/html/layout.erb +23 -23
  488. data/templates/default/layout/html/listing.erb +4 -4
  489. data/templates/default/layout/html/objects.erb +32 -32
  490. data/templates/default/layout/html/script_setup.erb +4 -4
  491. data/templates/default/layout/html/search.erb +12 -12
  492. data/templates/default/layout/html/setup.rb +89 -89
  493. data/templates/default/method/html/header.erb +16 -16
  494. data/templates/default/method/setup.rb +4 -4
  495. data/templates/default/method_details/html/header.erb +2 -2
  496. data/templates/default/method_details/html/method_signature.erb +24 -24
  497. data/templates/default/method_details/html/source.erb +9 -9
  498. data/templates/default/method_details/setup.rb +11 -11
  499. data/templates/default/method_details/text/header.erb +10 -10
  500. data/templates/default/method_details/text/method_signature.erb +12 -12
  501. data/templates/default/method_details/text/setup.rb +11 -11
  502. data/templates/default/module/dot/child.erb +1 -1
  503. data/templates/default/module/dot/dependencies.erb +2 -2
  504. data/templates/default/module/dot/header.erb +6 -6
  505. data/templates/default/module/dot/info.erb +13 -13
  506. data/templates/default/module/dot/setup.rb +15 -15
  507. data/templates/default/module/html/attribute_details.erb +10 -10
  508. data/templates/default/module/html/attribute_summary.erb +8 -8
  509. data/templates/default/module/html/box_info.erb +43 -43
  510. data/templates/default/module/html/children.erb +8 -8
  511. data/templates/default/module/html/constant_summary.erb +17 -17
  512. data/templates/default/module/html/defines.erb +2 -2
  513. data/templates/default/module/html/header.erb +5 -5
  514. data/templates/default/module/html/inherited_attributes.erb +14 -14
  515. data/templates/default/module/html/inherited_constants.erb +8 -8
  516. data/templates/default/module/html/inherited_methods.erb +18 -18
  517. data/templates/default/module/html/item_summary.erb +40 -40
  518. data/templates/default/module/html/method_details_list.erb +9 -9
  519. data/templates/default/module/html/method_summary.erb +13 -13
  520. data/templates/default/module/html/methodmissing.erb +12 -12
  521. data/templates/default/module/setup.rb +167 -167
  522. data/templates/default/module/text/children.erb +9 -9
  523. data/templates/default/module/text/class_meths_list.erb +7 -7
  524. data/templates/default/module/text/extends.erb +7 -7
  525. data/templates/default/module/text/header.erb +7 -7
  526. data/templates/default/module/text/includes.erb +7 -7
  527. data/templates/default/module/text/instance_meths_list.erb +7 -7
  528. data/templates/default/module/text/setup.rb +13 -13
  529. data/templates/default/onefile/html/files.erb +4 -4
  530. data/templates/default/onefile/html/headers.erb +6 -6
  531. data/templates/default/onefile/html/layout.erb +17 -17
  532. data/templates/default/onefile/html/readme.erb +2 -2
  533. data/templates/default/onefile/html/setup.rb +62 -62
  534. data/templates/default/root/dot/child.erb +2 -2
  535. data/templates/default/root/dot/setup.rb +6 -6
  536. data/templates/default/root/html/setup.rb +2 -2
  537. data/templates/default/tags/html/example.erb +10 -10
  538. data/templates/default/tags/html/index.erb +2 -2
  539. data/templates/default/tags/html/option.erb +24 -24
  540. data/templates/default/tags/html/overload.erb +13 -13
  541. data/templates/default/tags/html/see.erb +7 -7
  542. data/templates/default/tags/html/tag.erb +20 -20
  543. data/templates/default/tags/setup.rb +57 -57
  544. data/templates/default/tags/text/example.erb +12 -12
  545. data/templates/default/tags/text/index.erb +1 -1
  546. data/templates/default/tags/text/option.erb +20 -20
  547. data/templates/default/tags/text/overload.erb +19 -19
  548. data/templates/default/tags/text/see.erb +11 -11
  549. data/templates/default/tags/text/tag.erb +13 -13
  550. data/templates/guide/class/html/setup.rb +2 -2
  551. data/templates/guide/docstring/html/setup.rb +2 -2
  552. data/templates/guide/fulldoc/html/css/style.css +108 -108
  553. data/templates/guide/fulldoc/html/js/app.js +33 -33
  554. data/templates/guide/fulldoc/html/setup.rb +74 -74
  555. data/templates/guide/layout/html/layout.erb +81 -81
  556. data/templates/guide/layout/html/setup.rb +25 -25
  557. data/templates/guide/method/html/header.erb +17 -17
  558. data/templates/guide/method/html/setup.rb +22 -22
  559. data/templates/guide/module/html/header.erb +6 -6
  560. data/templates/guide/module/html/method_list.erb +4 -4
  561. data/templates/guide/module/html/setup.rb +27 -27
  562. data/templates/guide/onefile/html/files.erb +4 -4
  563. data/templates/guide/onefile/html/setup.rb +6 -6
  564. data/templates/guide/onefile/html/toc.erb +3 -3
  565. data/templates/guide/tags/html/setup.rb +9 -9
  566. data/yard.gemspec +43 -43
  567. metadata +4 -3
@@ -1,96 +1,96 @@
1
- # frozen_string_literal: true
2
- require 'stringio'
3
-
4
- RSpec.describe YARD::CLI::Stats do
5
- before do
6
- Registry.clear
7
- YARD.parse_string <<-eof
8
- class A
9
- CONST = 1
10
-
11
- def foo; end
12
-
13
- attr_reader :fooattr
14
-
15
- # Documented
16
- def bar; end
17
- end
18
- module B; end
19
- eof
20
-
21
- @main_stats =
22
- "Files: 1\n" \
23
- "Modules: 1 ( 1 undocumented)\n" \
24
- "Classes: 1 ( 1 undocumented)\n" \
25
- "Constants: 1 ( 1 undocumented)\n" \
26
- "Attributes: 1 ( 0 undocumented)\n" \
27
- "Methods: 2 ( 1 undocumented)\n" \
28
- " 33.33% documented\n"
29
-
30
- @output = StringIO.new
31
- @stats = CLI::Stats.new(false)
32
- allow(@stats).to receive(:support_rdoc_document_file!).and_return([])
33
- allow(@stats).to receive(:yardopts).and_return([])
34
- allow(log).to receive(:puts) {|*args| @output << args.join("\n") << "\n" }
35
- end
36
-
37
- it "lists undocumented objects with --list-undoc when there are undocumented objects" do
38
- @stats.run('--list-undoc')
39
- expect(@output.string).to eq <<-eof
40
- #{@main_stats}
41
- Undocumented Objects:
42
-
43
- (in file: (stdin))
44
- A
45
- A#foo
46
- A::CONST
47
- B
48
- eof
49
- end
50
-
51
- it "lists no undocumented objects with --list-undoc when there is nothing undocumented" do
52
- Registry.clear
53
- YARD.parse_string <<-eof
54
- # documentation
55
- def foo; end
56
- eof
57
- @stats.run('--list-undoc')
58
- expect(@output.string).to eq "Files: 1\n" \
59
- "Modules: 0 ( 0 undocumented)\n" \
60
- "Classes: 0 ( 0 undocumented)\n" \
61
- "Constants: 0 ( 0 undocumented)\n" \
62
- "Attributes: 0 ( 0 undocumented)\n" \
63
- "Methods: 1 ( 0 undocumented)\n" \
64
- " 100.00% documented\n"
65
- end
66
-
67
- it "lists undocumented objects in compact mode with --list-undoc --compact" do
68
- @stats.run('--list-undoc', '--compact')
69
- expect(@output.string).to eq <<-eof
70
- #{@main_stats}
71
- Undocumented Objects:
72
- A ((stdin):1)
73
- A#foo ((stdin):4)
74
- A::CONST ((stdin):2)
75
- B ((stdin):11)
76
- eof
77
- end
78
-
79
- it "still lists stats with --quiet" do
80
- @stats.run('--quiet')
81
- expect(@output.string).to eq @main_stats
82
- end
83
-
84
- it "ignores everything with --no-public" do
85
- @stats.run('--no-public')
86
- expect(@output.string).to eq(
87
- "Files: 0\n" \
88
- "Modules: 0 ( 0 undocumented)\n" \
89
- "Classes: 0 ( 0 undocumented)\n" \
90
- "Constants: 0 ( 0 undocumented)\n" \
91
- "Attributes: 0 ( 0 undocumented)\n" \
92
- "Methods: 0 ( 0 undocumented)\n" \
93
- " 100.00% documented\n"
94
- )
95
- end
96
- end
1
+ # frozen_string_literal: true
2
+ require 'stringio'
3
+
4
+ RSpec.describe YARD::CLI::Stats do
5
+ before do
6
+ Registry.clear
7
+ YARD.parse_string <<-eof
8
+ class A
9
+ CONST = 1
10
+
11
+ def foo; end
12
+
13
+ attr_reader :fooattr
14
+
15
+ # Documented
16
+ def bar; end
17
+ end
18
+ module B; end
19
+ eof
20
+
21
+ @main_stats =
22
+ "Files: 1\n" \
23
+ "Modules: 1 ( 1 undocumented)\n" \
24
+ "Classes: 1 ( 1 undocumented)\n" \
25
+ "Constants: 1 ( 1 undocumented)\n" \
26
+ "Attributes: 1 ( 0 undocumented)\n" \
27
+ "Methods: 2 ( 1 undocumented)\n" \
28
+ " 33.33% documented\n"
29
+
30
+ @output = StringIO.new
31
+ @stats = CLI::Stats.new(false)
32
+ allow(@stats).to receive(:support_rdoc_document_file!).and_return([])
33
+ allow(@stats).to receive(:yardopts).and_return([])
34
+ allow(log).to receive(:puts) {|*args| @output << args.join("\n") << "\n" }
35
+ end
36
+
37
+ it "lists undocumented objects with --list-undoc when there are undocumented objects" do
38
+ @stats.run('--list-undoc')
39
+ expect(@output.string).to eq <<-eof
40
+ #{@main_stats}
41
+ Undocumented Objects:
42
+
43
+ (in file: (stdin))
44
+ A
45
+ A#foo
46
+ A::CONST
47
+ B
48
+ eof
49
+ end
50
+
51
+ it "lists no undocumented objects with --list-undoc when there is nothing undocumented" do
52
+ Registry.clear
53
+ YARD.parse_string <<-eof
54
+ # documentation
55
+ def foo; end
56
+ eof
57
+ @stats.run('--list-undoc')
58
+ expect(@output.string).to eq "Files: 1\n" \
59
+ "Modules: 0 ( 0 undocumented)\n" \
60
+ "Classes: 0 ( 0 undocumented)\n" \
61
+ "Constants: 0 ( 0 undocumented)\n" \
62
+ "Attributes: 0 ( 0 undocumented)\n" \
63
+ "Methods: 1 ( 0 undocumented)\n" \
64
+ " 100.00% documented\n"
65
+ end
66
+
67
+ it "lists undocumented objects in compact mode with --list-undoc --compact" do
68
+ @stats.run('--list-undoc', '--compact')
69
+ expect(@output.string).to eq <<-eof
70
+ #{@main_stats}
71
+ Undocumented Objects:
72
+ A ((stdin):1)
73
+ A#foo ((stdin):4)
74
+ A::CONST ((stdin):2)
75
+ B ((stdin):11)
76
+ eof
77
+ end
78
+
79
+ it "still lists stats with --quiet" do
80
+ @stats.run('--quiet')
81
+ expect(@output.string).to eq @main_stats
82
+ end
83
+
84
+ it "ignores everything with --no-public" do
85
+ @stats.run('--no-public')
86
+ expect(@output.string).to eq(
87
+ "Files: 0\n" \
88
+ "Modules: 0 ( 0 undocumented)\n" \
89
+ "Classes: 0 ( 0 undocumented)\n" \
90
+ "Constants: 0 ( 0 undocumented)\n" \
91
+ "Attributes: 0 ( 0 undocumented)\n" \
92
+ "Methods: 0 ( 0 undocumented)\n" \
93
+ " 100.00% documented\n"
94
+ )
95
+ end
96
+ end
@@ -1,38 +1,38 @@
1
- # frozen_string_literal: true
2
-
3
- $TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
4
-
5
- require 'fileutils'
6
-
7
- RSpec.describe YARD::CLI::Yardoc do
8
- include FileUtils
9
-
10
- context 'building the documentation of YARD itself' do
11
- before(:context) do
12
- rm_rf File.join($TOPDIR, 'doc')
13
- rm_rf File.join($TOPDIR, '.yardoc')
14
-
15
- # Note: as this is very time consuming, we do it only once
16
- Dir.chdir($TOPDIR) do
17
- @res = YARD::CLI::Yardoc.new.run('--title', 'YARD-On-YARD')
18
- end
19
- end
20
-
21
- it 'succeeds and creates doc/ and .yardoc/' do
22
- expect(@res).to be true
23
- expect(Dir.exist?('doc')).to be true
24
- expect(Dir.exist?('.yardoc')).to be true
25
- end
26
-
27
- it 'writes the given title in each documentation file' do
28
- Dir.glob(File.join($TOPDIR, 'doc/**/*.html')) do |htmlfile|
29
- next if %w(
30
- frames file_list class_list method_list tag_list _index
31
- ).include?(File.basename(htmlfile, '.html'))
32
- html = File.read(htmlfile)
33
-
34
- expect(html.index('&mdash; YARD-On-YARD')).to be >= 0
35
- end
36
- end
37
- end
38
- end if ENV['CI'] || ENV['YY']
1
+ # frozen_string_literal: true
2
+
3
+ $TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
4
+
5
+ require 'fileutils'
6
+
7
+ RSpec.describe YARD::CLI::Yardoc do
8
+ include FileUtils
9
+
10
+ context 'building the documentation of YARD itself' do
11
+ before(:context) do
12
+ rm_rf File.join($TOPDIR, 'doc')
13
+ rm_rf File.join($TOPDIR, '.yardoc')
14
+
15
+ # Note: as this is very time consuming, we do it only once
16
+ Dir.chdir($TOPDIR) do
17
+ @res = YARD::CLI::Yardoc.new.run('--title', 'YARD-On-YARD')
18
+ end
19
+ end
20
+
21
+ it 'succeeds and creates doc/ and .yardoc/' do
22
+ expect(@res).to be true
23
+ expect(Dir.exist?('doc')).to be true
24
+ expect(Dir.exist?('.yardoc')).to be true
25
+ end
26
+
27
+ it 'writes the given title in each documentation file' do
28
+ Dir.glob(File.join($TOPDIR, 'doc/**/*.html')) do |htmlfile|
29
+ next if %w(
30
+ frames file_list class_list method_list tag_list _index
31
+ ).include?(File.basename(htmlfile, '.html'))
32
+ html = File.read(htmlfile)
33
+
34
+ expect(html.index('&mdash; YARD-On-YARD')).to be >= 0
35
+ end
36
+ end
37
+ end
38
+ end if ENV['CI'] || ENV['YY']
@@ -1,862 +1,896 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::CLI::Yardoc do
4
- before do
5
- @yardoc = YARD::CLI::Yardoc.new
6
- @yardoc.statistics = false
7
- @yardoc.use_document_file = false
8
- @yardoc.use_yardopts_file = false
9
- @yardoc.generate = false
10
- allow(Templates::Engine).to receive(:render)
11
- allow(Templates::Engine).to receive(:generate)
12
- allow(YARD).to receive(:parse)
13
- allow(Registry).to receive(:load)
14
- allow(Registry).to receive(:save)
15
- allow(File).to receive(:open!)
16
- end
17
-
18
- describe "Defaults" do
19
- before do
20
- @yardoc = CLI::Yardoc.new
21
- allow(@yardoc).to receive(:yardopts).and_return([])
22
- allow(@yardoc).to receive(:support_rdoc_document_file!).and_return([])
23
- @yardoc.parse_arguments
24
- end
25
-
26
- it "does not use cache by default" do
27
- expect(@yardoc.use_cache).to be false
28
- end
29
-
30
- it "prints statistics by default" do
31
- expect(@yardoc.statistics).to be true
32
- end
33
-
34
- it "generates output by default" do
35
- expect(@yardoc.generate).to be true
36
- end
37
-
38
- it "reads .yardopts by default" do
39
- expect(@yardoc.use_yardopts_file).to be true
40
- end
41
-
42
- it "reads .document by default" do
43
- expect(@yardoc.use_document_file).to be true
44
- end
45
-
46
- it "uses lib, app, and ext as default file glob paths" do
47
- expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
48
- end
49
-
50
- it "uses rdoc as default markup type (but falls back on none)" do
51
- expect(@yardoc.options.markup).to eq :rdoc
52
- end
53
-
54
- it "uses default as default template" do
55
- expect(@yardoc.options.template).to eq :default
56
- end
57
-
58
- it "uses HTML as default format" do
59
- expect(@yardoc.options.format).to eq :html
60
- end
61
-
62
- it "uses 'Object' as default return type" do
63
- expect(@yardoc.options.default_return).to eq 'Object'
64
- end
65
-
66
- it "does not hide void return types by default" do
67
- expect(@yardoc.options.hide_void_return).to be false
68
- end
69
-
70
- it "only shows public visibility by default" do
71
- expect(@yardoc.visibilities).to eq [:public]
72
- end
73
-
74
- it "does not list objects by default" do
75
- expect(@yardoc.list).to be false
76
- end
77
-
78
- it "does not embed mixins by default" do
79
- expect(@yardoc.options.embed_mixins).to be_empty
80
- end
81
-
82
- it "does not set any locale by default" do
83
- expect(@yardoc.options.locale).to be nil
84
- end
85
- end
86
-
87
- describe "General options" do
88
- def self.should_accept(*args, &block)
89
- @counter ||= 0
90
- @counter += 1
91
- counter = @counter
92
- define_method("test_options_#{@counter}", &block)
93
- args.each do |arg|
94
- it("accepts #{arg}") { send("test_options_#{counter}", arg) }
95
- end
96
- end
97
-
98
- should_accept('--single-db') do |arg|
99
- @yardoc.parse_arguments(arg)
100
- expect(Registry.single_object_db).to be true
101
- Registry.single_object_db = nil
102
- end
103
-
104
- should_accept('--no-single-db') do |arg|
105
- @yardoc.parse_arguments(arg)
106
- expect(Registry.single_object_db).to be false
107
- Registry.single_object_db = nil
108
- end
109
-
110
- should_accept('-c', '--use-cache') do |arg|
111
- @yardoc.parse_arguments(arg)
112
- expect(@yardoc.use_cache).to be true
113
- end
114
-
115
- should_accept('--no-cache') do |arg|
116
- @yardoc.parse_arguments(arg)
117
- expect(@yardoc.use_cache).to be false
118
- end
119
-
120
- should_accept('--yardopts') do |arg|
121
- @yardoc = CLI::Yardoc.new
122
- @yardoc.use_document_file = false
123
- expect(@yardoc).to receive(:yardopts).at_least(1).times.and_return([])
124
- @yardoc.parse_arguments(arg)
125
- expect(@yardoc.use_yardopts_file).to be true
126
- @yardoc.parse_arguments('--no-yardopts', arg)
127
- expect(@yardoc.use_yardopts_file).to be true
128
- end
129
-
130
- should_accept('--yardopts with filename') do |_arg|
131
- @yardoc = CLI::Yardoc.new
132
- expect(File).to receive(:read_binary).with('.foobar').and_return('')
133
- @yardoc.use_document_file = false
134
- @yardoc.parse_arguments('--yardopts', '.foobar')
135
- expect(@yardoc.use_yardopts_file).to be true
136
- expect(@yardoc.options_file).to eq '.foobar'
137
- end
138
-
139
- should_accept('--no-yardopts') do |arg|
140
- @yardoc = CLI::Yardoc.new
141
- @yardoc.use_document_file = false
142
- expect(@yardoc).not_to receive(:yardopts)
143
- @yardoc.parse_arguments(arg)
144
- expect(@yardoc.use_yardopts_file).to be false
145
- @yardoc.parse_arguments('--yardopts', arg)
146
- expect(@yardoc.use_yardopts_file).to be false
147
- end
148
-
149
- should_accept('--document') do |arg|
150
- @yardoc = CLI::Yardoc.new
151
- @yardoc.use_yardopts_file = false
152
- expect(@yardoc).to receive(:support_rdoc_document_file!).and_return([])
153
- @yardoc.parse_arguments('--no-document', arg)
154
- expect(@yardoc.use_document_file).to be true
155
- end
156
-
157
- should_accept('--no-document') do |arg|
158
- @yardoc = CLI::Yardoc.new
159
- @yardoc.use_yardopts_file = false
160
- expect(@yardoc).not_to receive(:support_rdoc_document_file!)
161
- @yardoc.parse_arguments('--document', arg)
162
- expect(@yardoc.use_document_file).to be false
163
- end
164
-
165
- should_accept('-b', '--db') do |arg|
166
- @yardoc.parse_arguments(arg, 'test')
167
- expect(Registry.yardoc_file).to eq 'test'
168
- Registry.yardoc_file = '.yardoc'
169
- end
170
-
171
- should_accept('-n', '--no-output') do |arg|
172
- expect(Templates::Engine).not_to receive(:generate)
173
- @yardoc.run(arg)
174
- end
175
-
176
- should_accept('--exclude') do |arg|
177
- expect(YARD).to receive(:parse).with(['a'], ['nota', 'b'])
178
- @yardoc.run(arg, 'nota', arg, 'b', 'a')
179
- end
180
-
181
- should_accept('--no-save') do |arg|
182
- expect(YARD).to receive(:parse)
183
- expect(Registry).not_to receive(:save)
184
- @yardoc.run(arg)
185
- end
186
-
187
- # This example relies on processing Yard's own documentation, and with
188
- # --fail-on-warning option on, will raise a SystemExit error if building
189
- # that documentation produces any one warning.
190
- #
191
- # Unless handled, it will cause immediate and abnormal process exit,
192
- # without running remaining tests, and with non-successful exit status.
193
- #
194
- # While suppressing exceptions is generally a bad practice and against this
195
- # project's style guide, here it is well advocated,
196
- # hence Lint/HandleExceptions cop is disabled.
197
- should_accept('--fail-on-warning') do |arg|
198
- expect(YARD).to receive(:parse)
199
- begin
200
- @yardoc.run(arg)
201
- rescue SystemExit # rubocop:disable Lint/HandleExceptions
202
- end
203
- end
204
- end
205
-
206
- describe "Output options" do
207
- it "accepts --title" do
208
- @yardoc.parse_arguments('--title', 'hello world')
209
- expect(@yardoc.options.title).to eq 'hello world'
210
- end
211
-
212
- it "allows --title to have multiple spaces in .yardopts" do
213
- expect(File).to receive(:read_binary).with("test").and_return("--title \"Foo Bar\"")
214
- @yardoc.options_file = "test"
215
- @yardoc.use_yardopts_file = true
216
- @yardoc.run
217
- expect(@yardoc.options.title).to eq "Foo Bar"
218
- end
219
-
220
- it "aliases --main to the --readme flag" do
221
- Dir.chdir(File.join(File.dirname(__FILE__), '..', '..')) do
222
- @yardoc.parse_arguments('--main', 'README.md')
223
- expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.md', '')
224
- end
225
- end
226
-
227
- it "selects a markup provider when --markup-provider or -mp is set" do
228
- @yardoc.parse_arguments("-M", "test")
229
- expect(@yardoc.options.markup_provider).to eq :test
230
- @yardoc.parse_arguments("--markup-provider", "test2")
231
- expect(@yardoc.options.markup_provider).to eq :test2
232
- end
233
-
234
- it "selects a markup format when -m is set" do
235
- expect(@yardoc).to receive(:verify_markup_options).and_return(true)
236
- @yardoc.generate = true
237
- @yardoc.parse_arguments('-m', 'markdown')
238
- expect(@yardoc.options.markup).to eq :markdown
239
- end
240
-
241
- it "accepts --default-return" do
242
- @yardoc.parse_arguments(*%w(--default-return XYZ))
243
- expect(@yardoc.options.default_return).to eq "XYZ"
244
- end
245
-
246
- it "allows --hide-void-return to be set" do
247
- @yardoc.parse_arguments(*%w(--hide-void-return))
248
- expect(@yardoc.options.hide_void_return).to be true
249
- end
250
-
251
- it "accepts --embed-mixins" do
252
- @yardoc.parse_arguments(*%w(--embed-mixins))
253
- expect(@yardoc.options.embed_mixins).to eq ['*']
254
- end
255
-
256
- it "accepts --embed-mixin MODULE" do
257
- @yardoc.parse_arguments(*%w(--embed-mixin MyModule))
258
- expect(@yardoc.options.embed_mixins).to eq ['MyModule']
259
- end
260
-
261
- it "generates all objects with --use-cache" do
262
- expect(YARD).to receive(:parse)
263
- expect(Registry).to receive(:load)
264
- expect(Registry).to receive(:load_all)
265
- allow(@yardoc).to receive(:generate).and_return(true)
266
- @yardoc.run(*%w(--use-cache))
267
- end
268
-
269
- it "does not print statistics with --no-stats" do
270
- allow(@yardoc).to receive(:statistics).and_return(false)
271
- expect(CLI::Stats).not_to receive(:new)
272
- @yardoc.run(*%w(--no-stats))
273
- end
274
-
275
- it "disables progress bar with --no-progress" do
276
- old = log.show_progress
277
- log.show_progress = true
278
- @yardoc.run(*%w(--no-progress))
279
- expect(log.show_progress).to eq false
280
- log.show_progress = old
281
- end
282
-
283
- describe "--asset" do
284
- before do
285
- @yardoc.generate = true
286
- allow(@yardoc).to receive(:run_generate)
287
- end
288
-
289
- it "copies assets to output directory" do
290
- expect(FileUtils).to receive(:cp_r).with('a', 'doc/a')
291
- @yardoc.run(*%w(--asset a))
292
- expect(@yardoc.assets).to eq('a' => 'a')
293
- end
294
-
295
- it "allows multiple --asset options" do
296
- expect(FileUtils).to receive(:cp_r).with('a', 'doc/a')
297
- expect(FileUtils).to receive(:cp_r).with('b', 'doc/b')
298
- @yardoc.run(*%w(--asset a --asset b))
299
- expect(@yardoc.assets).to eq('a' => 'a', 'b' => 'b')
300
- end
301
-
302
- it "does not allow from or to to refer to a path above current path" do
303
- expect(log).to receive(:warn).exactly(4).times.with(/invalid/i)
304
- @yardoc.run(*%w(--asset ../../../etc/passwd))
305
- expect(@yardoc.assets).to be_empty
306
- @yardoc.run(*%w(--asset a/b/c/d/../../../../../../etc/passwd))
307
- expect(@yardoc.assets).to be_empty
308
- @yardoc.run(*%w(--asset /etc/passwd))
309
- expect(@yardoc.assets).to be_empty
310
- @yardoc.run(*%w(--asset normal:/etc/passwd))
311
- expect(@yardoc.assets).to be_empty
312
- end
313
-
314
- it "allows from:to syntax" do
315
- expect(FileUtils).to receive(:cp_r).with(%r{foo(\/\.)?}, 'doc/bar')
316
- @yardoc.run(*%w(--asset foo:bar))
317
- expect(@yardoc.assets).to eq('foo' => 'bar')
318
- end
319
-
320
- it "does not put from inside of to/ if from is a directory" do
321
- begin
322
- from = 'tmp_foo'
323
- to = 'tmp_bar'
324
- full_to = File.join(File.dirname(__FILE__), to)
325
- FileUtils.mkdir_p(from)
326
- @yardoc.options.serializer.basepath = File.dirname(__FILE__)
327
- @yardoc.run("--asset", "#{from}:#{to}")
328
- @yardoc.run("--asset", "#{from}:#{to}")
329
- expect(File.directory?(full_to)).to be true
330
- expect(File.directory?(File.join(full_to, 'tmp_foo'))).to be false
331
- ensure
332
- FileUtils.rm_rf(from)
333
- FileUtils.rm_rf(full_to)
334
- end
335
- end
336
- end
337
-
338
- describe "--locale" do
339
- it "applies specified locale to all extra file objects" do
340
- allow(File).to receive(:read).with('extra_file1').and_return('')
341
- allow(File).to receive(:read).with('extra_file2').and_return('')
342
-
343
- extra_file_object1 = CodeObjects::ExtraFileObject.new('extra_file1')
344
- extra_file_object2 = CodeObjects::ExtraFileObject.new('extra_file2')
345
- expect(extra_file_object1).to receive(:locale=).with('fr')
346
- expect(extra_file_object2).to receive(:locale=).with('fr')
347
-
348
- allow(CodeObjects::ExtraFileObject).to receive(:new).with('extra_file1').and_return(extra_file_object1)
349
- allow(CodeObjects::ExtraFileObject).to receive(:new).with('extra_file2').and_return(extra_file_object2)
350
- allow(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
351
- allow(File).to receive(:file?).with('extra_file1').and_return(true)
352
- allow(File).to receive(:file?).with('extra_file2').and_return(true)
353
- @yardoc.run('--locale=fr', '-', 'extra_file1', 'extra_file2')
354
- end
355
- end
356
-
357
- describe "--po-dir" do
358
- it "sets Registry.po_dir" do
359
- expect(Registry).to receive(:po_dir=).with("locale")
360
- @yardoc.run('--po-dir=locale')
361
- end
362
- end
363
- end
364
-
365
- describe "--[no-]api" do
366
- before { Registry.clear }
367
-
368
- it "allows --api name" do
369
- YARD.parse_string <<-eof
370
- # @api private
371
- class Foo; end
372
- # @api public
373
- class Bar; end
374
- class Baz; end
375
- eof
376
- @yardoc.run('--api', 'private')
377
- expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Foo')]
378
- end
379
-
380
- it "allows multiple --api's to all be shown" do
381
- YARD.parse_string <<-eof
382
- # @api private
383
- class Foo; end
384
- # @api public
385
- class Bar; end
386
- class Baz; end
387
- eof
388
- @yardoc.run('--api', 'private', '--api', 'public')
389
- expect(@yardoc.options.verifier.run(Registry.all).
390
- sort_by(&:path)).to eq [P('Bar'), P('Foo')]
391
- end
392
-
393
- it "allows --no-api to specify objects with no @api tag" do
394
- YARD.parse_string <<-eof
395
- # @api private
396
- class Foo; end
397
- # @api public
398
- class Bar; end
399
- class Baz; end
400
- eof
401
- @yardoc.run('--api', '')
402
- expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Baz')]
403
- @yardoc.options.verifier = Verifier.new
404
- @yardoc.run('--no-api')
405
- expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Baz')]
406
- end
407
-
408
- it "allows --no-api to work with other --api switches" do
409
- YARD.parse_string <<-eof
410
- # @api private
411
- class Foo; end
412
- # @api public
413
- class Bar; end
414
- class Baz; end
415
- eof
416
- @yardoc.run('--no-api', '--api', 'public')
417
- expect(@yardoc.options.verifier.run(Registry.all).
418
- sort_by(&:path)).to eq [P('Bar'), P('Baz')]
419
- end
420
-
421
- it "ensures Ruby code cannot be used" do
422
- [':symbol', '42', '"; exit'].each do |ruby|
423
- @yardoc.options.verifier.expressions = []
424
- @yardoc.run('--api', ruby)
425
- expect(@yardoc.options.verifier.expressions[1]).to include(ruby.inspect)
426
- end
427
- end
428
- end
429
-
430
- describe "--hide-api option" do
431
- it "allows --hide-api to hide objects with api tags" do
432
- YARD.parse_string <<-eof
433
- # @api private
434
- class Foo; end
435
- class Bar; end
436
- class Baz; end
437
- eof
438
- @yardoc.run('--hide-api', 'private')
439
- expect(@yardoc.options.verifier.run(Registry.all).
440
- sort_by(&:path)).to eq [P('Bar'), P('Baz')]
441
- end
442
-
443
- it "allows --hide-api to work with --api" do
444
- YARD.parse_string <<-eof
445
- # @api private
446
- class Foo; end
447
- # @api public
448
- class Bar; end
449
- class Baz; end
450
- eof
451
- @yardoc.run('--api', 'public', '--hide-api', 'private')
452
- expect(@yardoc.options.verifier.run(Registry.all).
453
- sort_by(&:path)).to eq [P('Bar')]
454
- end
455
- end
456
-
457
- describe "--no-private option" do
458
- it "accepts --no-private" do
459
- obj = double(:object)
460
- expect(obj).to receive(:tag).ordered.with(:private).and_return(true)
461
- @yardoc.parse_arguments(*%w(--no-private))
462
- expect(@yardoc.options.verifier.call(obj)).to be false
463
- end
464
-
465
- it "hides object if namespace is @private with --no-private" do
466
- ns = double(:namespace, :type => :module)
467
- expect(ns).to receive(:tag).with(:private).and_return(true)
468
- obj = double(:object, :namespace => ns)
469
- expect(obj).to receive(:tag).with(:private).and_return(false)
470
- @yardoc.parse_arguments(*%w(--no-private))
471
- expect(@yardoc.options.verifier.call(obj)).to be false
472
- end
473
-
474
- it "does not call #tag on namespace if namespace is proxy with --no-private" do
475
- ns = double(:namespace)
476
- expect(ns).to receive(:is_a?).with(CodeObjects::Proxy).and_return(true)
477
- expect(ns).not_to receive(:tag)
478
- obj = double(:object, :type => :class, :namespace => ns, :visibility => :public)
479
- expect(obj).to receive(:tag).ordered.with(:private).and_return(false)
480
- @yardoc.parse_arguments(*%w(--no-private))
481
- expect(@yardoc.options.verifier.call(obj)).to be true
482
- end
483
-
484
- # @bug gh-197
485
- it "does not call #tag on namespace if namespace is proxy with --no-private" do
486
- Registry.clear
487
- YARD.parse_string "module Qux; class Foo::Bar; end; end"
488
- foobar = Registry.at('Foo::Bar')
489
- foobar.namespace.type = :module
490
- @yardoc.parse_arguments(*%w(--no-private))
491
- expect(@yardoc.options.verifier.call(foobar)).to be true
492
- end
493
-
494
- it "does not call #tag on proxy object" do # @bug gh-197
495
- @yardoc.parse_arguments(*%w(--no-private))
496
- expect(@yardoc.options.verifier.call(P('ProxyClass'))).to be true
497
- end
498
-
499
- it "hides methods inside a 'private' class/module with --no-private" do
500
- Registry.clear
501
- YARD.parse_string <<-eof
502
- # @private
503
- class ABC
504
- def foo; end
505
- end
506
- eof
507
- @yardoc.parse_arguments(*%w(--no-private))
508
- expect(@yardoc.options.verifier.call(Registry.at('ABC'))).to be false
509
- expect(@yardoc.options.verifier.call(Registry.at('ABC#foo'))).to be false
510
- end
511
- end
512
-
513
- describe ".yardopts and .document handling" do
514
- before do
515
- @yardoc.use_yardopts_file = true
516
- end
517
-
518
- it "searches for and uses yardopts file specified by #options_file" do
519
- expect(File).to receive(:read_binary).with("test").and_return("-o \n\nMYPATH\nFILE1 FILE2")
520
- @yardoc.use_document_file = false
521
- @yardoc.options_file = "test"
522
- @yardoc.run
523
- expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
524
- expect(@yardoc.files).to eq ["FILE1", "FILE2"]
525
- end
526
-
527
- it "uses String#shell_split to split .yardopts tokens" do
528
- optsdata = String.new("foo bar")
529
- expect(optsdata).to receive(:shell_split)
530
- expect(File).to receive(:read_binary).with("test").and_return(optsdata)
531
- @yardoc.options_file = "test"
532
- @yardoc.run
533
- end
534
-
535
- it "allows opts specified in command line to override yardopts file" do
536
- expect(File).to receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
537
- @yardoc.run("-o", "MYPATH", "FILE")
538
- expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
539
- expect(@yardoc.files).to eq ["FILE"]
540
- end
541
-
542
- it "loads the RDoc .document file if found" do
543
- expect(File).to receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
544
- @yardoc.use_document_file = true
545
- allow(@yardoc).to receive(:support_rdoc_document_file!).and_return(["FILE2", "FILE3"])
546
- @yardoc.run("-o", "MYPATH", "FILE1")
547
- expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
548
- expect(@yardoc.files).to eq ["FILE2", "FILE3", "FILE1"]
549
- end
550
- end
551
-
552
- describe "Query options" do
553
- after { Registry.clear }
554
-
555
- it "hides private constants in with default visibilities" do
556
- classobj = CodeObjects::ClassObject.new(:root, :Foo) {|o| o.visibility = :private }
557
- @yardoc.run
558
- expect(@yardoc.options.verifier.run([classobj])).to eq []
559
- end
560
-
561
- it "sets up visibility rules as verifier" do
562
- methobj = CodeObjects::MethodObject.new(:root, :test) {|o| o.visibility = :private }
563
- expect(File).to receive(:read_binary).with("test").and_return("--private")
564
- @yardoc.use_yardopts_file = true
565
- @yardoc.options_file = "test"
566
- @yardoc.run
567
- expect(@yardoc.options.verifier.call(methobj)).to be true
568
- end
569
-
570
- it "accepts a --query" do
571
- @yardoc.parse_arguments(*%w(--query @return))
572
- expect(@yardoc.options.verifier).to be_a(Verifier)
573
- end
574
-
575
- it "accepts multiple --query arguments" do
576
- obj = double(:object)
577
- expect(obj).to receive(:tag).ordered.with('return').and_return(true)
578
- expect(obj).to receive(:tag).ordered.with('tag').and_return(false)
579
- @yardoc.parse_arguments(*%w(--query @return --query @tag))
580
- expect(@yardoc.options.verifier).to be_a(Verifier)
581
- expect(@yardoc.options.verifier.call(obj)).to be false
582
- end
583
- end
584
-
585
- describe "Extra file arguments" do
586
- it "accepts extra files if specified after '-' with source files" do
587
- expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
588
- expect(File).to receive(:file?).with('extra_file1').and_return(true)
589
- expect(File).to receive(:file?).with('extra_file2').and_return(true)
590
- expect(File).to receive(:read).with('extra_file1').and_return('')
591
- expect(File).to receive(:read).with('extra_file2').and_return('')
592
- @yardoc.parse_arguments(*%w(file1 file2 - extra_file1 extra_file2))
593
- expect(@yardoc.files).to eq %w(file1 file2)
594
- expect(@yardoc.options.files).to eq(
595
- [CodeObjects::ExtraFileObject.new('extra_file1', ''),
596
- CodeObjects::ExtraFileObject.new('extra_file2', '')]
597
- )
598
- end
599
-
600
- it "accepts files section only containing extra files" do
601
- expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
602
- @yardoc.parse_arguments(*%w(- LICENSE))
603
- expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
604
- expect(@yardoc.options.files).to eq [CodeObjects::ExtraFileObject.new('LICENSE', '')]
605
- end
606
-
607
- it "accepts globs as extra files" do
608
- expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return []
609
- expect(Dir).to receive(:glob).with('*.txt').and_return ['a.txt', 'b.txt']
610
- expect(File).to receive(:read).with('a.txt').and_return('')
611
- expect(File).to receive(:read).with('b.txt').and_return('')
612
- expect(File).to receive(:file?).with('a.txt').and_return(true)
613
- expect(File).to receive(:file?).with('b.txt').and_return(true)
614
- @yardoc.parse_arguments(*%w(file1 file2 - *.txt))
615
- expect(@yardoc.files).to eq %w(file1 file2)
616
- expect(@yardoc.options.files).to eq(
617
- [CodeObjects::ExtraFileObject.new('a.txt', ''),
618
- CodeObjects::ExtraFileObject.new('b.txt', '')]
619
- )
620
- end
621
-
622
- it "warns if extra file is not found" do
623
- expect(log).to receive(:warn).with(/Could not find file: UNKNOWN/)
624
- @yardoc.parse_arguments(*%w(- UNKNOWN))
625
- end
626
-
627
- it "warns if readme file is not found" do
628
- expect(log).to receive(:warn).with(/Could not find file: UNKNOWN/)
629
- @yardoc.parse_arguments(*%w(-r UNKNOWN))
630
- end
631
-
632
- it "warns on absolute paths in extra files" do
633
- expect(log).to receive(:warn).with(%r{Invalid file: /path/to/file})
634
- @yardoc.parse_arguments(*%w(- /path/to/file))
635
- end
636
-
637
- it "warns on absolute paths in readme" do
638
- expect(log).to receive(:warn).with(%r{Invalid file: /path/to/file})
639
- @yardoc.parse_arguments(*%w(-r /path/to/file))
640
- end
641
-
642
- it "uses first file as readme if no readme is specified when using --one-file" do
643
- expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return []
644
- expect(Dir).to receive(:glob).with('lib/*.rb').and_return(['lib/foo.rb'])
645
- expect(File).to receive(:read).with('lib/foo.rb').and_return('')
646
- @yardoc.parse_arguments(*%w(--one-file lib/*.rb))
647
- expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('lib/foo.rb', '')
648
- end
649
-
650
- it "uses readme it exists when using --one-file" do
651
- expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README']
652
- expect(File).to receive(:read).with('README').and_return('')
653
- @yardoc.parse_arguments(*%w(--one-file lib/*.rb))
654
- expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README', '')
655
- end
656
-
657
- it "does not allow US-ASCII charset when using --one-file" do
658
- ienc = Encoding.default_internal
659
- eenc = Encoding.default_external
660
- expect(log).to receive(:warn).with(/not compatible with US-ASCII.*using ASCII-8BIT/)
661
- @yardoc.parse_arguments(*%w(--one-file --charset us-ascii))
662
- expect(Encoding.default_internal.name).to eq 'ASCII-8BIT'
663
- expect(Encoding.default_external.name).to eq 'ASCII-8BIT'
664
- Encoding.default_internal = ienc
665
- Encoding.default_external = eenc
666
- end if defined?(::Encoding)
667
- end
668
-
669
- describe "Source file arguments" do
670
- it "accepts no params and parse {lib,app}/**/*.rb ext/**/*.c" do
671
- @yardoc.parse_arguments
672
- expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
673
- end
674
- end
675
-
676
- describe "Tags options" do
677
- def tag_created(switch, factory_method)
678
- visible_tags = double(:visible_tags)
679
- expect(visible_tags).to receive(:|).ordered.with([:foo])
680
- expect(visible_tags).to receive(:-).ordered.with([]).and_return(visible_tags)
681
- expect(Tags::Library).to receive(:define_tag).with('Foo', :foo, factory_method)
682
- allow(Tags::Library).to receive(:visible_tags=)
683
- expect(Tags::Library).to receive(:visible_tags).at_least(1).times.and_return(visible_tags)
684
- @yardoc.parse_arguments("--#{switch}-tag", 'foo')
685
- end
686
-
687
- def tag_hidden(tag)
688
- visible_tags = double(:visible_tags)
689
- expect(visible_tags).to receive(:|).ordered.with([tag])
690
- expect(visible_tags).to receive(:-).ordered.with([tag]).and_return([])
691
- expect(Tags::Library).to receive(:define_tag).with(tag.to_s.capitalize, tag, nil)
692
- allow(Tags::Library).to receive(:visible_tags=)
693
- expect(Tags::Library).to receive(:visible_tags).at_least(1).times.and_return(visible_tags)
694
- end
695
-
696
- it "accepts --tag" do
697
- expect(Tags::Library).to receive(:define_tag).with('Title of Foo', :foo, nil)
698
- @yardoc.parse_arguments('--tag', 'foo:Title of Foo')
699
- end
700
-
701
- it "accepts --tag without title (and default to capitalized tag name)" do
702
- expect(Tags::Library).to receive(:define_tag).with('Foo', :foo, nil)
703
- @yardoc.parse_arguments('--tag', 'foo')
704
- end
705
-
706
- it "only lists tag once if declared twice" do
707
- visible_tags = []
708
- allow(Tags::Library).to receive(:define_tag)
709
- allow(Tags::Library).to receive(:visible_tags).and_return([:foo])
710
- allow(Tags::Library).to receive(:visible_tags=) {|value| visible_tags = value }
711
- @yardoc.parse_arguments('--tag', 'foo', '--tag', 'foo')
712
- expect(visible_tags).to eq [:foo]
713
- end
714
-
715
- it "accepts --type-tag" do
716
- tag_created 'type', :with_types
717
- end
718
-
719
- it "accepts --type-name-tag" do
720
- tag_created 'type-name', :with_types_and_name
721
- end
722
-
723
- it "accepts --name-tag" do
724
- tag_created 'name', :with_name
725
- end
726
-
727
- it "accepts --title-tag" do
728
- tag_created 'title', :with_title_and_text
729
- end
730
-
731
- it "accepts --hide-tag before tag is listed" do
732
- tag_hidden(:anewfoo)
733
- @yardoc.parse_arguments('--hide-tag', 'anewfoo', '--tag', 'anewfoo')
734
- end
735
-
736
- it "accepts --hide-tag after tag is listed" do
737
- tag_hidden(:anewfoo2)
738
- @yardoc.parse_arguments('--tag', 'anewfoo2', '--hide-tag', 'anewfoo2')
739
- end
740
-
741
- it "accepts --transitive-tag" do
742
- @yardoc.parse_arguments('--transitive-tag', 'foo')
743
- expect(Tags::Library.transitive_tags).to include(:foo)
744
- end
745
-
746
- it "accepts --non-transitive-tag" do
747
- Tags::Library.transitive_tags |= [:foo]
748
- @yardoc.parse_arguments('--non-transitive-tag', 'foo')
749
- expect(Tags::Library.transitive_tags).not_to include(:foo)
750
- end
751
- end
752
-
753
- describe "Safe mode" do
754
- before do
755
- allow(YARD::Config).to receive(:options).and_return(:safe_mode => true)
756
- end
757
-
758
- it "does not allow --load or -e in safe mode" do
759
- expect(@yardoc).not_to receive(:require)
760
- @yardoc.run('--load', 'foo')
761
- @yardoc.run('-e', 'foo')
762
- end
763
-
764
- it "does not allow --query in safe mode" do
765
- @yardoc.run('--query', 'foo')
766
- expect(@yardoc.options.verifier.expressions).not_to include("foo")
767
- end
768
-
769
- it "does not allow modifying the template paths" do
770
- expect(YARD::Templates::Engine).not_to receive(:register_template_path)
771
- @yardoc.run('-p', 'foo')
772
- @yardoc.run('--template-path', 'foo')
773
- end
774
- end
775
-
776
- describe "Markup Loading" do
777
- it "loads rdoc markup if no markup is provided" do
778
- @yardoc.generate = true
779
- @yardoc.run
780
- expect(@yardoc.options.markup).to eq :rdoc
781
- end
782
-
783
- it "loads rdoc markup even when no output is specified" do
784
- @yardoc.parse_arguments('--no-output')
785
- expect(@yardoc.options.markup).to eq :rdoc
786
- end
787
-
788
- it "warns if rdoc cannot be loaded and fallback to :none" do
789
- mod = YARD::Templates::Helpers::MarkupHelper
790
- mod.clear_markup_cache
791
- expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:rdoc).and_return([{:lib => 'INVALID'}])
792
- expect(log).to receive(:warn).with(/Could not load default RDoc formatter/)
793
- allow(@yardoc).to receive(:generate) { @yardoc.options.files = []; true }
794
- @yardoc.run
795
- expect(@yardoc.options.markup).to eq :none
796
- mod.clear_markup_cache
797
- end
798
-
799
- it "returns an error immediately if markup for any files are missing" do
800
- mod = YARD::Templates::Helpers::MarkupHelper
801
- mod.clear_markup_cache
802
- expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
803
- expect(log).to receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
804
- files = [CodeObjects::ExtraFileObject.new('test.md', '')]
805
- allow(@yardoc).to receive(:generate) { @yardoc.options.files = files; true }
806
- @yardoc.run
807
- mod.clear_markup_cache
808
- end
809
-
810
- it "returns an error immediately if markup for any files are missing (file markup specified in attributes)" do
811
- mod = YARD::Templates::Helpers::MarkupHelper
812
- mod.clear_markup_cache
813
- expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
814
- expect(log).to receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
815
- files = [CodeObjects::ExtraFileObject.new('test', '# @markup markdown')]
816
- allow(@yardoc).to receive(:generate) { @yardoc.options.files = files; true }
817
- @yardoc.run
818
- mod.clear_markup_cache
819
- end
820
- end
821
-
822
- describe "#run" do
823
- it "parses arguments if run() is called" do
824
- expect(@yardoc).to receive(:parse_arguments)
825
- @yardoc.run
826
- end
827
-
828
- it "parses arguments if run(arg1, arg2, ...) is called" do
829
- expect(@yardoc).to receive(:parse_arguments)
830
- @yardoc.run('--private', '-p', 'foo')
831
- end
832
-
833
- it "does not parse arguments if run(nil) is called" do
834
- expect(@yardoc).not_to receive(:parse_arguments)
835
- @yardoc.run(nil)
836
- end
837
-
838
- it "creates processing lock if saving" do
839
- expect(Registry).to receive(:lock_for_writing).and_yield
840
- @yardoc.run
841
- end
842
-
843
- it "does not create processing lock if not saving" do
844
- expect(Registry).not_to receive(:lock_for_writing)
845
- @yardoc.run('--no-save')
846
- end
847
-
848
- context "with --fail-on-warning" do
849
- it "exits with error status code if a warning occurs" do
850
- allow(log).to receive(:warned).and_return(true)
851
- expect { @yardoc.run("--fail-on-warning") }.to raise_error(SystemExit) do |error|
852
- expect(error).not_to be_success
853
- end
854
- end
855
-
856
- it "does not exit if a warning does not occur" do
857
- allow(log).to receive(:warned).and_return(false)
858
- expect { @yardoc.run("--fail-on-warning") }.not_to raise_error
859
- end
860
- end
861
- end
862
- end
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe YARD::CLI::Yardoc do
4
+ before do
5
+ @yardoc = YARD::CLI::Yardoc.new
6
+ @yardoc.statistics = false
7
+ @yardoc.use_document_file = false
8
+ @yardoc.use_yardopts_file = false
9
+ @yardoc.generate = false
10
+ allow(Templates::Engine).to receive(:render)
11
+ allow(Templates::Engine).to receive(:generate)
12
+ allow(YARD).to receive(:parse)
13
+ allow(Registry).to receive(:load)
14
+ allow(Registry).to receive(:save)
15
+ allow(File).to receive(:open!)
16
+ end
17
+
18
+ describe "Defaults" do
19
+ before do
20
+ @yardoc = CLI::Yardoc.new
21
+ allow(@yardoc).to receive(:yardopts).and_return([])
22
+ allow(@yardoc).to receive(:support_rdoc_document_file!).and_return([])
23
+ @yardoc.parse_arguments
24
+ end
25
+
26
+ it "does not use cache by default" do
27
+ expect(@yardoc.use_cache).to be false
28
+ end
29
+
30
+ it "prints statistics by default" do
31
+ expect(@yardoc.statistics).to be true
32
+ end
33
+
34
+ it "generates output by default" do
35
+ expect(@yardoc.generate).to be true
36
+ end
37
+
38
+ it "reads .yardopts by default" do
39
+ expect(@yardoc.use_yardopts_file).to be true
40
+ end
41
+
42
+ it "reads .document by default" do
43
+ expect(@yardoc.use_document_file).to be true
44
+ end
45
+
46
+ it "uses lib, app, and ext as default file glob paths" do
47
+ expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
48
+ end
49
+
50
+ it "uses rdoc as default markup type (but falls back on none)" do
51
+ expect(@yardoc.options.markup).to eq :rdoc
52
+ end
53
+
54
+ it "uses default as default template" do
55
+ expect(@yardoc.options.template).to eq :default
56
+ end
57
+
58
+ it "uses HTML as default format" do
59
+ expect(@yardoc.options.format).to eq :html
60
+ end
61
+
62
+ it "uses 'Object' as default return type" do
63
+ expect(@yardoc.options.default_return).to eq 'Object'
64
+ end
65
+
66
+ it "does not hide void return types by default" do
67
+ expect(@yardoc.options.hide_void_return).to be false
68
+ end
69
+
70
+ it "only shows public visibility by default" do
71
+ expect(@yardoc.visibilities).to eq [:public]
72
+ end
73
+
74
+ it "does not list objects by default" do
75
+ expect(@yardoc.list).to be false
76
+ end
77
+
78
+ it "does not embed mixins by default" do
79
+ expect(@yardoc.options.embed_mixins).to be_empty
80
+ end
81
+
82
+ it "does not set any locale by default" do
83
+ expect(@yardoc.options.locale).to be nil
84
+ end
85
+ end
86
+
87
+ describe "General options" do
88
+ def self.should_accept(*args, &block)
89
+ @counter ||= 0
90
+ @counter += 1
91
+ counter = @counter
92
+ define_method("test_options_#{@counter}", &block)
93
+ args.each do |arg|
94
+ it("accepts #{arg}") { send("test_options_#{counter}", arg) }
95
+ end
96
+ end
97
+
98
+ should_accept('--single-db') do |arg|
99
+ @yardoc.parse_arguments(arg)
100
+ expect(Registry.single_object_db).to be true
101
+ Registry.single_object_db = nil
102
+ end
103
+
104
+ should_accept('--no-single-db') do |arg|
105
+ @yardoc.parse_arguments(arg)
106
+ expect(Registry.single_object_db).to be false
107
+ Registry.single_object_db = nil
108
+ end
109
+
110
+ should_accept('-c', '--use-cache') do |arg|
111
+ @yardoc.parse_arguments(arg)
112
+ expect(@yardoc.use_cache).to be true
113
+ end
114
+
115
+ should_accept('--no-cache') do |arg|
116
+ @yardoc.parse_arguments(arg)
117
+ expect(@yardoc.use_cache).to be false
118
+ end
119
+
120
+ should_accept('--yardopts') do |arg|
121
+ @yardoc = CLI::Yardoc.new
122
+ @yardoc.use_document_file = false
123
+ expect(@yardoc).to receive(:yardopts).at_least(1).times.and_return([])
124
+ @yardoc.parse_arguments(arg)
125
+ expect(@yardoc.use_yardopts_file).to be true
126
+ @yardoc.parse_arguments('--no-yardopts', arg)
127
+ expect(@yardoc.use_yardopts_file).to be true
128
+ end
129
+
130
+ should_accept('--yardopts with filename') do |_arg|
131
+ @yardoc = CLI::Yardoc.new
132
+ expect(File).to receive(:read_binary).with('.foobar').and_return('')
133
+ @yardoc.use_document_file = false
134
+ @yardoc.parse_arguments('--yardopts', '.foobar')
135
+ expect(@yardoc.use_yardopts_file).to be true
136
+ expect(@yardoc.options_file).to eq '.foobar'
137
+ end
138
+
139
+ should_accept('--no-yardopts') do |arg|
140
+ @yardoc = CLI::Yardoc.new
141
+ @yardoc.use_document_file = false
142
+ expect(@yardoc).not_to receive(:yardopts)
143
+ @yardoc.parse_arguments(arg)
144
+ expect(@yardoc.use_yardopts_file).to be false
145
+ @yardoc.parse_arguments('--yardopts', arg)
146
+ expect(@yardoc.use_yardopts_file).to be false
147
+ end
148
+
149
+ should_accept('--document') do |arg|
150
+ @yardoc = CLI::Yardoc.new
151
+ @yardoc.use_yardopts_file = false
152
+ expect(@yardoc).to receive(:support_rdoc_document_file!).and_return([])
153
+ @yardoc.parse_arguments('--no-document', arg)
154
+ expect(@yardoc.use_document_file).to be true
155
+ end
156
+
157
+ should_accept('--no-document') do |arg|
158
+ @yardoc = CLI::Yardoc.new
159
+ @yardoc.use_yardopts_file = false
160
+ expect(@yardoc).not_to receive(:support_rdoc_document_file!)
161
+ @yardoc.parse_arguments('--document', arg)
162
+ expect(@yardoc.use_document_file).to be false
163
+ end
164
+
165
+ should_accept('-b', '--db') do |arg|
166
+ @yardoc.parse_arguments(arg, 'test')
167
+ expect(Registry.yardoc_file).to eq 'test'
168
+ Registry.yardoc_file = '.yardoc'
169
+ end
170
+
171
+ should_accept('-n', '--no-output') do |arg|
172
+ expect(Templates::Engine).not_to receive(:generate)
173
+ @yardoc.run(arg)
174
+ end
175
+
176
+ should_accept('--exclude') do |arg|
177
+ expect(YARD).to receive(:parse).with(['a'], ['nota', 'b'])
178
+ @yardoc.run(arg, 'nota', arg, 'b', 'a')
179
+ end
180
+
181
+ should_accept('--no-save') do |arg|
182
+ expect(YARD).to receive(:parse)
183
+ expect(Registry).not_to receive(:save)
184
+ @yardoc.run(arg)
185
+ end
186
+
187
+ # This example relies on processing Yard's own documentation, and with
188
+ # --fail-on-warning option on, will raise a SystemExit error if building
189
+ # that documentation produces any one warning.
190
+ #
191
+ # Unless handled, it will cause immediate and abnormal process exit,
192
+ # without running remaining tests, and with non-successful exit status.
193
+ #
194
+ # While suppressing exceptions is generally a bad practice and against this
195
+ # project's style guide, here it is well advocated,
196
+ # hence Lint/HandleExceptions cop is disabled.
197
+ should_accept('--fail-on-warning') do |arg|
198
+ expect(YARD).to receive(:parse)
199
+ begin
200
+ @yardoc.run(arg)
201
+ rescue SystemExit # rubocop:disable Lint/HandleExceptions
202
+ end
203
+ end
204
+ end
205
+
206
+ describe "Output options" do
207
+ it "accepts --title" do
208
+ @yardoc.parse_arguments('--title', 'hello world')
209
+ expect(@yardoc.options.title).to eq 'hello world'
210
+ end
211
+
212
+ it "allows --title to have multiple spaces in .yardopts" do
213
+ expect(File).to receive(:read_binary).with("test").and_return("--title \"Foo Bar\"")
214
+ @yardoc.options_file = "test"
215
+ @yardoc.use_yardopts_file = true
216
+ @yardoc.run
217
+ expect(@yardoc.options.title).to eq "Foo Bar"
218
+ end
219
+
220
+ it "aliases --main to the --readme flag" do
221
+ Dir.chdir(File.join(File.dirname(__FILE__), '..', '..')) do
222
+ @yardoc.parse_arguments('--main', 'README.md')
223
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.md', '')
224
+ end
225
+ end
226
+
227
+ it "selects a markup provider when --markup-provider or -mp is set" do
228
+ @yardoc.parse_arguments("-M", "test")
229
+ expect(@yardoc.options.markup_provider).to eq :test
230
+ @yardoc.parse_arguments("--markup-provider", "test2")
231
+ expect(@yardoc.options.markup_provider).to eq :test2
232
+ end
233
+
234
+ it "selects a markup format when -m is set" do
235
+ expect(@yardoc).to receive(:verify_markup_options).and_return(true)
236
+ @yardoc.generate = true
237
+ @yardoc.parse_arguments('-m', 'markdown')
238
+ expect(@yardoc.options.markup).to eq :markdown
239
+ end
240
+
241
+ it "accepts --default-return" do
242
+ @yardoc.parse_arguments(*%w(--default-return XYZ))
243
+ expect(@yardoc.options.default_return).to eq "XYZ"
244
+ end
245
+
246
+ it "allows --hide-void-return to be set" do
247
+ @yardoc.parse_arguments(*%w(--hide-void-return))
248
+ expect(@yardoc.options.hide_void_return).to be true
249
+ end
250
+
251
+ it "accepts --embed-mixins" do
252
+ @yardoc.parse_arguments(*%w(--embed-mixins))
253
+ expect(@yardoc.options.embed_mixins).to eq ['*']
254
+ end
255
+
256
+ it "accepts --embed-mixin MODULE" do
257
+ @yardoc.parse_arguments(*%w(--embed-mixin MyModule))
258
+ expect(@yardoc.options.embed_mixins).to eq ['MyModule']
259
+ end
260
+
261
+ it "generates all objects with --use-cache" do
262
+ expect(YARD).to receive(:parse)
263
+ expect(Registry).to receive(:load)
264
+ expect(Registry).to receive(:load_all)
265
+ allow(@yardoc).to receive(:generate).and_return(true)
266
+ @yardoc.run(*%w(--use-cache))
267
+ end
268
+
269
+ it "does not print statistics with --no-stats" do
270
+ allow(@yardoc).to receive(:statistics).and_return(false)
271
+ expect(CLI::Stats).not_to receive(:new)
272
+ @yardoc.run(*%w(--no-stats))
273
+ end
274
+
275
+ it "disables progress bar with --no-progress" do
276
+ old = log.show_progress
277
+ log.show_progress = true
278
+ @yardoc.run(*%w(--no-progress))
279
+ expect(log.show_progress).to eq false
280
+ log.show_progress = old
281
+ end
282
+
283
+ describe "--asset" do
284
+ before do
285
+ @yardoc.generate = true
286
+ allow(@yardoc).to receive(:run_generate)
287
+ end
288
+
289
+ it "copies assets to output directory" do
290
+ expect(FileUtils).to receive(:cp_r).with('a', 'doc/a')
291
+ @yardoc.run(*%w(--asset a))
292
+ expect(@yardoc.assets).to eq('a' => 'a')
293
+ end
294
+
295
+ it "allows multiple --asset options" do
296
+ expect(FileUtils).to receive(:cp_r).with('a', 'doc/a')
297
+ expect(FileUtils).to receive(:cp_r).with('b', 'doc/b')
298
+ @yardoc.run(*%w(--asset a --asset b))
299
+ expect(@yardoc.assets).to eq('a' => 'a', 'b' => 'b')
300
+ end
301
+
302
+ it "does not allow from or to to refer to a path above current path" do
303
+ expect(log).to receive(:warn).exactly(4).times.with(/invalid/i)
304
+ @yardoc.run(*%w(--asset ../../../etc/passwd))
305
+ expect(@yardoc.assets).to be_empty
306
+ @yardoc.run(*%w(--asset a/b/c/d/../../../../../../etc/passwd))
307
+ expect(@yardoc.assets).to be_empty
308
+ @yardoc.run(*%w(--asset /etc/passwd))
309
+ expect(@yardoc.assets).to be_empty
310
+ @yardoc.run(*%w(--asset normal:/etc/passwd))
311
+ expect(@yardoc.assets).to be_empty
312
+ end
313
+
314
+ it "allows from:to syntax" do
315
+ expect(FileUtils).to receive(:cp_r).with(%r{foo(\/\.)?}, 'doc/bar')
316
+ @yardoc.run(*%w(--asset foo:bar))
317
+ expect(@yardoc.assets).to eq('foo' => 'bar')
318
+ end
319
+
320
+ it "does not put from inside of to/ if from is a directory" do
321
+ begin
322
+ from = 'tmp_foo'
323
+ to = 'tmp_bar'
324
+ full_to = File.join(File.dirname(__FILE__), to)
325
+ FileUtils.mkdir_p(from)
326
+ @yardoc.options.serializer.basepath = File.dirname(__FILE__)
327
+ @yardoc.run("--asset", "#{from}:#{to}")
328
+ @yardoc.run("--asset", "#{from}:#{to}")
329
+ expect(File.directory?(full_to)).to be true
330
+ expect(File.directory?(File.join(full_to, 'tmp_foo'))).to be false
331
+ ensure
332
+ FileUtils.rm_rf(from)
333
+ FileUtils.rm_rf(full_to)
334
+ end
335
+ end
336
+ end
337
+
338
+ describe "--locale" do
339
+ it "applies specified locale to all extra file objects" do
340
+ allow(File).to receive(:read).with('extra_file1').and_return('')
341
+ allow(File).to receive(:read).with('extra_file2').and_return('')
342
+
343
+ extra_file_object1 = CodeObjects::ExtraFileObject.new('extra_file1')
344
+ extra_file_object2 = CodeObjects::ExtraFileObject.new('extra_file2')
345
+ expect(extra_file_object1).to receive(:locale=).with('fr')
346
+ expect(extra_file_object2).to receive(:locale=).with('fr')
347
+
348
+ allow(CodeObjects::ExtraFileObject).to receive(:new).with('extra_file1').and_return(extra_file_object1)
349
+ allow(CodeObjects::ExtraFileObject).to receive(:new).with('extra_file2').and_return(extra_file_object2)
350
+ allow(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
351
+ allow(File).to receive(:file?).with('extra_file1').and_return(true)
352
+ allow(File).to receive(:file?).with('extra_file2').and_return(true)
353
+ @yardoc.run('--locale=fr', '-', 'extra_file1', 'extra_file2')
354
+ end
355
+ end
356
+
357
+ describe "--po-dir" do
358
+ it "sets Registry.po_dir" do
359
+ expect(Registry).to receive(:po_dir=).with("locale")
360
+ @yardoc.run('--po-dir=locale')
361
+ end
362
+ end
363
+ end
364
+
365
+ describe "--[no-]api" do
366
+ before { Registry.clear }
367
+
368
+ it "allows --api name" do
369
+ YARD.parse_string <<-eof
370
+ # @api private
371
+ class Foo; end
372
+ # @api public
373
+ class Bar; end
374
+ class Baz; end
375
+ eof
376
+ @yardoc.run('--api', 'private')
377
+ expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Foo')]
378
+ end
379
+
380
+ it "allows multiple --api's to all be shown" do
381
+ YARD.parse_string <<-eof
382
+ # @api private
383
+ class Foo; end
384
+ # @api public
385
+ class Bar; end
386
+ class Baz; end
387
+ eof
388
+ @yardoc.run('--api', 'private', '--api', 'public')
389
+ expect(@yardoc.options.verifier.run(Registry.all).
390
+ sort_by(&:path)).to eq [P('Bar'), P('Foo')]
391
+ end
392
+
393
+ it "allows --no-api to specify objects with no @api tag" do
394
+ YARD.parse_string <<-eof
395
+ # @api private
396
+ class Foo; end
397
+ # @api public
398
+ class Bar; end
399
+ class Baz; end
400
+ eof
401
+ @yardoc.run('--api', '')
402
+ expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Baz')]
403
+ @yardoc.options.verifier = Verifier.new
404
+ @yardoc.run('--no-api')
405
+ expect(@yardoc.options.verifier.run(Registry.all)).to eq [P('Baz')]
406
+ end
407
+
408
+ it "allows --no-api to work with other --api switches" do
409
+ YARD.parse_string <<-eof
410
+ # @api private
411
+ class Foo; end
412
+ # @api public
413
+ class Bar; end
414
+ class Baz; end
415
+ eof
416
+ @yardoc.run('--no-api', '--api', 'public')
417
+ expect(@yardoc.options.verifier.run(Registry.all).
418
+ sort_by(&:path)).to eq [P('Bar'), P('Baz')]
419
+ end
420
+
421
+ it "ensures Ruby code cannot be used" do
422
+ [':symbol', '42', '"; exit'].each do |ruby|
423
+ @yardoc.options.verifier.expressions = []
424
+ @yardoc.run('--api', ruby)
425
+ expect(@yardoc.options.verifier.expressions[1]).to include(ruby.inspect)
426
+ end
427
+ end
428
+ end
429
+
430
+ describe "--hide-api option" do
431
+ it "allows --hide-api to hide objects with api tags" do
432
+ YARD.parse_string <<-eof
433
+ # @api private
434
+ class Foo; end
435
+ class Bar; end
436
+ class Baz; end
437
+ eof
438
+ @yardoc.run('--hide-api', 'private')
439
+ expect(@yardoc.options.verifier.run(Registry.all).
440
+ sort_by(&:path)).to eq [P('Bar'), P('Baz')]
441
+ end
442
+
443
+ it "allows --hide-api to work with --api" do
444
+ YARD.parse_string <<-eof
445
+ # @api private
446
+ class Foo; end
447
+ # @api public
448
+ class Bar; end
449
+ class Baz; end
450
+ eof
451
+ @yardoc.run('--api', 'public', '--hide-api', 'private')
452
+ expect(@yardoc.options.verifier.run(Registry.all).
453
+ sort_by(&:path)).to eq [P('Bar')]
454
+ end
455
+ end
456
+
457
+ describe "--no-private option" do
458
+ it "accepts --no-private" do
459
+ obj = double(:object)
460
+ expect(obj).to receive(:tag).ordered.with(:private).and_return(true)
461
+ @yardoc.parse_arguments(*%w(--no-private))
462
+ expect(@yardoc.options.verifier.call(obj)).to be false
463
+ end
464
+
465
+ it "hides object if namespace is @private with --no-private" do
466
+ ns = double(:namespace, :type => :module)
467
+ expect(ns).to receive(:tag).with(:private).and_return(true)
468
+ obj = double(:object, :namespace => ns)
469
+ expect(obj).to receive(:tag).with(:private).and_return(false)
470
+ @yardoc.parse_arguments(*%w(--no-private))
471
+ expect(@yardoc.options.verifier.call(obj)).to be false
472
+ end
473
+
474
+ it "does not call #tag on namespace if namespace is proxy with --no-private" do
475
+ ns = double(:namespace)
476
+ expect(ns).to receive(:is_a?).with(CodeObjects::Proxy).and_return(true)
477
+ expect(ns).not_to receive(:tag)
478
+ obj = double(:object, :type => :class, :namespace => ns, :visibility => :public)
479
+ expect(obj).to receive(:tag).ordered.with(:private).and_return(false)
480
+ @yardoc.parse_arguments(*%w(--no-private))
481
+ expect(@yardoc.options.verifier.call(obj)).to be true
482
+ end
483
+
484
+ # @bug gh-197
485
+ it "does not call #tag on namespace if namespace is proxy with --no-private" do
486
+ Registry.clear
487
+ YARD.parse_string "module Qux; class Foo::Bar; end; end"
488
+ foobar = Registry.at('Foo::Bar')
489
+ foobar.namespace.type = :module
490
+ @yardoc.parse_arguments(*%w(--no-private))
491
+ expect(@yardoc.options.verifier.call(foobar)).to be true
492
+ end
493
+
494
+ it "does not call #tag on proxy object" do # @bug gh-197
495
+ @yardoc.parse_arguments(*%w(--no-private))
496
+ expect(@yardoc.options.verifier.call(P('ProxyClass'))).to be true
497
+ end
498
+
499
+ it "hides methods inside a 'private' class/module with --no-private" do
500
+ Registry.clear
501
+ YARD.parse_string <<-eof
502
+ # @private
503
+ class ABC
504
+ def foo; end
505
+ end
506
+ eof
507
+ @yardoc.parse_arguments(*%w(--no-private))
508
+ expect(@yardoc.options.verifier.call(Registry.at('ABC'))).to be false
509
+ expect(@yardoc.options.verifier.call(Registry.at('ABC#foo'))).to be false
510
+ end
511
+ end
512
+
513
+ describe ".yardopts and .document handling" do
514
+ before do
515
+ @yardoc.use_yardopts_file = true
516
+ end
517
+
518
+ it "searches for and uses yardopts file specified by #options_file" do
519
+ expect(File).to receive(:read_binary).with("test").and_return("-o \n\nMYPATH\nFILE1 FILE2")
520
+ @yardoc.use_document_file = false
521
+ @yardoc.options_file = "test"
522
+ @yardoc.run
523
+ expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
524
+ expect(@yardoc.files).to eq ["FILE1", "FILE2"]
525
+ end
526
+
527
+ it "uses String#shell_split to split .yardopts tokens" do
528
+ optsdata = String.new("foo bar")
529
+ expect(optsdata).to receive(:shell_split)
530
+ expect(File).to receive(:read_binary).with("test").and_return(optsdata)
531
+ @yardoc.options_file = "test"
532
+ @yardoc.run
533
+ end
534
+
535
+ it "allows opts specified in command line to override yardopts file" do
536
+ expect(File).to receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
537
+ @yardoc.run("-o", "MYPATH", "FILE")
538
+ expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
539
+ expect(@yardoc.files).to eq ["FILE"]
540
+ end
541
+
542
+ it "loads the RDoc .document file if found" do
543
+ expect(File).to receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
544
+ @yardoc.use_document_file = true
545
+ allow(@yardoc).to receive(:support_rdoc_document_file!).and_return(["FILE2", "FILE3"])
546
+ @yardoc.run("-o", "MYPATH", "FILE1")
547
+ expect(@yardoc.options.serializer.options[:basepath]).to eq "MYPATH"
548
+ expect(@yardoc.files).to eq ["FILE2", "FILE3", "FILE1"]
549
+ end
550
+ end
551
+
552
+ describe "Query options" do
553
+ after { Registry.clear }
554
+
555
+ it "hides private constants in with default visibilities" do
556
+ classobj = CodeObjects::ClassObject.new(:root, :Foo) {|o| o.visibility = :private }
557
+ @yardoc.run
558
+ expect(@yardoc.options.verifier.run([classobj])).to eq []
559
+ end
560
+
561
+ it "sets up visibility rules as verifier" do
562
+ methobj = CodeObjects::MethodObject.new(:root, :test) {|o| o.visibility = :private }
563
+ expect(File).to receive(:read_binary).with("test").and_return("--private")
564
+ @yardoc.use_yardopts_file = true
565
+ @yardoc.options_file = "test"
566
+ @yardoc.run
567
+ expect(@yardoc.options.verifier.call(methobj)).to be true
568
+ end
569
+
570
+ it "accepts a --query" do
571
+ @yardoc.parse_arguments(*%w(--query @return))
572
+ expect(@yardoc.options.verifier).to be_a(Verifier)
573
+ end
574
+
575
+ it "accepts multiple --query arguments" do
576
+ obj = double(:object)
577
+ expect(obj).to receive(:tag).ordered.with('return').and_return(true)
578
+ expect(obj).to receive(:tag).ordered.with('tag').and_return(false)
579
+ @yardoc.parse_arguments(*%w(--query @return --query @tag))
580
+ expect(@yardoc.options.verifier).to be_a(Verifier)
581
+ expect(@yardoc.options.verifier.call(obj)).to be false
582
+ end
583
+ end
584
+
585
+ describe "Extra file arguments" do
586
+ it "accepts extra files if specified after '-' with source files" do
587
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
588
+ expect(File).to receive(:file?).with('extra_file1').and_return(true)
589
+ expect(File).to receive(:file?).with('extra_file2').and_return(true)
590
+ expect(File).to receive(:read).with('extra_file1').and_return('')
591
+ expect(File).to receive(:read).with('extra_file2').and_return('')
592
+ @yardoc.parse_arguments(*%w(file1 file2 - extra_file1 extra_file2))
593
+ expect(@yardoc.files).to eq %w(file1 file2)
594
+ expect(@yardoc.options.files).to eq(
595
+ [CodeObjects::ExtraFileObject.new('extra_file1', ''),
596
+ CodeObjects::ExtraFileObject.new('extra_file2', '')]
597
+ )
598
+ end
599
+
600
+ it "accepts files section only containing extra files" do
601
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return([])
602
+ @yardoc.parse_arguments(*%w(- LICENSE))
603
+ expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
604
+ expect(@yardoc.options.files).to eq [CodeObjects::ExtraFileObject.new('LICENSE', '')]
605
+ end
606
+
607
+ it "accepts globs as extra files" do
608
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return []
609
+ expect(Dir).to receive(:glob).with('*.txt').and_return ['a.txt', 'b.txt']
610
+ expect(File).to receive(:read).with('a.txt').and_return('')
611
+ expect(File).to receive(:read).with('b.txt').and_return('')
612
+ expect(File).to receive(:file?).with('a.txt').and_return(true)
613
+ expect(File).to receive(:file?).with('b.txt').and_return(true)
614
+ @yardoc.parse_arguments(*%w(file1 file2 - *.txt))
615
+ expect(@yardoc.files).to eq %w(file1 file2)
616
+ expect(@yardoc.options.files).to eq(
617
+ [CodeObjects::ExtraFileObject.new('a.txt', ''),
618
+ CodeObjects::ExtraFileObject.new('b.txt', '')]
619
+ )
620
+ end
621
+
622
+ it "warns if extra file is not found" do
623
+ expect(log).to receive(:warn).with(/Could not find file: UNKNOWN/)
624
+ @yardoc.parse_arguments(*%w(- UNKNOWN))
625
+ end
626
+
627
+ it "warns if readme file is not found" do
628
+ expect(log).to receive(:warn).with(/Could not find file: UNKNOWN/)
629
+ @yardoc.parse_arguments(*%w(-r UNKNOWN))
630
+ end
631
+
632
+ it "warns on absolute paths in extra files" do
633
+ expect(log).to receive(:warn).with(%r{Invalid file: /path/to/file})
634
+ @yardoc.parse_arguments(*%w(- /path/to/file))
635
+ end
636
+
637
+ it "warns on absolute paths in readme" do
638
+ expect(log).to receive(:warn).with(%r{Invalid file: /path/to/file})
639
+ @yardoc.parse_arguments(*%w(-r /path/to/file))
640
+ end
641
+
642
+ it "uses first file as readme if no readme is specified when using --one-file" do
643
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return []
644
+ expect(Dir).to receive(:glob).with('lib/*.rb').and_return(['lib/foo.rb'])
645
+ expect(File).to receive(:read).with('lib/foo.rb').and_return('')
646
+ @yardoc.parse_arguments(*%w(--one-file lib/*.rb))
647
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('lib/foo.rb', '')
648
+ end
649
+
650
+ it "uses no readme if files is empty and no readme is specified when using --one-file" do
651
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return []
652
+ @yardoc.parse_arguments '--one-file', ''
653
+ expect(@yardoc.options.readme).to be_nil
654
+ end
655
+
656
+ it "uses readme it exists when using --one-file" do
657
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README']
658
+ expect(File).to receive(:read).with('README').and_return('')
659
+ @yardoc.parse_arguments(*%w(--one-file lib/*.rb))
660
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README', '')
661
+ end
662
+
663
+ it "selects readme with no file extension over readme with file extension" do
664
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README.md', 'README-DEV', 'README']
665
+ expect(File).to receive(:read).with('README').and_return('')
666
+ @yardoc.parse_arguments
667
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README', '')
668
+ end
669
+
670
+ it "selects readme with no suffix over readme with hyphenated suffix" do
671
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README-fr.md', 'README.long-extension', 'README-de.md']
672
+ expect(File).to receive(:read).with('README.long-extension').and_return('')
673
+ @yardoc.parse_arguments
674
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.long-extension', '')
675
+ end
676
+
677
+ it "selects readme with no suffix over readme with dotted suffix" do
678
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README.fr.md', 'README.md', 'README.de.md']
679
+ expect(File).to receive(:read).with('README.md').and_return('')
680
+ @yardoc.parse_arguments
681
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README.md', '')
682
+ end
683
+
684
+ it "selects first readme from lexically sorted list" do
685
+ expect(Dir).to receive(:glob).with('README{,*[^~]}').and_return ['README-fr.md', 'README-de.md']
686
+ expect(File).to receive(:read).with('README-de.md').and_return('')
687
+ @yardoc.parse_arguments
688
+ expect(@yardoc.options.readme).to eq CodeObjects::ExtraFileObject.new('README-de.md', '')
689
+ end
690
+
691
+ it "does not allow US-ASCII charset when using --one-file" do
692
+ ienc = Encoding.default_internal
693
+ eenc = Encoding.default_external
694
+ expect(log).to receive(:warn).with(/not compatible with US-ASCII.*using ASCII-8BIT/)
695
+ @yardoc.parse_arguments(*%w(--one-file --charset us-ascii))
696
+ expect(Encoding.default_internal.name).to eq 'ASCII-8BIT'
697
+ expect(Encoding.default_external.name).to eq 'ASCII-8BIT'
698
+ Encoding.default_internal = ienc
699
+ Encoding.default_external = eenc
700
+ end if defined?(::Encoding)
701
+ end
702
+
703
+ describe "Source file arguments" do
704
+ it "accepts no params and parse {lib,app}/**/*.rb ext/**/*.c" do
705
+ @yardoc.parse_arguments
706
+ expect(@yardoc.files).to eq Parser::SourceParser::DEFAULT_PATH_GLOB
707
+ end
708
+ end
709
+
710
+ describe "Tags options" do
711
+ def tag_created(switch, factory_method)
712
+ visible_tags = double(:visible_tags)
713
+ expect(visible_tags).to receive(:|).ordered.with([:foo])
714
+ expect(visible_tags).to receive(:-).ordered.with([]).and_return(visible_tags)
715
+ expect(Tags::Library).to receive(:define_tag).with('Foo', :foo, factory_method)
716
+ allow(Tags::Library).to receive(:visible_tags=)
717
+ expect(Tags::Library).to receive(:visible_tags).at_least(1).times.and_return(visible_tags)
718
+ @yardoc.parse_arguments("--#{switch}-tag", 'foo')
719
+ end
720
+
721
+ def tag_hidden(tag)
722
+ visible_tags = double(:visible_tags)
723
+ expect(visible_tags).to receive(:|).ordered.with([tag])
724
+ expect(visible_tags).to receive(:-).ordered.with([tag]).and_return([])
725
+ expect(Tags::Library).to receive(:define_tag).with(tag.to_s.capitalize, tag, nil)
726
+ allow(Tags::Library).to receive(:visible_tags=)
727
+ expect(Tags::Library).to receive(:visible_tags).at_least(1).times.and_return(visible_tags)
728
+ end
729
+
730
+ it "accepts --tag" do
731
+ expect(Tags::Library).to receive(:define_tag).with('Title of Foo', :foo, nil)
732
+ @yardoc.parse_arguments('--tag', 'foo:Title of Foo')
733
+ end
734
+
735
+ it "accepts --tag without title (and default to capitalized tag name)" do
736
+ expect(Tags::Library).to receive(:define_tag).with('Foo', :foo, nil)
737
+ @yardoc.parse_arguments('--tag', 'foo')
738
+ end
739
+
740
+ it "only lists tag once if declared twice" do
741
+ visible_tags = []
742
+ allow(Tags::Library).to receive(:define_tag)
743
+ allow(Tags::Library).to receive(:visible_tags).and_return([:foo])
744
+ allow(Tags::Library).to receive(:visible_tags=) {|value| visible_tags = value }
745
+ @yardoc.parse_arguments('--tag', 'foo', '--tag', 'foo')
746
+ expect(visible_tags).to eq [:foo]
747
+ end
748
+
749
+ it "accepts --type-tag" do
750
+ tag_created 'type', :with_types
751
+ end
752
+
753
+ it "accepts --type-name-tag" do
754
+ tag_created 'type-name', :with_types_and_name
755
+ end
756
+
757
+ it "accepts --name-tag" do
758
+ tag_created 'name', :with_name
759
+ end
760
+
761
+ it "accepts --title-tag" do
762
+ tag_created 'title', :with_title_and_text
763
+ end
764
+
765
+ it "accepts --hide-tag before tag is listed" do
766
+ tag_hidden(:anewfoo)
767
+ @yardoc.parse_arguments('--hide-tag', 'anewfoo', '--tag', 'anewfoo')
768
+ end
769
+
770
+ it "accepts --hide-tag after tag is listed" do
771
+ tag_hidden(:anewfoo2)
772
+ @yardoc.parse_arguments('--tag', 'anewfoo2', '--hide-tag', 'anewfoo2')
773
+ end
774
+
775
+ it "accepts --transitive-tag" do
776
+ @yardoc.parse_arguments('--transitive-tag', 'foo')
777
+ expect(Tags::Library.transitive_tags).to include(:foo)
778
+ end
779
+
780
+ it "accepts --non-transitive-tag" do
781
+ Tags::Library.transitive_tags |= [:foo]
782
+ @yardoc.parse_arguments('--non-transitive-tag', 'foo')
783
+ expect(Tags::Library.transitive_tags).not_to include(:foo)
784
+ end
785
+ end
786
+
787
+ describe "Safe mode" do
788
+ before do
789
+ allow(YARD::Config).to receive(:options).and_return(:safe_mode => true)
790
+ end
791
+
792
+ it "does not allow --load or -e in safe mode" do
793
+ expect(@yardoc).not_to receive(:require)
794
+ @yardoc.run('--load', 'foo')
795
+ @yardoc.run('-e', 'foo')
796
+ end
797
+
798
+ it "does not allow --query in safe mode" do
799
+ @yardoc.run('--query', 'foo')
800
+ expect(@yardoc.options.verifier.expressions).not_to include("foo")
801
+ end
802
+
803
+ it "does not allow modifying the template paths" do
804
+ expect(YARD::Templates::Engine).not_to receive(:register_template_path)
805
+ @yardoc.run('-p', 'foo')
806
+ @yardoc.run('--template-path', 'foo')
807
+ end
808
+ end
809
+
810
+ describe "Markup Loading" do
811
+ it "loads rdoc markup if no markup is provided" do
812
+ @yardoc.generate = true
813
+ @yardoc.run
814
+ expect(@yardoc.options.markup).to eq :rdoc
815
+ end
816
+
817
+ it "loads rdoc markup even when no output is specified" do
818
+ @yardoc.parse_arguments('--no-output')
819
+ expect(@yardoc.options.markup).to eq :rdoc
820
+ end
821
+
822
+ it "warns if rdoc cannot be loaded and fallback to :none" do
823
+ mod = YARD::Templates::Helpers::MarkupHelper
824
+ mod.clear_markup_cache
825
+ expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:rdoc).and_return([{:lib => 'INVALID'}])
826
+ expect(log).to receive(:warn).with(/Could not load default RDoc formatter/)
827
+ allow(@yardoc).to receive(:generate) { @yardoc.options.files = []; true }
828
+ @yardoc.run
829
+ expect(@yardoc.options.markup).to eq :none
830
+ mod.clear_markup_cache
831
+ end
832
+
833
+ it "returns an error immediately if markup for any files are missing" do
834
+ mod = YARD::Templates::Helpers::MarkupHelper
835
+ mod.clear_markup_cache
836
+ expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
837
+ expect(log).to receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
838
+ files = [CodeObjects::ExtraFileObject.new('test.md', '')]
839
+ allow(@yardoc).to receive(:generate) { @yardoc.options.files = files; true }
840
+ @yardoc.run
841
+ mod.clear_markup_cache
842
+ end
843
+
844
+ it "returns an error immediately if markup for any files are missing (file markup specified in attributes)" do
845
+ mod = YARD::Templates::Helpers::MarkupHelper
846
+ mod.clear_markup_cache
847
+ expect(mod.const_get(:MARKUP_PROVIDERS)).to receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
848
+ expect(log).to receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
849
+ files = [CodeObjects::ExtraFileObject.new('test', '# @markup markdown')]
850
+ allow(@yardoc).to receive(:generate) { @yardoc.options.files = files; true }
851
+ @yardoc.run
852
+ mod.clear_markup_cache
853
+ end
854
+ end
855
+
856
+ describe "#run" do
857
+ it "parses arguments if run() is called" do
858
+ expect(@yardoc).to receive(:parse_arguments)
859
+ @yardoc.run
860
+ end
861
+
862
+ it "parses arguments if run(arg1, arg2, ...) is called" do
863
+ expect(@yardoc).to receive(:parse_arguments)
864
+ @yardoc.run('--private', '-p', 'foo')
865
+ end
866
+
867
+ it "does not parse arguments if run(nil) is called" do
868
+ expect(@yardoc).not_to receive(:parse_arguments)
869
+ @yardoc.run(nil)
870
+ end
871
+
872
+ it "creates processing lock if saving" do
873
+ expect(Registry).to receive(:lock_for_writing).and_yield
874
+ @yardoc.run
875
+ end
876
+
877
+ it "does not create processing lock if not saving" do
878
+ expect(Registry).not_to receive(:lock_for_writing)
879
+ @yardoc.run('--no-save')
880
+ end
881
+
882
+ context "with --fail-on-warning" do
883
+ it "exits with error status code if a warning occurs" do
884
+ allow(log).to receive(:warned).and_return(true)
885
+ expect { @yardoc.run("--fail-on-warning") }.to raise_error(SystemExit) do |error|
886
+ expect(error).not_to be_success
887
+ end
888
+ end
889
+
890
+ it "does not exit if a warning does not occur" do
891
+ allow(log).to receive(:warned).and_return(false)
892
+ expect { @yardoc.run("--fail-on-warning") }.not_to raise_error
893
+ end
894
+ end
895
+ end
896
+ end