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
@@ -5,29 +5,10 @@ describe Array do
5
5
  it "should create an Insertion object" do
6
6
  [].place('x').should be_kind_of(Insertion)
7
7
  end
8
- end
9
- end
10
-
11
- describe Insertion do
12
- describe '#before' do
13
- it "should place an object before another" do
14
- [1, 2].place(3).before(2).should == [1, 3, 2]
15
- [1, 2].place(3).before(1).should == [3, 1, 2]
16
- [1, [4], 2].place(3).before(2).should == [1, [4], 3, 2]
17
- end
18
- end
19
-
20
- describe '#after' do
21
- it "should place an object after another" do
22
- [1, 2].place(3).after(2).should == [1, 2, 3]
23
- end
24
-
25
- it "should place an object after another and its subsections" do
26
- [1, [2]].place(3).after(1).should == [1, [2], 3]
27
- end
28
-
29
- it "should not not ignore subsections if ignore_subections=false" do
30
- [1, [2]].place(3).after(1, false).should == [1, 3, [2]]
8
+
9
+ it "should allow multiple objects to be placed" do
10
+ [1, 2].place('x', 'y', 'z').before(2).should == [1, 'x', 'y', 'z', 2]
31
11
  end
32
12
  end
33
13
  end
14
+
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Insertion do
4
+ describe '#before' do
5
+ it "should place an object before another" do
6
+ [1, 2].place(3).before(2).should == [1, 3, 2]
7
+ [1, 2].place(3).before(1).should == [3, 1, 2]
8
+ [1, [4], 2].place(3).before(2).should == [1, [4], 3, 2]
9
+ end
10
+ end
11
+
12
+ describe '#after' do
13
+ it "should place an object after another" do
14
+ [1, 2].place(3).after(2).should == [1, 2, 3]
15
+ end
16
+
17
+ it "should no longer place an object after another and its subsections (0.6)" do
18
+ [1, [2]].place(3).after(1).should == [1, 3, [2]]
19
+ end
20
+
21
+ it "should place an array after an object" do
22
+ [1, 2, 3].place([4]).after(1).should == [1, [4], 2, 3]
23
+ end
24
+ end
25
+
26
+ describe '#before_any' do
27
+ it "should place an object before another anywhere inside list (including sublists)" do
28
+ [1, 2, [3]].place(4).before_any(3).should == [1, 2, [4, 3]]
29
+ end
30
+ end
31
+
32
+ describe '#after_any' do
33
+ it "should place an object after another anywhere inside list (including sublists)" do
34
+ [1, 2, [3]].place(4).after_any(3).should == [1, 2, [3, 4]]
35
+ end
36
+ end
37
+ end
@@ -9,6 +9,26 @@ describe YARD::Docstring do
9
9
  end
10
10
  end
11
11
 
12
+ describe '#+' do
13
+ it "should add another Docstring" do
14
+ d = Docstring.new("FOO") + Docstring.new("BAR")
15
+ d.should == "FOO\nBAR"
16
+ end
17
+
18
+ it "should copy over tags" do
19
+ d1 = Docstring.new("FOO\n@api private\n")
20
+ d2 = Docstring.new("BAR\n@param foo descr")
21
+ d = (d1 + d2)
22
+ d.should have_tag(:api)
23
+ d.should have_tag(:param)
24
+ end
25
+
26
+ it "should add a String" do
27
+ d = Docstring.new("FOO") + "BAR"
28
+ d.should == "FOOBAR"
29
+ end
30
+ end
31
+
12
32
  describe '#summary' do
13
33
  it "should handle empty docstrings" do
14
34
  o1 = Docstring.new
@@ -134,6 +154,10 @@ describe YARD::Docstring do
134
154
  end
135
155
 
136
156
  describe '#empty?/#blank?' do
157
+ before(:all) do
158
+ Tags::Library.define_tag "Invisible", :invisible_tag
159
+ end
160
+
137
161
  it "should be blank and empty if it has no content and no tags" do
