yard 0.5.8 → 0.6.0

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 (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
data/spec/cli/yri_spec.rb CHANGED
@@ -7,7 +7,7 @@ end
7
7
  describe YARD::CLI::Yardoc do
8
8
  before do
9
9
  @yri = YARD::CLI::YRI.new
10
- Registry.instance.stub!(:load)
10
+ Registry.stub!(:load)
11
11
  end
12
12
 
13
13
  describe '#find_object' do
@@ -50,5 +50,17 @@ describe YARD::CLI::Yardoc do
50
50
  spaths.should include('line1')
51
51
  spaths.should include('line2')
52
52
  end
53
+
54
+ it "should use DEFAULT_SEARCH_PATHS prior to other paths" do
55
+ YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.push('foo', 'bar')
56
+ path = %r{/\.yard/yri_search_paths$}
57
+ File.should_receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false)
58
+ File.should_receive(:file?).with(path).and_return(true)
59
+ File.should_receive(:readlines).with(path).and_return(%w(line1 line2))
60
+ @yri = YARD::CLI::YRI.new
61
+ spaths = @yri.instance_variable_get("@search_paths")
62
+ spaths[0,4].should == %w(foo bar line1 line2)
63
+ YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.replace([])
64
+ end
53
65
  end
54
66
  end
@@ -42,12 +42,6 @@ describe YARD::CodeObjects::Base do
42
42
  o2.docstring.should == "NOT_DOCSTRING"
43
43
  end
44
44
 
45
- it "should convert string into Docstring when #docstring= is set" do
46
- o = ClassObject.new(:root, :Me)
47
- o.docstring = "DOCSTRING"
48
- o.docstring.should be_instance_of(Docstring)
49
- end
50
-
51
45
  it "should allow complex name and convert that to namespace" do
52
46
  obj = CodeObjects::Base.new(nil, "A::B")
53
47
  obj.namespace.path.should == "A"
@@ -252,4 +246,55 @@ describe YARD::CodeObjects::Base do
252
246
  Registry.at('A#b').relative_path('A#c').should == '#c'
253
247
  end
254
248
  end
249
+
250
+ describe '#docstring=' do
251
+ it "should convert string into Docstring when #docstring= is set" do
252
+ o = ClassObject.new(:root, :Me)
253
+ o.docstring = "DOCSTRING"
254
+ o.docstring.should be_instance_of(Docstring)
255
+ end
256
+
257
+ it "should set docstring to docstring of other object if docstring is '(see Path)'" do
258
+ ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
259
+ o = ClassObject.new(:root, :Me)
260
+ o.docstring = '(see AnotherObject)'
261
+ o.docstring.should == "FOO"
262
+ end
263
+
264
+ it "should allow extra docstring after (see Path)" do
265
+ ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
266
+ o = ClassObject.new(:root, :Me)
267
+ o.docstring = "(see AnotherObject)\n\nEXTRA\n@api private"
268
+ o.docstring.should == "FOO\n\nEXTRA"
269
+ o.docstring.should have_tag(:api)
270
+ end
271
+ end
272
+
273
+ describe '#docstring' do
274
+ it "should return empty string if docstring was '(see Path)' and Path is not resolved" do
275
+ o = ClassObject.new(:root, :Me)
276
+ o.docstring = '(see AnotherObject)'
277
+ o.docstring.should == ""
278
+ end
279
+
280
+ it "should return docstring when object is resolved" do
281
+ o = ClassObject.new(:root, :Me)
282
+ o.docstring = '(see AnotherObject)'
283
+ o.docstring.should == ""
284
+ ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
285
+ o.docstring.should == "FOO"
286
+ end
287
+ end
288
+
289
+ describe '#add_file' do
290
+ it "should only add a file/line combination once" do
291
+ o = ClassObject.new(:root, :Me)
292
+ o.add_file('filename', 12)
293
+ o.files.should == [['filename', 12]]
294
+ o.add_file('filename', 12)
295
+ o.files.should == [['filename', 12]]
296
+ o.add_file('filename', 40) # different line
297
+ o.files.should == [['filename', 12], ['filename', 40]]
298
+ end
299
+ end
255
300
  end
@@ -48,7 +48,7 @@ describe YARD::CodeObjects::ClassObject do
48
48
  before(:all) do
49
49
  Registry.clear
50
50
 
51
- Parser::SourceParser.parse_string <<-eof
51
+ YARD.parse_string <<-eof
52
52
  class SuperYard < String
53
53
  def foo; end
54
54
  def foo2; end
