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,32 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe YARD::CodeObjects::NamespaceMapper do
5
- include YARD::CodeObjects::NamespaceMapper
6
-
7
- describe '#register_separator' do
8
- it 'should allow separators to be registered' do
9
- register_separator '!', :test_type
10
-
11
- expect(separators_for_type(:test_type)).to eq ['!']
12
- expect(types_for_separator('!')).to eq [:test_type]
13
-
14
- unregister_separator_by_type :test_type
15
-
16
- expect(separators_for_type(:test_type)).to be_empty
17
- expect(types_for_separator('!')).to be_empty
18
- end
19
- end
20
-
21
- describe '.on_invalidate' do
22
- it 'receives a callback when a new separator is added' do
23
- invalidated = false
24
- NamespaceMapper.on_invalidate { invalidated = true }
25
-
26
- register_separator '!', :test_type
27
- expect(invalidated).to be true
28
-
29
- unregister_separator_by_type :test_type
30
- end
31
- end
32
- end
@@ -1,171 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe YARD::CodeObjects::NamespaceObject do
5
- before { Registry.clear }
6
-
7
- describe "#child" do
8
- it "returns the object matching the name passed in if argument is a Symbol" do
9
- obj = NamespaceObject.new(nil, :YARD)
10
- other = NamespaceObject.new(obj, :Other)
11
- expect(obj.child(:Other)).to eq other
12
- expect(obj.child('Other')).to eq other
13
- end
14
-
15
- it "looks for attributes matching the object if the argument is a Hash" do
16
- obj = NamespaceObject.new(nil, :YARD)
17
- NamespaceObject.new(obj, :NotOther)
18
- other = NamespaceObject.new(obj, :Other)
19
- other.somevalue = 2
20
- expect(obj.child(:somevalue => 2)).to eq other
21
- end
22
- end
23
-
24
- describe "#meths" do
25
- it "returns #meths even if parent is a Proxy" do
26
- obj = NamespaceObject.new(P(:String), :YARD)
27
- expect(obj.meths).to be_empty
28
- end
29
-
30
- it "does not list included methods that are already defined in the namespace using #meths" do
31
- a = ModuleObject.new(nil, :Mod1)
32
- ameth = MethodObject.new(a, :testing)
33
- b = ModuleObject.new(nil, :Mod2)
34
- bmeth = MethodObject.new(b, :foo)
35
- c = NamespaceObject.new(nil, :YARD)
36
- cmeth = MethodObject.new(c, :testing)
37
- cmeth2 = MethodObject.new(c, :foo)
38
- c.instance_mixins << a
39
- c.class_mixins << b
40
-
41
- meths = c.meths
42
- expect(meths).to include(bmeth)
43
- expect(meths).to include(cmeth)
44
- expect(meths).to include(cmeth2)
45
- expect(meths).not_to include(ameth)
46
-
47
- meths = c.included_meths
48
- expect(meths).to include(bmeth)
49
- expect(meths).not_to include(ameth)
50
- expect(meths).not_to include(cmeth)
51
- expect(meths).not_to include(cmeth2)
52
- end
53
- end
54
-
55
- describe "#included_meths" do
56
- it "lists methods mixed into the class scope as class methods" do
57
- b = ModuleObject.new(nil, :Mod2)
58
- bmeth = MethodObject.new(b, :foo)
59
- bmeth2 = MethodObject.new(b, :foo2)
60
- c = NamespaceObject.new(nil, :YARD)
61
- c.class_mixins << b
62
-
63
- [bmeth, bmeth2].each {|o| expect(o.scope).to eq :instance }
64
- meths = c.included_meths(:scope => :class)
65
- meths.each {|o| expect(o.scope).to eq :class }
66
- end
67
-
68
- it "does not list methods overridden by another included module" do
69
- a = ModuleObject.new(nil, :Mod)
70
- ameth = MethodObject.new(a, :testing)
71
- b = ModuleObject.new(nil, :Mod2)
72
- bmeth = MethodObject.new(b, :testing)
73
- c = NamespaceObject.new(nil, :YARD)
74
- c.instance_mixins.unshift a
75
- c.instance_mixins.unshift b
76
- c.class_mixins.unshift b
77
- c.class_mixins.unshift a
78
-
79
- meths = c.included_meths(:scope => :instance)
80
- expect(meths).not_to include(ameth)
81
- expect(meths).to include(bmeth)
82
-
83
- meths = c.included_meths(:scope => :class)
84
- expect(meths).to include(ameth)
85
- expect(meths).not_to include(bmeth)
86
- end
87
- end
88
-
89
- describe "#class_attributes" do
90
- it "lists class attributes" do
91
- a = NamespaceObject.new(nil, :Mod)
92
- a.attributes[:instance][:a] = {:read => MethodObject.new(a, :a), :write => nil}
93
- a.attributes[:instance][:b] = {:read => MethodObject.new(a, :b), :write => nil}
94
- a.attributes[:class][:a] = {:read => MethodObject.new(a, :a, :class), :write => nil}
95
- expect(a.class_attributes.keys).to include(:a)
96
- expect(a.class_attributes.keys).not_to include(:b)
97
- end
98
- end
99
-
100
- describe "#instance_attributes" do
101
- it "lists instance attributes" do
102
- a = NamespaceObject.new(nil, :Mod)
103
- a.attributes[:instance][:a] = {:read => MethodObject.new(a, :a), :write => nil}
104
- a.attributes[:instance][:b] = {:read => MethodObject.new(a, :b), :write => nil}
105
- a.attributes[:class][:a] = {:read => MethodObject.new(a, :a, :class), :write => nil}
106
- expect(a.instance_attributes.keys).to include(:a)
107
- expect(a.instance_attributes.keys).to include(:b)
108
- end
109
- end
110
-
111
- describe "#constants/#included_constants" do
112
- before do
113
- Registry.clear
114
-
115
- YARD.parse_string <<-eof
116
- module A
117
- CONST1 = 1
118
- CONST2 = 2
119
- end
120
-
121
- module B
122
- CONST2 = -2
123
- CONST3 = -3
124
- end
125
-
126
- class C
127
- CONST3 = 3
128
- CONST4 = 4
129
-
130
- include A
131
- include B
132
- end
133
- eof
134
- end
135
-
136
- it "lists all included constants by default" do
137
- consts = P(:C).constants
138
- expect(consts).to include(P('A::CONST1'))
139
- expect(consts).to include(P('C::CONST4'))
140
- end
141
-
142
- it "allows :included to be set to false to ignore included constants" do
143
- consts = P(:C).constants(:included => false)
144
- expect(consts).not_to include(P('A::CONST1'))
145
- expect(consts).to include(P('C::CONST4'))
146
- end
147
-
148
- it "does not list an included constant if it is defined in the object" do
149
- consts = P(:C).constants
150
- expect(consts).to include(P('C::CONST3'))
151
- expect(consts).not_to include(P('B::CONST3'))
152
- end
153
-
154
- it "does not list an included constant if it is shadowed by another included constant" do
155
- consts = P(:C).included_constants
156
- expect(consts).to include(P('B::CONST2'))
157
- expect(consts).not_to include(P('A::CONST2'))
158
- end
159
- end
160
-
161
- describe "#included_meths" do
162
- it "returns all included methods with :all = true" do
163
- YARD.parse_string <<-eof
164
- module B; def foo; end end
165
- module C; def bar; end end
166
- class A; include B; include C; def foo; end; def bar; end end
167
- eof
168
- expect(Registry.at('A').included_meths(:all => true)).to eq [P('C#bar'), P('B#foo')]
169
- end
170
- end
171
- end
@@ -1,147 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe YARD::CodeObjects::Proxy do
5
- before { Registry.clear }
6
-
7
- it "does not allow constants to be used as a namespace if they do not resolve to a valid namespace" do
8
- a = ConstantObject.new(:root, :A)
9
- a.value = "$$INVALID$$"
10
- expect { P("A::MyClass") }.to raise_error(Parser::UndocumentableError)
11
- end
12
-
13
- it "returns the object if it's in the Registry" do
14
- ModuleObject.new(:root, :YARD)
15
- proxyobj = P(:root, :YARD)
16
- expect(proxyobj.type).to eq :module
17
- expect(Proxy === proxyobj).to be false
18
- end
19
-
20
- it "handles complex string namespaces" do
21
- ModuleObject.new(:root, :A)
22
- ModuleObject.new(P(nil, :A), :B)
23
- expect(P(:root, "A::B")).to be_instance_of(ModuleObject)
24
- end
25
-
26
- it "does not return true to Proxy === obj if obj is a Proxy class holding a resolved object" do
27
- expect(Proxy === P(:root, 'a')).to be true
28
- expect(Proxy === P(:root)).to be false
29
- MethodObject.new(:root, 'a')
30
- expect(Proxy === P(:root, 'a')).to be false
31
- x = Proxy.new(:root, 'a')
32
- expect(Proxy === x).to be false
33
- end
34
-
35
- it "returns the object if it's an included Module" do
36
- yardobj = ModuleObject.new(:root, :YARD)
37
- pathobj = ClassObject.new(:root, :TestClass)
38
- pathobj.instance_mixins << yardobj
39
- expect(P(P(nil, :TestClass), :YARD)).to be_instance_of(ModuleObject)
40
- end
41
-
42
- it "responds to respond_to?" do
43
- ClassObject.new(:root, :Object)
44
- ModuleObject.new(:root, :YARD)
45
- expect(P(:YARD).respond_to?(:children)).to be true
46
- expect(P(:NOTYARD).respond_to?(:children)).to be false
47
-
48
- expect(P(:YARD).respond_to?(:initialize)).to be false
49
- expect(P(:YARD).respond_to?(:initialize, true)).to be true
50
- expect(P(:NOTYARD).respond_to?(:initialize)).to be false
51
- expect(P(:NOTYARD).respond_to?(:initialize, true)).to be true
52
- end
53
-
54
- it "makes itself obvious that it's a proxy" do
55
- pathobj = P(:root, :YARD)
56
- expect(pathobj.class).to eq Proxy
57
- expect(Proxy === pathobj).to be true
58
- end
59
-
60
- it "pretends it's the object's type if it can resolve" do
61
- ModuleObject.new(:root, :YARD)
62
- proxyobj = P(:root, :YARD)
63
- expect(proxyobj).to be_instance_of(ModuleObject)
64
- end
65
-
66
- it "handles instance method names" do
67
- obj = P(nil, '#test')
68
- expect(obj.name).to eq :test
69
- expect(obj.path).to eq "#test"
70
- expect(obj.namespace).to eq Registry.root
71
- end
72
-
73
- it "handles instance method names under a namespace" do
74
- pathobj = ModuleObject.new(:root, :YARD)
75
- obj = P(pathobj, "A::B#test")
76
- expect(obj.name).to eq :test
77
- expect(obj.path).to eq "A::B#test"
78
- end
79
-
80
- it "allows type to be changed" do
81
- obj = P("InvalidClass")
82
- expect(obj.type).to eq :proxy
83
- expect(Proxy === obj).to be true
84
- obj.type = :class
85
- expect(obj.type).to eq :class
86
- end
87
-
88
- it "does NOT retain a type change between Proxy objects" do
89
- P("InvalidClass").type = :class
90
- expect(P("InvalidClass").type).to eq :proxy
91
- end
92
-
93
- it "uses type to ensure resolved object is of intended type" do
94
- YARD.parse_string <<-eof
95
- module Foo
96
- class Bar; end
97
- def self.Bar; end
98
- end
99
- eof
100
- proxy = Proxy.new(P('Foo'), 'Bar')
101
- proxy.type = :method
102
- expect(proxy.path).to eq 'Foo.Bar'
103
- end
104
-
105
- it "allows type in initializer" do
106
- expect(Proxy.new(Registry.root, 'Foo', :method).type).to eq :method
107
- expect(P(Registry.root, 'Foo', :method).type).to eq :method
108
- end
109
-
110
- it "never equals Registry.root" do
111
- expect(P("MYPROXY")).not_to eq Registry.root
112
- expect(P("X::A")).not_to eq Registry.root
113
- end
114
-
115
- it "resets namespace and name when object is resolved" do
116
- obj1 = ModuleObject.new(:root, :YARD)
117
- obj2 = ModuleObject.new(:root, :NOTYARD)
118
- resolved = Proxy.new(obj2, :YARD)
119
- expect(resolved).to eq obj1
120
- expect(resolved.namespace).to eq Registry.root
121
- expect(resolved.name).to eq :YARD
122
- end
123
-
124
- it "ensures that the correct object was resolved" do
125
- foo = ModuleObject.new(:root, :Foo)
126
- foobar = ModuleObject.new(foo, :Bar)
127
- ClassObject.new(foo, :Baz)
128
-
129
- # Remember, we're looking for Qux::Bar, not just 'Bar'
130
- proxy = Proxy.new(foobar, 'Foo::Qux::Bar')
131
- expect(proxy.type).to eq :proxy
132
-
133
- qux = ModuleObject.new(foo, :Qux)
134
- ModuleObject.new(qux, :Bar)
135
-
136
- # Now it should resolve
137
- expect(proxy.type).to eq :module
138
- end
139
-
140
- it "handles constant names in namespaces" do
141
- YARD.parse_string <<-eof
142
- module A; end; B = A
143
- module B::C; def foo; end end
144
- eof
145
- expect(Proxy.new(:root, 'B::C')).to eq Registry.at('A::C')
146
- end
147
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- include CodeObjects
@@ -1,171 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'yaml'
3
-
4
- RSpec.describe YARD::Config do
5
- describe ".load" do
6
- before do
7
- expect(File).to receive(:file?).twice.with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
8
- end
9
-
10
- it "uses default options if no ~/.yard/config is found" do
11
- expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
12
- expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
13
- YARD::Config.load
14
- expect(YARD::Config.options).to eq YARD::Config::DEFAULT_CONFIG_OPTIONS
15
- end
16
-
17
- it "overwrites options with data in ~/.yard/config" do
18
- expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(true)
19
- expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
20
- expect(YAML).to receive(:load_file).with(YARD::Config::CONFIG_FILE).and_return('test' => true)
21
- YARD::Config.load
22
- expect(YARD::Config.options[:test]).to be true
23
- end
24
-
25
- it "ignores any plugins specified in '~/.yard/ignored_plugins'" do
26
- expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
27
- expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(true)
28
- expect(File).to receive(:read).with(YARD::Config::IGNORED_PLUGINS).and_return('yard-plugin plugin2')
29
- YARD::Config.load
30
- expect(YARD::Config.options[:ignored_plugins]).to eq ['yard-plugin', 'yard-plugin2']
31
- expect(YARD::Config).not_to receive(:require).with('yard-plugin2')
32
- expect(YARD::Config.load_plugin('yard-plugin2')).to be false
33
- end
34
-
35
- it "loads safe_mode setting from --safe command line option" do
36
- expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
37
- expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
38
- ARGV.replace(['--safe'])
39
- YARD::Config.load
40
- expect(YARD::Config.options[:safe_mode]).to be true
41
- ARGV.replace([''])
42
- end
43
- end
44
-
45
- describe ".save" do
46
- it "saves options to config file" do
47
- allow(YARD::Config).to receive(:options).and_return(:a => 1, :b => %w(a b c))
48
- file = double(:file)
49
- expect(File).to receive(:open).with(YARD::Config::CONFIG_FILE, 'w').and_yield(file)
50
- expect(file).to receive(:write).with(YAML.dump(:a => 1, :b => %w(a b c)))
51
- YARD::Config.save
52
- end
53
- end
54
-
55
- describe ".load_plugin" do
56
- it "loads a plugin by 'name' as 'yard-name'" do
57
- expect(YARD::Config).to receive(:require).with('yard-foo')
58
- expect(log).to receive(:debug).with(/Loading plugin 'yard-foo'/).once
59
- expect(YARD::Config.load_plugin('foo')).to be true
60
- end
61
-
62
- it "does not load plugins like 'doc-*'" do
63
- expect(YARD::Config).not_to receive(:require).with('yard-doc-core')
64
- YARD::Config.load_plugin('doc-core')
65
- YARD::Config.load_plugin('yard-doc-core')
66
- end
67
-
68
- it "loads plugin by 'yard-name' as 'yard-name'" do
69
- expect(YARD::Config).to receive(:require).with('yard-foo')
70
- expect(log).to receive(:debug).with(/Loading plugin 'yard-foo'/).once
71
- expect(YARD::Config.load_plugin('yard-foo')).to be true
72
- end
73
-
74
- it "loads plugin by 'yard_name' as 'yard_name'" do
75
- expect(YARD::Config).to receive(:require).with('yard_foo')
76
- expect(log).to receive(:debug).with(/Loading plugin 'yard_foo'/).once
77
- log.show_backtraces = false
78
- expect(YARD::Config.load_plugin('yard_foo')).to be true
79
- end
80
-
81
- it "logs error if plugin is not found" do
82
- expect(YARD::Config).to receive(:require).with('yard-foo').and_raise(LoadError)
83
- expect(log).to receive(:error).with(/Error loading plugin 'yard-foo'/).once
84
- expect(YARD::Config.load_plugin('yard-foo')).to be false
85
- end
86
-
87
- it "sanitizes plugin name (remove /'s)" do
88
- expect(YARD::Config).to receive(:require).with('yard-foofoo')
89
- expect(YARD::Config.load_plugin('foo/foo')).to be true
90
- end
91
-
92
- it "ignores plugins in :ignore_plugins" do
93
- allow(YARD::Config).to receive(:options).and_return(:ignored_plugins => ['yard-foo', 'yard-bar'])
94
- expect(YARD::Config.load_plugin('foo')).to be false
95
- expect(YARD::Config.load_plugin('bar')).to be false
96
- end
97
- end
98
-
99
- describe ".load_plugins" do
100
- it "loads gem plugins if :load_plugins is true" do
101
- allow(YARD::Config).to receive(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
102
- allow(YARD::Config).to receive(:load_plugin)
103
- expect(YARD::Config).to receive(:require).with('rubygems')
104
- YARD::Config.load_plugins
105
- end
106
-
107
- it "ignores gem loading if RubyGems cannot load" do
108
- allow(YARD::Config).to receive(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
109
- expect(YARD::Config).to receive(:require).with('rubygems').and_raise(LoadError)
110
- expect(YARD::Config.load_plugins).to be false
111
- end
112
-
113
- it "loads certain plugins automatically when specified in :autoload_plugins" do
114
- expect(File).to receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
115
- allow(YARD::Config).to receive(:options).and_return(:load_plugins => false, :ignored_plugins => [], :autoload_plugins => ['yard-plugin'])
116
- expect(YARD::Config).to receive(:require).with('yard-plugin').and_return(true)
117
- expect(YARD::Config.load_plugins).to be true
118
- end
119
-
120
- it "parses --plugin from command line arguments" do
121
- expect(YARD::Config).to receive(:arguments).at_least(1).times.and_return(%w(--plugin foo --plugin bar a b c))
122
- expect(YARD::Config).to receive(:load_plugin).with('foo').and_return(true)
123
- expect(YARD::Config).to receive(:load_plugin).with('bar').and_return(true)
124
- expect(YARD::Config.load_plugins).to be true
125
- end
126
-
127
- it "loads --plugin arguments from .yardopts" do
128
- expect(File).to receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).twice.and_return(true)
129
- expect(File).to receive(:file?).with(YARD::Config::CONFIG_FILE).and_return(false)
130
- expect(File).to receive(:file?).with(YARD::Config::IGNORED_PLUGINS).and_return(false)
131
- expect(File).to receive(:read_binary).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).twice.and_return('--plugin foo')
132
- expect(YARD::Config).to receive(:load_plugin).with('foo')
133
- YARD::Config.load
134
- end
135
-
136
- it "loads any gem plugins starting with 'yard_' or 'yard-'" do
137
- expect(File).to receive(:file?).with(CLI::Yardoc::DEFAULT_YARDOPTS_FILE).and_return(false)
138
- allow(YARD::Config).to receive(:options).and_return(:load_plugins => true, :ignored_plugins => ['yard_plugin'], :autoload_plugins => [])
139
- plugins = {
140
- 'yard' => double('yard'),
141
- 'yard_plugin' => double('yard_plugin'),
142
- 'yard-plugin' => double('yard-plugin'),
143
- 'my-yard-plugin' => double('yard-plugin'),
144
- 'rspec' => double('rspec')
145
- }
146
- plugins.each do |k, v|
147
- expect(v).to receive(:name).at_least(1).times.and_return(k)
148
- end
149
-
150
- expect(YARD::GemIndex).to receive(:each) {|&b| plugins.values.each(&b) }
151
- expect(YARD::Config).to receive(:load_plugin).with('yard_plugin').and_return(false)
152
- expect(YARD::Config).to receive(:load_plugin).with('yard-plugin').and_return(true)
153
- expect(YARD::Config.load_plugins).to be true
154
- end
155
-
156
- it "logs an error if a gem raises an error" do
157
- allow(YARD::Config).to receive(:options).and_return(:load_plugins => true, :ignored_plugins => [], :autoload_plugins => [])
158
- plugins = {
159
- 'yard-plugin' => double('yard-plugin')
160
- }
161
- plugins.each do |k, v|
162
- expect(v).to receive(:name).at_least(1).times.and_return(k)
163
- end
164
-
165
- expect(YARD::GemIndex).to receive(:each) {|&b| plugins.values.each(&b) }
166
- expect(YARD::Config).to receive(:load_plugin).with('yard-plugin').and_raise(Gem::LoadError)
167
- expect(log).to receive(:error).with(/Error loading plugin 'yard-plugin'/)
168
- expect(YARD::Config.load_plugins).to be false
169
- end
170
- end
171
- end