138
162
  Docstring.new.should be_blank
139
163
  Docstring.new.should be_empty
@@ -158,6 +182,17 @@ describe YARD::Docstring do
158
182
  d.should be_empty
159
183
  d.should_not be_blank
160
184
  end
185
+
186
+ it "should be blank if it has no visible tags" do
187
+ d = Docstring.new("@invisible_tag value")
188
+ d.should be_blank
189
+ end
190
+
191
+ it "should not be blank if it has invisible tags and only_visible_tags = false" do
192
+ d = Docstring.new("@invisible_tag value")
193
+ d.add_tag Tags::Tag.new('invisible_tag', nil, nil)
194
+ d.blank?(false).should == false
195
+ end
161
196
  end
162
197
 
163
198
  describe '#add_tag' do
@@ -238,5 +273,33 @@ eof
238
273
  eof
239
274
  doc.tag(:param).text.should == "some value\nfoo bar\n baz"
240
275
  end
276
+
277
+ it "should allow numbers in tags" do
278
+ Tags::Library.define_tag(nil, :foo1)
279
+ Tags::Library.define_tag(nil, :foo2)
280
+ Tags::Library.define_tag(nil, :foo3)
281
+ doc = Docstring.new(<<-eof)
282
+ @foo1 bar1
283
+ @foo2 bar2
284
+ @foo3 bar3
285
+ eof
286
+ doc.tag(:foo1).text.should == "bar1"
287
+ doc.tag(:foo2).text.should == "bar2"
288
+ end
289
+
290
+ it "should end tag on newline if next line is not indented" do
291
+ doc = Docstring.new(<<-eof)
292
+ @author bar1
293
+ @api bar2
294
+ Hello world
295
+ eof
296
+ doc.tag(:author).text.should == "bar1"
297
+ doc.tag(:api).text.should == "bar2"
298
+ end
299
+
300
+ it "should warn about unknown tag" do
301
+ log.should_receive(:warn).with(/Unknown tag @hello$/)
302
+ Docstring.new("@hello world")
303
+ end
241
304
  end
242
305
  end
@@ -87,4 +87,8 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AttributeHandler" do
87
87
  it "should add existing writer method as part of attr_reader combo" do
88
88
  Registry.at('C#foo').attr_info[:write].should == Registry.at('C#foo=')
89
89
  end
90
+
91
+ it "should maintain visibility for attr_reader" do
92
+ Registry.at('D#parser').visibility.should == :protected
93
+ end
90
94
  end
@@ -2,38 +2,110 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  include Parser
4
4
 
5
- describe YARD::Handlers::Base, "#handles and inheritance" do
6
- before do
7
- Handlers::Base.stub!(:inherited)
8
- end
9
-
10
- it "should keep track of subclasses" do
11
- Handlers::Base.should_receive(:inherited).once
12
- class TestHandler < Handlers::Base; end
13
- end
5
+ describe YARD::Handlers::Base do
6
+ describe "#handles and inheritance" do
7
+ before do
8
+ Handlers::Base.stub!(:inherited)
9
+ end
14
10
 
15
- it "should raise NotImplementedError if process is called on a class with no #process" do
16
- class TestNotImplementedHandler < Handlers::Base
11
+ it "should keep track of subclasses" do
12
+ Handlers::Base.should_receive(:inherited).once
13
+ class TestHandler < Handlers::Base; end
17
14
  end
15
+
16
+ it "should raise NotImplementedError if process is called on a class with no #process" do
17
+ class TestNotImplementedHandler < Handlers::Base
18
+ end
18
19
 