@@ -67,6 +67,14 @@ describe YARD::CodeObjects::ClassObject do
67
67
  def mymethod; end
68
68
  def bar; end
69
69
  end
70
+
71
+ module IncludedYard
72
+ def foo; end
73
+ end
74
+
75
+ class FinalYard < SuperYard
76
+ include IncludedYard
77
+ end
70
78
  eof
71
79
  end
72
80
 
@@ -104,6 +112,12 @@ describe YARD::CodeObjects::ClassObject do
104
112
  meths.should include(P('MiddleYard#middle'))
105
113
  meths.should_not include(P('SuperYard#middle'))
106
114
  end
115
+
116
+ it "should show mixed in methods before superclass method" do
117
+ meths = P(:FinalYard).meths
118
+ meths.should include(P('IncludedYard#foo'))
119
+ meths.should_not include(P('SuperYard#foo'))
120
+ end
107
121
  end
108
122
 
109
123
  describe "#constants / #inherited_constants" do
@@ -115,4 +115,33 @@ describe YARD::CodeObjects::MethodObject do
115
115
  MethodObject.new(@yard, :initialize).constructor?.should be_false
116
116
  end
117
117
  end
118
+
119
+ describe '#overridden_method' do
120
+ before { Registry.clear }
121
+
122
+ it "should return overridden method from mixin first" do
123
+ YARD.parse_string(<<-eof)
124
+ module C; def foo; end end
125
+ class A; def foo; end end
126
+ class B < A; include C; def foo; end end
127
+ eof
128
+ Registry.at('B#foo').overridden_method.should == Registry.at('C#foo')
129
+ end
130
+
131
+ it "should return overridden method from superclass" do
132
+ YARD.parse_string(<<-eof)
133
+ class A; def foo; end end
134
+ class B < A; def foo; end end
135
+ eof
136
+ Registry.at('B#foo').overridden_method.should == Registry.at('A#foo')
137
+ end
138
+
139
+ it "should return nil if none is found" do
140
+ YARD.parse_string(<<-eof)
141
+ class A; end
142
+ class B < A; def foo; end end
143
+ eof
144
+ Registry.at('B#foo').overridden_method.should be_nil
145
+ end
146
+ end
118
147
  end
@@ -3,147 +3,168 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe YARD::CodeObjects::NamespaceObject do
4
4
  before { Registry.clear }
5
5
 
6
- it "should respond to #child with the object name passed in" do
7
- obj = NamespaceObject.new(nil, :YARD)
8
- other = NamespaceObject.new(obj, :Other)
9
- obj.child(:Other).should == other
10
- obj.child('Other').should == other
11
- end
12
-
13
- it "should respond to #child with hash of reader attributes with their response value" do
14
- obj = NamespaceObject.new(nil, :YARD)
15
- NamespaceObject.new(obj, :NotOther)
16
- other = NamespaceObject.new(obj, :Other)
17
- other.somevalue = 2
18
- obj.child(:somevalue => 2).should == other
19
- end
20
-
21
- it "should return #meths even if parent is a Proxy" do
22
- obj = NamespaceObject.new(P(:String), :YARD)
23
- obj.meths.should be_empty
24
- end
25
-
26
- it "should not list included methods that are already defined in the namespace using #meths" do
27
- a = ModuleObject.new(nil, :Mod1)
28
- ameth = MethodObject.new(a, :testing)
29
- b = ModuleObject.new(nil, :Mod2)
30
- bmeth = MethodObject.new(b, :foo)
31
- c = NamespaceObject.new(nil, :YARD)
32
- cmeth = MethodObject.new(c, :testing)
33
- cmeth2 = MethodObject.new(c, :foo)
34
- c.instance_mixins << a
35
- c.class_mixins << b
36
-
37
- meths = c.meths
38
- meths.should include(bmeth)
39
- meths.should include(cmeth)
40
- meths.should include(cmeth2)
41
- meths.should_not include(ameth)
42
-
43
- meths = c.included_meths
44
- meths.should include(bmeth)
45
- meths.should_not include(ameth)
46
- meths.should_not include(cmeth)
47
- meths.should_not include(cmeth2)
48
- end
6
+ describe '#child' do
7
+ it "should return the object matching the name passed in if argument is a Symbol" do
8
+ obj = NamespaceObject.new(nil, :YARD)
9
+ other = NamespaceObject.new(obj, :Other)
10
+ obj.child(:Other).should == other
11
+ obj.child('Other').should == other
12
+ end
49
13
 
