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,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Parser, "tag handling" do
4
- before { parse_file :tag_handler_001, __FILE__ }
5
-
6
- it "knows the list of all available tags" do
7
- expect(P("Foo#foo").tags).to include(P("Foo#foo").tag(:api))
8
- end
9
-
10
- it "knows the text of tags on a method" do
11
- expect(P("Foo#foo").tag(:api).text).to eq "public"
12
- end
13
-
14
- it "returns true when asked whether a tag exists" do
15
- expect(P("Foo#foo").has_tag?(:api)).to be true
16
- end
17
- end
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Rake::YardocTask 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(YARD::CLI::Yardoc).to receive(:new).and_return(@yardoc)
16
- ::Rake.application.clear
17
- end
18
-
19
- def run
20
- ::Rake.application.tasks[0].invoke
21
- end
22
-
23
- describe "#initialize" do
24
- it "allows separate rake task name to be set" do
25
- YARD::Rake::YardocTask.new(:notyardoc)
26
- expect(::Rake.application.tasks[0].name).to eq "notyardoc"
27
- end
28
- end
29
-
30
- describe "#files" do
31
- it "allows files to be set" do
32
- YARD::Rake::YardocTask.new do |t|
33
- t.files = ['a', 'b', 'c']
34
- end
35
- run
36
- expect(@yardoc.files).to eq %w(a b c)
37
- end
38
- end
39
-
40
- describe "#options" do
41
- it "allows extra options to be set" do
42
- YARD::Rake::YardocTask.new do |t|
43
- t.options = ['--private', '--protected']
44
- end
45
- run
46
- expect(@yardoc.visibilities).to eq [:public, :private, :protected]
47
- end
48
-
49
- it "allows --api and --no-api" do
50
- YARD::Rake::YardocTask.new do |t|
51
- t.options = %w(--api public --no-api)
52
- end
53
- run
54
- expect(@yardoc.options.verifier.expressions).to include('["public"].include?(@api.text) || !@api')
55
- end
56
- end
57
-
58
- describe "#stats_options" do
59
- before do
60
- @yard_stats = Object.new
61
- allow(@yard_stats).to receive(:run)
62
- allow(YARD::CLI::Stats).to receive(:new).and_return(@yard_stats)
63
- end
64
-
65
- it "invokes stats" do
66
- expect(@yard_stats).to receive(:run).with('--list-undoc', '--use-cache')
67
- @yardoc.statistics = true
68
- YARD::Rake::YardocTask.new do |t|
69
- t.stats_options = %w(--list-undoc)
70
- end
71
- run
72
- expect(@yardoc.statistics).to be false
73
- end
74
- end
75
-
76
- describe "#before" do
77
- it "allows before callback" do
78
- proc = lambda {}
79
- expect(proc).to receive(:call)
80
- expect(@yardoc).to receive(:run)
81
- YARD::Rake::YardocTask.new {|t| t.before = proc }
82
- run
83
- end
84
- end
85
-
86
- describe "#after" do
87
- it "allows after callback" do
88
- proc = lambda {}
89
- expect(proc).to receive(:call)
90
- expect(@yardoc).to receive(:run)
91
- YARD::Rake::YardocTask.new {|t| t.after = proc }
92
- run
93
- end
94
- end
95
-
96
- describe "#verifier" do
97
- it "allows a verifier proc to be set" do
98
- verifier = Verifier.new
99
- expect(@yardoc).to receive(:run) do
100
- expect(@yardoc.options[:verifier]).to eq verifier
101
- end
102
- YARD::Rake::YardocTask.new {|t| t.verifier = verifier }
103
- run
104
- end
105
-
106
- it "overrides --query options" do
107
- verifier = Verifier.new
108
- expect(@yardoc).to receive(:run) do
109
- expect(@yardoc.options[:verifier]).to eq verifier
110
- end
111
- YARD::Rake::YardocTask.new do |t|
112
- t.options += ['--query', '@return']
113
- t.verifier = verifier
114
- end
115
- run
116
- end
117
- end
118
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::RegistryResolver do
4
- include YARD::CodeObjects::NamespaceMapper
5
-
6
- describe '#starts_with_separator_match' do
7
- subject { RegistryResolver.new }
8
-
9
- it 'should clear cache when a namespace separator is registered' do
10
- expect(subject.send(:starts_with_separator_match).to_s).not_to include('!')
11
- register_separator '!', :test_type
12
- expect(subject.send(:starts_with_separator_match).to_s).to include('!')
13
- end
14
- end
15
- end
@@ -1,463 +0,0 @@
1
- # frozen_string_literal: true
2
- include CodeObjects
3
-
4
- require "thread"
5
-
6
- RSpec.describe YARD::Registry do
7
- before { Registry.clear }
8
-
9
- describe ".yardoc_file_for_gem" do
10
- before do
11
- @gem = double('gem')
12
- allow(@gem).to receive(:name).and_return('foo')
13
- allow(@gem).to receive(:full_name).and_return('foo-1.0')
14
- allow(@gem).to receive(:full_gem_path).and_return('/path/to/foo')
15
- allow(@gem).to receive(:doc_dir).and_return('/path/to/foo/doc')
16
- allow(@gem).to receive(:doc_dir).with('.yardoc').and_return('/path/to/foo/doc/.yardoc')
17
- end
18
-
19
- it "returns nil if gem isn't found" do
20
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([])
21
- expect(Registry.yardoc_file_for_gem('foo')).to eq nil
22
- end
23
-
24
- it "allows version to be specified" do
25
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '= 2').and_return([])
26
- expect(Registry.yardoc_file_for_gem('foo', '= 2')).to eq nil
27
- end
28
-
29
- it "returns existing .yardoc path for gem when for_writing=false" do
30
- allow(File).to receive(:exist?).twice.and_return(false)
31
- allow(File).to receive(:exist?).with('/path/to/foo/.yardoc').and_return(true)
32
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
33
- expect(Registry.yardoc_file_for_gem('foo')).to eq '/path/to/foo/.yardoc'
34
- end
35
-
36
- it "returns new existing .yardoc path for gem when for_writing=false" do
37
- allow(File).to receive(:exist?).and_return(false)
38
- allow(File).to receive(:exist?).with('/path/to/foo/doc/.yardoc').and_return(true)
39
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
40
- expect(Registry.yardoc_file_for_gem('foo')).to eq '/path/to/foo/doc/.yardoc'
41
- end
42
-
43
- it "returns nil if no .yardoc path exists in gem when for_writing=false" do
44
- allow(File).to receive(:exist?).twice.and_return(false)
45
- allow(File).to receive(:exist?).with('/path/to/foo/.yardoc').and_return(false)
46
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
47
- expect(Registry.yardoc_file_for_gem('foo')).to eq nil
48
- end
49
-
50
- it "searches local gem path first if for_writing=false" do
51
- allow(File).to receive(:exist?).and_return(true)
52
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
53
- expect(Registry.yardoc_file_for_gem('foo')).to match %r{/.yard/gem_index/foo-1.0.yardoc$}
54
- end
55
-
56
- it "returns global .yardoc path for gem if for_writing=true and dir is writable" do
57
- allow(File).to receive(:exist?).and_return(false)
58
- allow(File).to receive(:directory?).with(@gem.doc_dir).and_return(true)
59
- allow(File).to receive(:writable?).with(@gem.doc_dir).and_return(false)
60
- allow(File).to receive(:writable?).with(@gem.full_gem_path).and_return(true)
61
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
62
- expect(Registry.yardoc_file_for_gem('foo', '>= 0', true)).to eq '/path/to/foo/.yardoc'
63
- end
64
-
65
- it "returns new global .yardoc path for gem if for_writing=true and dir is writable" do
66
- allow(File).to receive(:writable?).with(@gem.doc_dir).and_return(true)
67
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
68
- expect(Registry.yardoc_file_for_gem('foo', '>= 0', true)).to eq '/path/to/foo/doc/.yardoc'
69
- end
70
-
71
- it "returns new global .yardoc path for gem if for_writing=true and parent dir is writable (but dir does not exist)" do
72
- allow(File).to receive(:writable?).with(@gem.doc_dir).and_return(false)
73
- allow(File).to receive(:directory?).with(@gem.doc_dir).and_return(false)
74
- allow(File).to receive(:writable?).with(File.dirname(@gem.doc_dir)).and_return(true)
75
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
76
- expect(Registry.yardoc_file_for_gem('foo', '>= 0', true)).to eq '/path/to/foo/doc/.yardoc'
77
- end
78
-
79
- it "returns local .yardoc path for gem if for_writing=true and dir is not writable" do
80
- allow(File).to receive(:writable?).with(@gem.doc_dir).and_return(false)
81
- allow(File).to receive(:writable?).with(@gem.full_gem_path).and_return(false)
82
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('foo', '>= 0').and_return([@gem])
83
- expect(Registry.yardoc_file_for_gem('foo', '>= 0', true)).to match %r{/.yard/gem_index/foo-1.0.yardoc$}
84
- end
85
-
86
- it "returns gem path if gem starts with yard-doc- and for_writing=false" do
87
- allow(@gem).to receive(:name).and_return('yard-doc-core')
88
- allow(@gem).to receive(:full_name).and_return('yard-doc-core-1.0')
89
- allow(@gem).to receive(:full_gem_path).and_return('/path/to/yard-doc-core')
90
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('yard-doc-core', '>= 0').and_return([@gem])
91
- allow(File).to receive(:exist?).with('/path/to/yard-doc-core/.yardoc').and_return(true)
92
- expect(Registry.yardoc_file_for_gem('yard-doc-core')).to eq '/path/to/yard-doc-core/.yardoc'
93
- end
94
-
95
- it "returns nil if gem starts with yard-doc- and for_writing=true" do
96
- allow(@gem).to receive(:name).and_return('yard-doc-core')
97
- allow(@gem).to receive(:full_name).and_return('yard-doc-core-1.0')
98
- allow(@gem).to receive(:full_gem_path).and_return('/path/to/yard-doc-core')
99
- allow(YARD::GemIndex).to receive(:find_all_by_name).with('yard-doc-core', '>= 0').and_return([@gem])
100
- allow(File).to receive(:exist?).with('/path/to/yard-doc-core/.yardoc').and_return(true)
101
- expect(Registry.yardoc_file_for_gem('yard-doc-core', '>= 0', true)).to eq nil
102
- end
103
- end
104
-
105
- describe ".root" do
106
- it "has an empty path for root" do
107
- expect(Registry.root.path).to eq ""
108
- end
109
- end
110
-
111
- describe ".locale" do
112
- it "loads locale object" do
113
- fr_locale = I18n::Locale.new("fr")
114
- store = Registry.send(:thread_local_store)
115
- expect(store).to receive(:locale).with("fr").and_return(fr_locale)
116
- expect(Registry.locale("fr")).to eq fr_locale
117
- end
118
- end
119
-
120
- describe ".resolve" do
121
- it "resolves any existing namespace" do
122
- o1 = ModuleObject.new(:root, :A)
123
- o2 = ModuleObject.new(o1, :B)
124
- o3 = ModuleObject.new(o2, :C)
125
- expect(Registry.resolve(o1, "B::C")).to eq o3
126
- Registry.resolve(:root, "A::B::C")
127
- end
128
-
129
- it "resolves an object in the root namespace when prefixed with ::" do
130
- o1 = ModuleObject.new(:root, :A)
131
- o2 = ModuleObject.new(o1, :B)
132
- o3 = ModuleObject.new(o2, :C)
133
- expect(Registry.resolve(o3, "::A")).to eq o1
134
-
135
- expect(Registry.resolve(o3, "::String", false, true)).to eq P(:String)
136
- end
137
-
138
- it "resolves instance methods with # prefix" do
139
- o1 = ModuleObject.new(:root, :A)
140
- o2 = ModuleObject.new(o1, :B)
141
- o3 = ModuleObject.new(o2, :C)
142
- o4 = MethodObject.new(o3, :methname)
143
- expect(Registry.resolve(o1, "B::C#methname")).to eq o4
144
- expect(Registry.resolve(o2, "C#methname")).to eq o4
145
- expect(Registry.resolve(o3, "#methname")).to eq o4
146
- end
147
-
148
- it "resolves instance methods in the root without # prefix" do
149
- o = MethodObject.new(:root, :methname)
150
- expect(Registry.resolve(:root, 'methname')).to eq o
151
- end
152
-
153
- it "does lexical lookup on the initial namespace" do
154
- YARD.parse_string <<-eof
155
- module A
156
- module B; module C; end end
157
- module D; module E; end end
158
- end
159
- eof
160
-
161
- d = Registry.at('A::B::C')
162
- expect(Registry.resolve(d, 'D::E')).to eq Registry.at('A::D::E')
163
- end
164
-
165
- it "resolves superclass methods when inheritance = true" do
166
- superyard = ClassObject.new(:root, :SuperYard)
167
- yard = ClassObject.new(:root, :YARD)
168
- yard.superclass = superyard
169
- imeth = MethodObject.new(superyard, :hello)
170
- cmeth = MethodObject.new(superyard, :class_hello, :class)
171
-
172
- expect(Registry.resolve(yard, "#hello", false)).to be nil
173
- expect(Registry.resolve(yard, "#hello", true)).to eq imeth
174
- expect(Registry.resolve(yard, "class_hello", false)).to be nil
175
- expect(Registry.resolve(yard, "class_hello", true)).to eq cmeth
176
- end
177
-
178
- it "does not look at superclass proxies when inheritance = true" do
179
- YARD.parse_string "class A::B; end"
180
- expect(Registry.resolve(Registry.at('A::B'), "#bar", true)).to eq nil
181
- end
182
-
183
- it "resolves mixin methods when inheritance = true" do
184
- yard = ClassObject.new(:root, :YARD)
185
- mixin = ModuleObject.new(:root, :Mixin)
186
- yard.mixins(:instance) << mixin
187
- imeth = MethodObject.new(mixin, :hello)
188
- cmeth = MethodObject.new(mixin, :class_hello, :class)
189
-
190
- expect(Registry.resolve(yard, "#hello", false)).to be nil
191
- expect(Registry.resolve(yard, "#hello", true)).to eq imeth
192
- expect(Registry.resolve(yard, "class_hello", false)).to be nil
193
- expect(Registry.resolve(yard, "class_hello", true)).to eq cmeth
194
- end
195
-
196
- it "resolves methods in Object when inheritance = true" do
197
- YARD.parse_string <<-eof
198
- class Object; def foo; end end
199
- class A; end
200
- class MyObject < A; end
201
- eof
202
-
203
- expect(Registry.resolve(P('MyObject'), '#foo', true)).to eq P('Object#foo')
204
- end
205
-
206
- it "resolves methods in BasicObject when inheritance = true" do
207
- YARD.parse_string <<-eof
208
- class BasicObject; def foo; end end
209
- class A; end
210
- class MyObject < A; end
211
- eof
212
-
213
- expect(Registry.resolve(P('MyObject'), '#foo', true)).to eq P('BasicObject#foo')
214
- end
215
-
216
- it "does not perform lexical lookup to resolve a method object by more than one namespace" do
217
- YARD.parse_string <<-eof
218
- module A
219
- def foo; end
220
- def self.bar; end
221
- module B; module C; end end
222
- end
223
- eof
224
-
225
- expect(Registry.resolve(P('A::B::C'), '#foo', true)).to be nil
226
- expect(Registry.resolve(P('A::B::C'), '.bar', true)).to be nil
227
- expect(Registry.resolve(P('A::B'), '#foo', true)).not_to be nil
228
- expect(Registry.resolve(P('A::B'), '.bar', true)).not_to be nil
229
- end
230
-
231
- it "does not resolve methods in Object if inheriting BasicObject when inheritance = true" do
232
- YARD.parse_string <<-eof
233
- class Object; def foo; end end
234
- class MyObject < BasicObject; end
235
- eof
236
-
237
- expect(Registry.resolve(P('MyObject'), '#foo', true)).to be nil
238
- end
239
-
240
- it "performs lookups on each individual namespace when inheritance = true" do
241
- YARD.parse_string <<-eof
242
- module A
243
- module B; include A::D end
244
- module C; extend A::D end
245
- module D; def bar; end end
246
- end
247
- eof
248
-
249
- r = Registry.root
250
- expect(Registry.resolve(r, 'A::B#bar', true)).to eq Registry.at('A::D#bar')
251
- expect(Registry.resolve(r, 'A::C.bar', true)).to eq Registry.at('A::D#bar')
252
- end
253
-
254
- it "allows type=:typename to ensure resolved object is of a certain type" do
255
- YARD.parse_string "class Foo; end"
256
- expect(Registry.resolve(Registry.root, 'Foo')).to eq Registry.at('Foo')
257
- expect(Registry.resolve(Registry.root, 'Foo', false, false, :method)).to be nil
258
- end
259
-
260
- it "allows keep trying to find obj where type equals object type" do
261
- YARD.parse_string <<-eof
262
- module Foo
263
- class Bar; end
264
- def self.Bar; end
265
- end
266
- eof
267
- expect(Registry.resolve(P('Foo'), 'Bar', false, false, :class)).to eq Registry.at('Foo::Bar')
268
- expect(Registry.resolve(P('Foo'), 'Bar', false, false, :method)).to eq(
269
- Registry.at('Foo.Bar')
270
- )
271
- end
272
-
273
- it "returns proxy fallback with given type if supplied" do
274
- YARD.parse_string "module Foo; end"
275
- proxy = Registry.resolve(P('Foo'), 'Bar', false, true, :method)
276
- expect(proxy.type).to eq :method
277
- proxy = Registry.resolve(P('Qux'), 'Bar', false, true, :method)
278
- expect(proxy.type).to eq :method
279
- end
280
-
281
- it "does not return proxy on original namespace if path is anchored to root" do
282
- YARD.parse_string "module Foo; class Bar; def baz; end end end"
283
- proxy = Registry.resolve(P('Foo::Bar#baz'), '::Bar', true, true)
284
- expect(proxy.path).to eq('Bar')
285
- expect(proxy.namespace).to equal(Registry.root)
286
- expect(proxy.type).to eq(:proxy)
287
- end
288
-
289
- it "only checks 'Path' in lookup on root namespace" do
290
- expect(Registry).to receive(:at).once.with('Test').and_return(true)
291
- Registry.resolve(Registry.root, "Test")
292
- end
293
-
294
- it "does not perform lookup by joining namespace and name without separator" do
295
- yard = ClassObject.new(:root, :YARD)
296
- expect(Registry).not_to receive(:at).with('YARDB')
297
- Registry.resolve(yard, 'B')
298
- end
299
- end
300
-
301
- describe ".all" do
302
- it "returns objects of types specified by arguments" do
303
- ModuleObject.new(:root, :A)
304
- o1 = ClassObject.new(:root, :B)
305
- o2 = MethodObject.new(:root, :testing)
306
- r = Registry.all(:method, :class)
307
- expect(r).to include(o1, o2)
308
- end
309
-
310
- it "returns code objects" do
311
- o1 = ModuleObject.new(:root, :A)
312
- o2 = ClassObject.new(:root, :B)
313
- MethodObject.new(:root, :testing)
314
- r = Registry.all.select {|t| NamespaceObject === t }
315
- expect(r).to include(o1, o2)
316
- end
317
-
318
- it "allows .all to omit list" do
319
- o1 = ModuleObject.new(:root, :A)
320
- o2 = ClassObject.new(:root, :B)
321
- r = Registry.all
322
- expect(r).to include(o1, o2)
323
- end
324
- end
325
-
326
- describe ".paths" do
327
- it "returns all object paths" do
328
- ModuleObject.new(:root, :A)
329
- ClassObject.new(:root, :B)
330
- expect(Registry.paths).to include('A', 'B')
331
- end
332
- end
333
-
334
- describe ".load_yardoc" do
335
- it "delegates load to RegistryStore" do
336
- store = RegistryStore.new
337
- expect(store).to receive(:load).with('foo')
338
- expect(RegistryStore).to receive(:new).and_return(store)
339
- Registry.yardoc_file = 'foo'
340
- Registry.load_yardoc
341
- end
342
-
343
- it "returns itself" do
344
- expect(Registry.load_yardoc).to eq Registry
345
- end
346
-
347
- it "maintains hash key equality on loaded objects" do
348
- Registry.clear
349
- Registry.load!(File.dirname(__FILE__) + '/serializers/data/serialized_yardoc')
350
- baz = Registry.at('Foo#baz')
351
- expect(Registry.at('Foo').aliases.keys).to include(baz)
352
- expect(Registry.at('Foo').aliases.key?(baz)).to be true
353
- end
354
- end
355
-
356
- ['load', 'load_all', 'load!'].each do |meth|
357
- describe('.' + meth) do
358
- it "returns itself" do
359
- expect(Registry.send(meth)).to eq Registry
360
- end
361
- end
362
- end
363
-
364
- describe ".each" do
365
- before do
366
- YARD.parse_string "def a; end; def b; end; def c; end"
367
- end
368
-
369
- after { Registry.clear }
370
-
371
- it "iterates over .all" do
372
- items = []
373
- Registry.each {|x| items << x.path }
374
- expect(items.sort).to eq ['#a', '#b', '#c']
375
- end
376
-
377
- it "includes Enumerable and allow for find, select" do
378
- expect(Registry.find {|x| x.path == "#a" }).to be_a(CodeObjects::MethodObject)
379
- end
380
- end
381
-
382
- describe ".instance" do
383
- it "returns itself" do
384
- expect(Registry.instance).to eq Registry
385
- end
386
- end
387
-
388
- describe ".single_object_db" do
389
- it "defaults to nil" do
390
- expect(Registry.single_object_db).to eq nil
391
- Thread.new { expect(Registry.single_object_db).to eq nil }.join
392
- end
393
- end
394
-
395
- describe "Thread local" do
396
- it "maintains two Registries in separate threads" do
397
- barrier = 0
398
- mutex = Mutex.new
399
- threads = []
400
- threads << Thread.new do
401
- Registry.clear
402
- YARD.parse_string "# docstring 1\nclass Foo; end"
403
- mutex.synchronize { barrier += 1 }
404
- "barrier < 2, spinning" while barrier < 2
405
- expect(Registry.at('Foo').docstring).to eq "docstring 1"
406
- end
407
- threads << Thread.new do
408
- Registry.clear
409
- YARD.parse_string "# docstring 2\nclass Foo; end"
410
- mutex.synchronize { barrier += 1 }
411
- "barrier < 2, spinning" while barrier < 2
412
- expect(Registry.at('Foo').docstring).to eq "docstring 2"
413
- end
414
- threads.each(&:join)
415
- end
416
-
417
- it "allows setting of yardoc_file in separate threads" do
418
- barrier = 0
419
- mutex = Mutex.new
420
- threads = []
421
- threads << Thread.new do
422
- expect(Registry.yardoc_file).to eq '.yardoc'
423
- Registry.yardoc_file = 'foo'
424
- mutex.synchronize { barrier += 1 }
425
- "barrier = 1, spinning" while barrier == 1
426
- expect(Registry.yardoc_file).to eq 'foo'
427
- end
428
- threads << Thread.new do
429
- "barrier = 0, spinning" while barrier == 0
430
- expect(Registry.yardoc_file).to eq '.yardoc'
431
- mutex.synchronize { barrier += 1 }
432
- Registry.yardoc_file = 'foo2'
433
- end
434
- threads.each(&:join)
435
- Registry.yardoc_file = Registry::DEFAULT_YARDOC_FILE
436
- end
437
-
438
- it "automatically clears in new threads" do
439
- Thread.new { expect(Registry.all).to be_empty }.join
440
- end
441
-
442
- it "allows setting of po_dir in separate threads" do
443
- barrier = 0
444
- mutex = Mutex.new
445
- threads = []
446
- threads << Thread.new do
447
- expect(Registry.po_dir).to eq 'po'
448
- Registry.po_dir = 'locale'
449
- mutex.synchronize { barrier += 1 }
450
- "barrier = 1, spinning" while barrier == 1
451
- expect(Registry.po_dir).to eq 'locale'
452
- end
453
- threads << Thread.new do
454
- "barrier = 0, spinning" while barrier == 0
455
- expect(Registry.po_dir).to eq 'po'
456
- mutex.synchronize { barrier += 1 }
457
- Registry.po_dir = '.'
458
- end
459
- threads.each(&:join)
460
- Registry.po_dir = Registry::DEFAULT_PO_DIR
461
- end
462
- end
463
- end