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.
- data/.yardopts +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- 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.
|
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
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
63
|
-
a
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|