50
- it "should list included_meths mixed into the class scope as class methods" do
51
- b = ModuleObject.new(nil, :Mod2)
52
- bmeth = MethodObject.new(b, :foo)
53
- bmeth2 = MethodObject.new(b, :foo2)
54
- c = NamespaceObject.new(nil, :YARD)
55
- c.class_mixins << b
56
-
57
- [bmeth, bmeth2].each {|o| o.scope.should == :instance }
58
- meths = c.included_meths(:scope => :class)
59
- meths.each {|o| o.scope.should == :class }
14
+ it "should look for attributes matching the object if the argument is a Hash" do
15
+ obj = NamespaceObject.new(nil, :YARD)
16
+ NamespaceObject.new(obj, :NotOther)
17
+ other = NamespaceObject.new(obj, :Other)
18
+ other.somevalue = 2
19
+ obj.child(:somevalue => 2).should == other
20
+ end
60
21
  end
61
22
 
62
- it "should not list methods overridden by another included module" do
63
- a = ModuleObject.new(nil, :Mod)
64
- ameth = MethodObject.new(a, :testing)
65
- b = ModuleObject.new(nil, :Mod2)
66
- bmeth = MethodObject.new(b, :testing)
67
- c = NamespaceObject.new(nil, :YARD)
68
- c.instance_mixins << a
69
- c.instance_mixins << b
70
- c.class_mixins << b
71
- c.class_mixins << a
72
-
73
- meths = c.included_meths(:scope => :instance)
74
- meths.should_not include(ameth)
75
- meths.should include(bmeth)
76
-
77
- meths = c.included_meths(:scope => :class)
78
- meths.should include(ameth)
79
- meths.should_not include(bmeth)
80
- end
81
-
82
- it "should list class attributes using #class_attributes" do
83
- a = NamespaceObject.new(nil, :Mod)
84
- a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
85
- a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
86
- a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
87
- a.class_attributes.keys.should include(:a)
88
- a.class_attributes.keys.should_not include(:b)
89
- end
90
-
91
- it "should list instance attributes using #instance attributes" do
92
- a = NamespaceObject.new(nil, :Mod)
93
- a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
94
- a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
95
- a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
96
- a.instance_attributes.keys.should include(:a)
97
- a.instance_attributes.keys.should include(:b)
23
+ describe '#meths' do
24
+ it "should return #meths even if parent is a Proxy" do
25
+ obj = NamespaceObject.new(P(:String), :YARD)
26
+ obj.meths.should be_empty
27
+ end
28
+
29
+ it "should not list included methods that are already defined in the namespace using #meths" do
30
+ a = ModuleObject.new(nil, :Mod1)
31
+ ameth = MethodObject.new(a, :testing)
32
+ b = ModuleObject.new(nil, :Mod2)
33
+ bmeth = MethodObject.new(b, :foo)
34
+ c = NamespaceObject.new(nil, :YARD)
35
+ cmeth = MethodObject.new(c, :testing)
36
+ cmeth2 = MethodObject.new(c, :foo)
37
+ c.instance_mixins << a
38
+ c.class_mixins << b
39
+
40
+ meths = c.meths
41
+ meths.should include(bmeth)
42
+ meths.should include(cmeth)
43
+ meths.should include(cmeth2)
44
+ meths.should_not include(ameth)
45
+
46
+ meths = c.included_meths
47
+ meths.should include(bmeth)
48
+ meths.should_not include(ameth)
49
+ meths.should_not include(cmeth)
50
+ meths.should_not include(cmeth2)
51
+ end
98
52
  end
99
- end
100
53
 
