yard 0.9.24 → 0.9.25

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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -24
  3. data/CHANGELOG.md +18 -3
  4. data/README.md +96 -101
  5. data/Rakefile +2 -0
  6. data/lib/yard/cli/diff.rb +4 -1
  7. data/lib/yard/cli/server.rb +22 -13
  8. data/lib/yard/code_objects/proxy.rb +2 -1
  9. data/lib/yard/globals.rb +1 -1
  10. data/lib/yard/handlers/c/base.rb +164 -129
  11. data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
  12. data/lib/yard/registry_store.rb +1 -1
  13. data/lib/yard/templates/helpers/html_helper.rb +10 -3
  14. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  15. data/lib/yard/version.rb +1 -1
  16. data/tasks/update_error_map.rake +53 -0
  17. data/yard.gemspec +1 -1
  18. metadata +3 -207
  19. data/spec/cli/command_parser_spec.rb +0 -43
  20. data/spec/cli/command_spec.rb +0 -36
  21. data/spec/cli/config_spec.rb +0 -148
  22. data/spec/cli/diff_spec.rb +0 -254
  23. data/spec/cli/display_spec.rb +0 -30
  24. data/spec/cli/gems_spec.rb +0 -81
  25. data/spec/cli/graph_spec.rb +0 -18
  26. data/spec/cli/help_spec.rb +0 -22
  27. data/spec/cli/i18n_spec.rb +0 -107
  28. data/spec/cli/list_spec.rb +0 -8
  29. data/spec/cli/markup_types_spec.rb +0 -22
  30. data/spec/cli/server_spec.rb +0 -324
  31. data/spec/cli/stats_spec.rb +0 -96
  32. data/spec/cli/yard_on_yard_spec.rb +0 -38
  33. data/spec/cli/yardoc_spec.rb +0 -896
  34. data/spec/cli/yri_spec.rb +0 -101
  35. data/spec/code_objects/base_spec.rb +0 -485
  36. data/spec/code_objects/class_object_spec.rb +0 -226
  37. data/spec/code_objects/code_object_list_spec.rb +0 -36
  38. data/spec/code_objects/constants_spec.rb +0 -116
  39. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  40. data/spec/code_objects/macro_object_spec.rb +0 -150
  41. data/spec/code_objects/method_object_spec.rb +0 -184
  42. data/spec/code_objects/module_object_spec.rb +0 -142
  43. data/spec/code_objects/namespace_mapper_spec.rb +0 -32
  44. data/spec/code_objects/namespace_object_spec.rb +0 -171
  45. data/spec/code_objects/proxy_spec.rb +0 -147
  46. data/spec/code_objects/spec_helper.rb +0 -3
  47. data/spec/config_spec.rb +0 -171
  48. data/spec/core_ext/array_spec.rb +0 -13
  49. data/spec/core_ext/file_spec.rb +0 -72
  50. data/spec/core_ext/hash_spec.rb +0 -14
  51. data/spec/core_ext/insertion_spec.rb +0 -37
  52. data/spec/core_ext/module_spec.rb +0 -9
  53. data/spec/core_ext/string_spec.rb +0 -42
  54. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  55. data/spec/docstring_parser_spec.rb +0 -280
  56. data/spec/docstring_spec.rb +0 -373
  57. data/spec/handlers/alias_handler_spec.rb +0 -82
  58. data/spec/handlers/attribute_handler_spec.rb +0 -96
  59. data/spec/handlers/base_spec.rb +0 -216
  60. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  61. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  62. data/spec/handlers/c/class_handler_spec.rb +0 -78
  63. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  64. data/spec/handlers/c/init_handler_spec.rb +0 -48
  65. data/spec/handlers/c/method_handler_spec.rb +0 -327
  66. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  67. data/spec/handlers/c/module_handler_spec.rb +0 -71
  68. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  69. data/spec/handlers/c/path_handler_spec.rb +0 -36
  70. data/spec/handlers/c/spec_helper.rb +0 -23
  71. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  72. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  73. data/spec/handlers/class_handler_spec.rb +0 -247
  74. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  75. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  76. data/spec/handlers/constant_handler_spec.rb +0 -112
  77. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  78. data/spec/handlers/dsl_handler_spec.rb +0 -226
  79. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  80. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  81. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  82. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  83. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  84. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  85. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  86. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  87. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  88. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  89. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  90. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  91. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  92. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  93. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  94. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  95. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  96. data/spec/handlers/exception_handler_spec.rb +0 -49
  97. data/spec/handlers/extend_handler_spec.rb +0 -28
  98. data/spec/handlers/legacy_base_spec.rb +0 -128
  99. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  100. data/spec/handlers/method_handler_spec.rb +0 -214
  101. data/spec/handlers/mixin_handler_spec.rb +0 -60
  102. data/spec/handlers/module_function_handler_spec.rb +0 -106
  103. data/spec/handlers/module_handler_spec.rb +0 -35
  104. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  105. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  106. data/spec/handlers/processor_spec.rb +0 -35
  107. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  108. data/spec/handlers/ruby/base_spec.rb +0 -95
  109. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  110. data/spec/handlers/spec_helper.rb +0 -33
  111. data/spec/handlers/visibility_handler_spec.rb +0 -44
  112. data/spec/handlers/yield_handler_spec.rb +0 -52
  113. data/spec/i18n/locale_spec.rb +0 -81
  114. data/spec/i18n/message_spec.rb +0 -52
  115. data/spec/i18n/messages_spec.rb +0 -67
  116. data/spec/i18n/pot_generator_spec.rb +0 -295
  117. data/spec/i18n/text_spec.rb +0 -184
  118. data/spec/logging_spec.rb +0 -44
  119. data/spec/options_spec.rb +0 -171
  120. data/spec/parser/base_spec.rb +0 -24
  121. data/spec/parser/c_parser_spec.rb +0 -236
  122. data/spec/parser/examples/array.c.txt +0 -6267
  123. data/spec/parser/examples/example1.rb.txt +0 -8
  124. data/spec/parser/examples/extrafile.c.txt +0 -8
  125. data/spec/parser/examples/file.c.txt +0 -28
  126. data/spec/parser/examples/multifile.c.txt +0 -22
  127. data/spec/parser/examples/namespace.cpp.txt +0 -68
  128. data/spec/parser/examples/override.c.txt +0 -424
  129. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  130. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  131. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  132. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  133. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  134. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  135. data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
  136. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  137. data/spec/parser/source_parser_spec.rb +0 -727
  138. data/spec/parser/tag_parsing_spec.rb +0 -17
  139. data/spec/rake/yardoc_task_spec.rb +0 -118
  140. data/spec/registry_resolver_spec.rb +0 -15
  141. data/spec/registry_spec.rb +0 -463
  142. data/spec/registry_store_spec.rb +0 -327
  143. data/spec/rubygems/doc_manager_spec.rb +0 -112
  144. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  145. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  146. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  147. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  148. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  149. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  150. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  151. data/spec/serializers/spec_helper.rb +0 -2
  152. data/spec/serializers/yardoc_serializer_spec.rb +0 -90
  153. data/spec/server/adapter_spec.rb +0 -39
  154. data/spec/server/commands/base_spec.rb +0 -91
  155. data/spec/server/commands/library_command_spec.rb +0 -39
  156. data/spec/server/doc_server_helper_spec.rb +0 -72
  157. data/spec/server/doc_server_serializer_spec.rb +0 -60
  158. data/spec/server/rack_adapter_spec.rb +0 -21
  159. data/spec/server/router_spec.rb +0 -123
  160. data/spec/server/spec_helper.rb +0 -22
  161. data/spec/server/static_caching_spec.rb +0 -47
  162. data/spec/server/webrick_servlet_spec.rb +0 -20
  163. data/spec/server_spec.rb +0 -19
  164. data/spec/spec_helper.rb +0 -212
  165. data/spec/tags/default_factory_spec.rb +0 -168
  166. data/spec/tags/default_tag_spec.rb +0 -11
  167. data/spec/tags/directives_spec.rb +0 -463
  168. data/spec/tags/library_spec.rb +0 -48
  169. data/spec/tags/overload_tag_spec.rb +0 -53
  170. data/spec/tags/ref_tag_list_spec.rb +0 -53
  171. data/spec/tags/types_explainer_spec.rb +0 -203
  172. data/spec/templates/class_spec.rb +0 -45
  173. data/spec/templates/constant_spec.rb +0 -41
  174. data/spec/templates/engine_spec.rb +0 -131
  175. data/spec/templates/examples/class001.html +0 -308
  176. data/spec/templates/examples/class001.txt +0 -36
  177. data/spec/templates/examples/class002.html +0 -39
  178. data/spec/templates/examples/constant001.txt +0 -25
  179. data/spec/templates/examples/constant002.txt +0 -7
  180. data/spec/templates/examples/constant003.txt +0 -11
  181. data/spec/templates/examples/method001.html +0 -137
  182. data/spec/templates/examples/method001.txt +0 -35
  183. data/spec/templates/examples/method002.html +0 -91
  184. data/spec/templates/examples/method002.txt +0 -20
  185. data/spec/templates/examples/method003.html +0 -165
  186. data/spec/templates/examples/method003.txt +0 -45
  187. data/spec/templates/examples/method004.html +0 -48
  188. data/spec/templates/examples/method004.txt +0 -10
  189. data/spec/templates/examples/method005.html +0 -105
  190. data/spec/templates/examples/method005.txt +0 -33
  191. data/spec/templates/examples/method006.html +0 -108
  192. data/spec/templates/examples/method006.txt +0 -20
  193. data/spec/templates/examples/module001.dot +0 -33
  194. data/spec/templates/examples/module001.html +0 -833
  195. data/spec/templates/examples/module001.txt +0 -33
  196. data/spec/templates/examples/module002.html +0 -341
  197. data/spec/templates/examples/module003.html +0 -202
  198. data/spec/templates/examples/module004.html +0 -394
  199. data/spec/templates/examples/module005.html +0 -82
  200. data/spec/templates/examples/tag001.txt +0 -82
  201. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  202. data/spec/templates/helpers/html_helper_spec.rb +0 -666
  203. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  204. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  205. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  206. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  207. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  208. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  209. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  210. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  211. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
  212. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
  213. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  214. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
  215. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
  216. data/spec/templates/method_spec.rb +0 -118
  217. data/spec/templates/module_spec.rb +0 -203
  218. data/spec/templates/onefile_spec.rb +0 -66
  219. data/spec/templates/section_spec.rb +0 -144
  220. data/spec/templates/spec_helper.rb +0 -76
  221. data/spec/templates/tag_spec.rb +0 -52
  222. data/spec/templates/template_spec.rb +0 -410
  223. data/spec/verifier_spec.rb +0 -106
@@ -1,38 +0,0 @@
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('— YARD-On-YARD')).to be >= 0
35
- end
36
- end
37
- end
38
- end if ENV['CI'] || ENV['YY']
@@ -1,896 +0,0 @@
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