19
- lambda { TestNotImplementedHandler.new(0, 0).process }.should raise_error(NotImplementedError)
20
+ lambda { TestNotImplementedHandler.new(0, 0).process }.should raise_error(NotImplementedError)
21
+ end
22
+
23
+ it "should allow multiple handles arguments" do
24
+ Handlers::Base.should_receive(:inherited).once
25
+ class TestHandler1 < Handlers::Base
26
+ handles :a, :b, :c
27
+ end
28
+ TestHandler1.handlers.should == [:a, :b, :c]
29
+ end
30
+
31
+ it "should allow multiple handles calls" do
32
+ Handlers::Base.should_receive(:inherited).once
33
+ class TestHandler2 < Handlers::Base
34
+ handles :a
35
+ handles :b
36
+ handles :c
37
+ end
38
+ TestHandler2.handlers.should == [:a, :b, :c]
39
+ end
20
40
  end
21
41
 
22
- it "should allow multiple handles arguments" do
23
- Handlers::Base.should_receive(:inherited).once
24
- class TestHandler1 < Handlers::Base
25
- handles :a, :b, :c
42
+ describe 'transitive tags' do
43
+ it "should add transitive tags to children" do
44
+ Registry.clear
45
+ YARD.parse_string <<-eof
46
+ # @since 1.0
47
+ # @author Foo
48
+ class A
49
+ def foo; end
50
+ # @since 1.1
51
+ def bar; end
52
+ end
53
+ eof
54
+ Registry.at('A').tag(:since).text.should == "1.0"
55
+ Registry.at('A#foo').tag(:since).text.should == "1.0"
56
+ Registry.at('A#bar').tag(:since).text.should == "1.1"
57
+ Registry.at('A#bar').tag(:author).should be_nil
26
58
  end
27
- TestHandler1.handlers.should == [:a, :b, :c]
28
59
  end
29
-
30
- it "should allow multiple handles calls" do
31
- Handlers::Base.should_receive(:inherited).once
32
- class TestHandler2 < Handlers::Base
33
- handles :a
34
- handles :b
35
- handles :c
36
- end
37
- TestHandler2.handlers.should == [:a, :b, :c]
60
+
61
+ describe '#push_state' do
62
+ def process(klass)
63
+ state = OpenStruct.new(:namespace => "ROOT", :scope => :instance, :owner => "ROOT")
64
+ klass.new(state, nil).process
65
+ end
66
+
67
+ it "should push and return all old state info after block" do
68
+ class PushStateHandler1 < Handlers::Base
69
+ def process
70
+ push_state(:namespace => "FOO", :scope => :class, :owner => "BAR") do
71
+ namespace.should == "FOO"
72
+ scope.should == :class
73
+ owner.should == "BAR"
74
+ end
75
+ namespace.should == "ROOT"
76
+ owner.should == "ROOT"
77
+ scope.should == :instance
78
+ end
79
+ end
80
+ process PushStateHandler1
81
+ end
82
+
83
+ it "should allow owner to be pushed individually" do
84
+ class PushStateHandler2 < Handlers::Base
85
+ def process
86
+ push_state(:owner => "BAR") do
87
+ namespace.should == "ROOT"
88
+ scope.should == :instance
89
+ owner.should == "BAR"
90
+ end
91
+ owner.should == "ROOT"
92
+ end
93
+ end
94
+ process PushStateHandler2
95
+ end
96
+
97
+ it "should allow scope to be pushed individually" do
98
+ class PushStateHandler3 < Handlers::Base
99
+ def process
100
+ push_state(:scope => :foo) do
101
+ namespace.should == "ROOT"
102
+ scope.should == :foo
103
+ owner.should == "ROOT"
104
+ end
105
+ scope.should == :instance
106
+ end
107
+ end
108
+ process PushStateHandler3
109
+ end
38
110
  end
39
111
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
4
4
  before(:all) { parse_file :class_handler_001, __FILE__ }
@@ -230,4 +230,8 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
230
230
  Registry.at("SemiDoccedStruct#fourth=").docstring.should == "sets the proc that writes stuff"
231
231
  end
232
232
 