101
- describe YARD::CodeObjects::NamespaceObject, '#constants/#included_constants' do
102
- before do
103
- Registry.clear
104
-
105
- Parser::SourceParser.parse_string <<-eof
106
- module A
107
- CONST1 = 1
108
- CONST2 = 2
109
- end
110
-
111
- module B
112
- CONST2 = -2
113
- CONST3 = -3
114
- end
115
-
116
- class C
117
- CONST3 = 3
118
- CONST4 = 4
119
-
120
- include A
121
- include B
122
- end
123
- eof
54
+ describe '#included_meths' do
55
+ it "should list methods mixed into the class scope as class methods" do
56
+ b = ModuleObject.new(nil, :Mod2)
57
+ bmeth = MethodObject.new(b, :foo)
58
+ bmeth2 = MethodObject.new(b, :foo2)
59
+ c = NamespaceObject.new(nil, :YARD)
60
+ c.class_mixins << b
61
+
62
+ [bmeth, bmeth2].each {|o| o.scope.should == :instance }
63
+ meths = c.included_meths(:scope => :class)
64
+ meths.each {|o| o.scope.should == :class }
65
+ end
66
+
67
+ it "should not list methods overridden by another included module" do
68
+ a = ModuleObject.new(nil, :Mod)
69
+ ameth = MethodObject.new(a, :testing)
70
+ b = ModuleObject.new(nil, :Mod2)
71
+ bmeth = MethodObject.new(b, :testing)
72
+ c = NamespaceObject.new(nil, :YARD)
73
+ c.instance_mixins.unshift a
74
+ c.instance_mixins.unshift b
75
+ c.class_mixins.unshift b
76
+ c.class_mixins.unshift a
77
+
78
+ meths = c.included_meths(:scope => :instance)
79
+ meths.should_not include(ameth)
80
+ meths.should include(bmeth)
81
+
82
+ meths = c.included_meths(:scope => :class)
83
+ meths.should include(ameth)
84
+ meths.should_not include(bmeth)
85
+ end
124
86
  end
125
87
 
126
- it "should list all included constants by default" do
127
- consts = P(:C).constants
128
- consts.should include(P('A::CONST1'))
129
- consts.should include(P('C::CONST4'))
88
+ describe '#class_attributes' do
89
+ it "should list class attributes" do
90
+ a = NamespaceObject.new(nil, :Mod)
91
+ a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
92
+ a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
93
+ a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
94
+ a.class_attributes.keys.should include(:a)
95
+ a.class_attributes.keys.should_not include(:b)
96
+ end
130
97
  end
131
98
 
132
- it "should allow :included to be set to false to ignore included constants" do
133
- consts = P(:C).constants(:included => false)
134
- consts.should_not include(P('A::CONST1'))
135
- consts.should include(P('C::CONST4'))
99
+ describe '#instance_attributes' do
100
+ it "should list instance attributes" do
101
+ a = NamespaceObject.new(nil, :Mod)
102
+ a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
103
+ a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
104
+ a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
105
+ a.instance_attributes.keys.should include(:a)
106
+ a.instance_attributes.keys.should include(:b)
107
+ end
136
108
  end
137
109
 
138
- it "should not list an included constant if it is defined in the object" do
139
- consts = P(:C).constants
140
- consts.should include(P('C::CONST3'))
141
- consts.should_not include(P('B::CONST3'))
110
+ describe '#constants/#included_constants' do
111
+ before do
112
+ Registry.clear
113
+
114
+ YARD.parse_string <<-eof
115
+ module A
116
+ CONST1 = 1
117
+ CONST2 = 2
118
+ end
119
+
120
+ module B
121
+ CONST2 = -2
122
+ CONST3 = -3
123
+ end
124
+
125
+ class C
126
+ CONST3 = 3
127
+ CONST4 = 4
128
+
129
+ include A
130
+ include B
131
+ end
132
+ eof
133
+ end
134
+
135
+ it "should list all included constants by default" do
136
+ consts = P(:C).constants
137
+ consts.should include(P('A::CONST1'))
138
+ consts.should include(P('C::CONST4'))
139
+ end
140
+
141
+ it "should allow :included to be set to false to ignore included constants" do
142
+ consts = P(:C).constants(:included => false)
143
+ consts.should_not include(P('A::CONST1'))
144
+ consts.should include(P('C::CONST4'))
145
+ end
146
+
147
+ it "should not list an included constant if it is defined in the object" do
148
+ consts = P(:C).constants
149
+ consts.should include(P('C::CONST3'))
150
+ consts.should_not include(P('B::CONST3'))
151
+ end
152
+
153
+ it "should not list an included constant if it is shadowed by another included constant" do
154
+ consts = P(:C).included_constants
155
+ consts.should include(P('B::CONST2'))
156
+ consts.should_not include(P('A::CONST2'))
157
+ end
142
158
  end
143
159
 
144
- it "should not list an included constant if it is shadowed by another included constant" do
145
- consts = P(:C).included_constants
146
- consts.should include(P('B::CONST2'))
147
- consts.should_not include(P('A::CONST2'))
160
+ describe '#included_meths' do
161
+ it "should return all included methods with :all = true" do
162
+ YARD.parse_string <<-eof
163
+ module B; def foo; end end
164
+ module C; def bar; end end
165
+ class A; include B; include C; def foo; end; def bar; end end
166
+ eof
167
+ Registry.at('A').included_meths(:all => true).should == [P('C#bar'), P('B#foo')]
168
+ end
148
169
  end
149
170
  end