233
+ it "should inherit from a regular struct" do
234
+ Registry.at('RegularStruct').superclass.should == P(:Struct)
235
+ Registry.at('RegularStruct2').superclass.should == P(:Struct)
236
+ end
233
237
  end
@@ -24,4 +24,9 @@ class C
24
24
 
25
25
  def bar=(value); end
26
26
  attr_reader :bar
27
+ end
28
+
29
+ class D
30
+ protected
31
+ attr_reader :parser
27
32
  end
@@ -83,6 +83,10 @@ end
83
83
  class Zebra
84
84
  end
85
85
 
86
+ # A simple struct
87
+ class RegularStruct < Struct; end
88
+ class RegularStruct2 < ::Struct; end
89
+
86
90
  class Point < Struct.new(:x, :y, :z)
87
91
  end
88
92
 
@@ -17,4 +17,9 @@ end
17
17
 
18
18
  module ::Kernel
19
19
  def x; end
20
- end
20
+ end
21
+
22
+ module A; end
23
+ module B; end
24
+ module C; end
25
+ class D; include A; include B; include C; end
@@ -17,4 +17,8 @@ class Testing
17
17
  def pub2; end
18
18
 
19
19
  protected :notpriv, 'notpriv2', :notpriv?
20
+
21
+ private name
22
+ private *argument
23
+ private *(method_call)
20
24
  end
@@ -122,4 +122,9 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodHandler" do
122
122
  meth.tag(:param).name.should == "opts"
123
123
  meth.tag(:param).types.should == ["Hash"]
124
124
  end
125
+
126
+ it "should raise an undocumentable error when a method is defined on an object instance" do
127
+ undoc_error "error = Foo; def error.at(foo) end"
128
+ Registry.at('error').should be_nil
129
+ end
125
130
  end
@@ -23,4 +23,8 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ModuleHandler" do
23
23
  it "should handle modules in the form ::ModName" do
24
24
  Registry.at("Kernel").should_not be_nil
25
25
  end
26
+
27
+ it "should list mixins in proper order" do
28
+ Registry.at('D').mixins.should == [P(:C), P(:B), P(:A)]
29
+ end
26
30
  end
@@ -21,4 +21,10 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}VisibilityHandler" do
21
21
  Registry['Testing#notpriv2'].visibility.should == :protected
22
22
  Registry['Testing#notpriv?'].visibility.should == :protected
23
23
  end
24
+
25
+ it "should only accept strings and symbols" do
26
+ Registry.at('Testing#name').should be_nil
27
+ Registry.at('Testing#argument').should be_nil
28
+ Registry.at('Testing#method_call').should be_nil
29
+ end
24
30
  end
@@ -244,5 +244,29 @@ describe YARD::Parser::SourceParser do
244
244
  YARD::Parser::SourceParser.parse_string("$$$", :ruby)
245
245
  end
246
246
  end
247
+
248
+ it "should handle groups" do
249
+ Registry.clear
250
+ YARD.parse_string <<-eof
251
+ class A
252
+ # @group Group Name
253
+ def foo; end
254
+ def foo2; end
255
+
256
+ # @endgroup
257
+
258
+ def bar; end
259
+
260
+ # @group Group 2
261
+ def baz; end
262
+ end
263
+ eof
264
+
265
+ Registry.at('A').groups.should == ['Group Name', 'Group 2']
266
+ Registry.at('A#bar').group.should be_nil
267
+ Registry.at('A#foo').group.should == "Group Name"
268
+ Registry.at('A#foo2').group.should == "Group Name"
269
+ Registry.at('A#baz').group.should == "Group 2"
270
+ end
247
271
  end
248
272
  end
@@ -73,13 +73,13 @@ describe YARD::Registry do
73
73
  end
74
74
  end
75
75
 
76
- describe '#root' do
76
+ describe '.root' do
77
77
  it "should have an empty path for root" do
78
78
  Registry.root.path.should == ""
79
79
  end
80
80
  end
81
81
 
82
- describe '#resolve' do
82
+ describe '.resolve' do
83
83
  it "should resolve any existing namespace" do
84
84
  o1 = ModuleObject.new(:root, :A)
85
85
  o2 = ModuleObject.new(o1, :B)
@@ -139,18 +139,18 @@ describe YARD::Registry do
139
139
  end
140
140
 
141
141
  it "should only check 'Path' in lookup on root namespace" do
142
- Registry.instance.should_receive(:at).once.with('Test').and_return(true)
142
+ Registry.should_receive(:at).once.with('Test').and_return(true)
143
143
  Registry.resolve(Registry.root, "Test")
144
144
  end
145
145
 
146
146
  it "should not perform lookup by joining namespace and name without separator" do
147
147
  yard = ClassObject.new(:root, :YARD)
148
- Registry.instance.should_not_receive(:at).with('YARDB')
148
+ Registry.should_not_receive(:at).with('YARDB')
149
149
  Registry.resolve(yard, 'B')
150
150
  end
151
151
  end
152
152
 
153
- describe '#all' do
153
+ describe '.all' do
154
154
  it "should return objects of types specified by arguments" do
155
155
  ModuleObject.new(:root, :A)
156
156
  o1 = ClassObject.new(:root, :B)
@@ -167,7 +167,7 @@ describe YARD::Registry do
167
167
  r.should include(o1, o2)
168
168
  end
169
169
 
170
- it "should allow #all to omit list" do
170
+ it "should allow .all to omit list" do
171
171
  o1 = ModuleObject.new(:root, :A)
172
172
  o2 = ClassObject.new(:root, :B)
173
173
  r = Registry.all
@@ -175,7 +175,7 @@ describe YARD::Registry do
175
175
  end
176
176
  end
177
177
 
178
- describe '#paths' do
178
+ describe '.paths' do
179
179
  it "should return all object paths" do
180
180
  o1 = ModuleObject.new(:root, :A)
181
181
  o2 = ClassObject.new(:root, :B)
@@ -183,7 +183,7 @@ describe YARD::Registry do
183
183
  end
184
184
  end
185
185
 
186
- describe '#load_yardoc' do
186
+ describe '.load_yardoc' do
187
187
  it "should delegate load to RegistryStore" do
188
188
  store = RegistryStore.new
189
189
  store.should_receive(:load).with('foo')
@@ -192,6 +192,10 @@ describe YARD::Registry do
192
192
  Registry.load_yardoc
193
193
  end
194
194
 
195
+ it "should return itself" do
196
+ Registry.load_yardoc.should == Registry
197
+ end
198
+
195
199
  it "should maintain hash key equality on loaded objects" do
196
200
  Registry.clear
197
201
  Registry.load!(File.dirname(__FILE__) + '/serializers/data/serialized_yardoc')
@@ -200,4 +204,36 @@ describe YARD::Registry do
200
204
  Registry.at('Foo').aliases.has_key?(baz).should == true
201
205
  end
202
206
  end
207
+
208
+ ['load', 'load_all', 'load!'].each do |meth|
209
+ describe('.' + meth) do
210
+ it "should return itself" do
211
+ Registry.send(meth).should == Registry
212
+ end
213
+ end
214
+ end
215
+
216
+ describe '.each' do
217
+ before do
218
+ YARD.parse_string "def a; end; def b; end; def c; end"
219
+ end
220
+
221
+ after { Registry.clear }
222
+
223
+ it "should iterate over .all" do
224
+ items = []
225
+ Registry.each {|x| items << x.path }
226
+ items.sort.should == ['#a', '#b', '#c']
227
+ end
228
+
229
+ it "should include Enumerable and allow for find, select" do
230
+ Registry.find {|x| x.path == "#a" }.should be_a(CodeObjects::MethodObject)
231
+ end
232
+ end
233
+
234
+ describe '.instance' do
235
+ it "should return itself" do
236
+ Registry.instance.should == Registry
237
+ end
238
+ end
203
239
  end