yard 0.8.7.6 → 0.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/LICENSE +2 -2
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/bin/yard +0 -0
- data/bin/yardoc +0 -0
- data/bin/yri +0 -0
- data/docs/GettingStarted.md +88 -6
- data/docs/images/handlers-class-diagram.png +0 -0
- data/docs/images/overview-class-diagram.png +0 -0
- data/docs/images/parser-class-diagram.png +0 -0
- data/docs/templates/default/fulldoc/html/full_list_tag.erb +6 -4
- data/lib/yard/autoload.rb +3 -0
- data/lib/yard/cli/yardoc.rb +1 -1
- data/lib/yard/code_objects/base.rb +4 -1
- data/lib/yard/code_objects/extra_file_object.rb +3 -1
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/docstring.rb +11 -6
- data/lib/yard/handlers/base.rb +1 -2
- data/lib/yard/handlers/c/base.rb +19 -0
- data/lib/yard/handlers/c/handler_methods.rb +42 -8
- data/lib/yard/handlers/c/init_handler.rb +1 -1
- data/lib/yard/handlers/c/method_handler.rb +3 -3
- data/lib/yard/handlers/ruby/decorator_handler_methods.rb +132 -0
- data/lib/yard/handlers/ruby/legacy/private_class_method_handler.rb +1 -1
- data/lib/yard/handlers/ruby/private_class_method_handler.rb +6 -39
- data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -30
- data/lib/yard/handlers/ruby/public_class_method_handler.rb +13 -0
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +1 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +5 -8
- data/lib/yard/logging.rb +1 -0
- data/lib/yard/parser/ruby/ruby_parser.rb +2 -2
- data/lib/yard/parser/source_parser.rb +6 -6
- data/lib/yard/rake/yardoc_task.rb +2 -2
- data/lib/yard/serializers/file_system_serializer.rb +33 -1
- data/lib/yard/server/commands/display_file_command.rb +8 -3
- data/lib/yard/server/commands/display_object_command.rb +7 -3
- data/lib/yard/server/doc_server_helper.rb +2 -8
- data/lib/yard/server/doc_server_serializer.rb +2 -4
- data/lib/yard/server/router.rb +1 -1
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +57 -8
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -10
- data/lib/yard/server/templates/default/layout/html/script_setup.erb +1 -2
- data/lib/yard/server/templates/default/method_details/html/permalink.erb +3 -3
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +4 -4
- data/lib/yard/tags/directives.rb +1 -0
- data/lib/yard/tags/library.rb +9 -7
- data/lib/yard/tags/overload_tag.rb +4 -1
- data/lib/yard/templates/helpers/html_helper.rb +4 -3
- data/lib/yard/templates/template_options.rb +3 -0
- data/lib/yard/version.rb +1 -1
- data/spec/cli/command_parser_spec.rb +14 -14
- data/spec/cli/command_spec.rb +11 -11
- data/spec/cli/config_spec.rb +32 -32
- data/spec/cli/diff_spec.rb +86 -90
- data/spec/cli/display_spec.rb +6 -6
- data/spec/cli/gems_spec.rb +28 -28
- data/spec/cli/graph_spec.rb +8 -8
- data/spec/cli/help_spec.rb +8 -8
- data/spec/cli/i18n_spec.rb +33 -37
- data/spec/cli/list_spec.rb +2 -2
- data/spec/cli/markup_types_spec.rb +3 -3
- data/spec/cli/server_spec.rb +74 -88
- data/spec/cli/stats_spec.rb +14 -14
- data/spec/cli/yardoc_spec.rb +316 -321
- data/spec/cli/yri_spec.rb +45 -45
- data/spec/code_objects/base_spec.rb +174 -173
- data/spec/code_objects/class_object_spec.rb +65 -65
- data/spec/code_objects/code_object_list_spec.rb +13 -11
- data/spec/code_objects/constants_spec.rb +68 -58
- data/spec/code_objects/extra_file_object_spec.rb +71 -59
- data/spec/code_objects/macro_object_spec.rb +64 -64
- data/spec/code_objects/method_object_spec.rb +80 -72
- data/spec/code_objects/module_object_spec.rb +47 -47
- data/spec/code_objects/namespace_object_spec.rb +51 -51
- data/spec/code_objects/proxy_spec.rb +54 -54
- data/spec/config_spec.rb +104 -104
- data/spec/core_ext/array_spec.rb +5 -5
- data/spec/core_ext/file_spec.rb +33 -33
- data/spec/core_ext/hash_spec.rb +5 -5
- data/spec/core_ext/insertion_spec.rb +18 -18
- data/spec/core_ext/module_spec.rb +6 -6
- data/spec/core_ext/string_spec.rb +17 -17
- data/spec/core_ext/symbol_hash_spec.rb +42 -39
- data/spec/docstring_parser_spec.rb +65 -65
- data/spec/docstring_spec.rb +137 -130
- data/spec/handlers/alias_handler_spec.rb +39 -39
- data/spec/handlers/attribute_handler_spec.rb +35 -35
- data/spec/handlers/base_spec.rb +60 -51
- data/spec/handlers/c/alias_handler_spec.rb +6 -6
- data/spec/handlers/c/attribute_handler_spec.rb +12 -12
- data/spec/handlers/c/class_handler_spec.rb +35 -22
- data/spec/handlers/c/constant_handler_spec.rb +24 -22
- data/spec/handlers/c/init_handler_spec.rb +10 -10
- data/spec/handlers/c/method_handler_spec.rb +150 -65
- data/spec/handlers/c/mixin_handler_spec.rb +5 -5
- data/spec/handlers/c/module_handler_spec.rb +27 -15
- data/spec/handlers/c/override_comment_handler_spec.rb +14 -14
- data/spec/handlers/c/path_handler_spec.rb +8 -8
- data/spec/handlers/c/spec_helper.rb +10 -0
- data/spec/handlers/c/struct_handler_spec.rb +3 -3
- data/spec/handlers/class_condition_handler_spec.rb +18 -18
- data/spec/handlers/class_handler_spec.rb +97 -97
- data/spec/handlers/class_method_handler_shared_examples.rb +132 -0
- data/spec/handlers/class_variable_handler_spec.rb +3 -3
- data/spec/handlers/constant_handler_spec.rb +32 -29
- data/spec/handlers/decorator_handler_methods_spec.rb +405 -0
- data/spec/handlers/dsl_handler_spec.rb +108 -109
- data/spec/handlers/examples/constant_handler_001.rb.txt +4 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/exception_handler_spec.rb +23 -23
- data/spec/handlers/extend_handler_spec.rb +9 -9
- data/spec/handlers/legacy_base_spec.rb +60 -60
- data/spec/handlers/method_condition_handler_spec.rb +5 -5
- data/spec/handlers/method_handler_spec.rb +92 -92
- data/spec/handlers/mixin_handler_spec.rb +25 -25
- data/spec/handlers/module_function_handler_spec.rb +24 -24
- data/spec/handlers/module_handler_spec.rb +15 -15
- data/spec/handlers/private_class_method_handler_spec.rb +4 -48
- data/spec/handlers/private_constant_handler_spec.rb +8 -8
- data/spec/handlers/processor_spec.rb +12 -12
- data/spec/handlers/public_class_method_handler_spec.rb +10 -0
- data/spec/handlers/ruby/base_spec.rb +16 -16
- data/spec/handlers/ruby/legacy/base_spec.rb +20 -18
- data/spec/handlers/spec_helper.rb +1 -1
- data/spec/handlers/visibility_handler_spec.rb +25 -21
- data/spec/handlers/yield_handler_spec.rb +28 -28
- data/spec/i18n/locale_spec.rb +16 -16
- data/spec/i18n/message_spec.rb +8 -8
- data/spec/i18n/messages_spec.rb +14 -14
- data/spec/i18n/pot_generator_spec.rb +32 -32
- data/spec/i18n/text_spec.rb +22 -22
- data/spec/logging_spec.rb +12 -12
- data/spec/options_spec.rb +56 -56
- data/spec/parser/base_spec.rb +9 -9
- data/spec/parser/c_parser_spec.rb +50 -50
- data/spec/parser/ruby/ast_node_spec.rb +7 -7
- data/spec/parser/ruby/legacy/statement_list_spec.rb +106 -106
- data/spec/parser/ruby/legacy/token_list_spec.rb +27 -27
- data/spec/parser/ruby/ruby_parser_spec.rb +123 -113
- data/spec/parser/source_parser_spec.rb +224 -224
- data/spec/parser/tag_parsing_spec.rb +6 -7
- data/spec/rake/yardoc_task_spec.rb +38 -48
- data/spec/registry_spec.rb +143 -143
- data/spec/registry_store_spec.rb +165 -165
- data/spec/rubygems/doc_manager_spec.rb +38 -38
- data/spec/serializers/file_system_serializer_spec.rb +53 -33
- data/spec/serializers/yardoc_serializer_spec.rb +15 -15
- data/spec/server/adapter_spec.rb +15 -15
- data/spec/server/commands/base_spec.rb +29 -29
- data/spec/server/commands/library_command_spec.rb +12 -12
- data/spec/server/commands/static_file_command_spec.rb +28 -28
- data/spec/server/doc_server_helper_spec.rb +8 -8
- data/spec/server/doc_server_serializer_spec.rb +23 -18
- data/spec/server/rack_adapter_spec.rb +6 -6
- data/spec/server/router_spec.rb +39 -39
- data/spec/server/static_caching_spec.rb +16 -16
- data/spec/server/webrick_servlet_spec.rb +6 -7
- data/spec/server_spec.rb +3 -3
- data/spec/spec_helper.rb +11 -2
- data/spec/tags/default_factory_spec.rb +64 -64
- data/spec/tags/default_tag_spec.rb +5 -5
- data/spec/tags/directives_spec.rb +121 -121
- data/spec/tags/library_spec.rb +14 -14
- data/spec/tags/overload_tag_spec.rb +24 -24
- data/spec/tags/ref_tag_list_spec.rb +12 -12
- data/spec/templates/class_spec.rb +3 -3
- data/spec/templates/constant_spec.rb +4 -4
- data/spec/templates/engine_spec.rb +47 -48
- data/spec/templates/examples/class001.html +129 -101
- data/spec/templates/examples/class002.html +31 -27
- data/spec/templates/examples/method001.html +54 -47
- data/spec/templates/examples/method002.html +33 -28
- data/spec/templates/examples/method003.html +70 -64
- data/spec/templates/examples/method004.html +13 -9
- data/spec/templates/examples/method005.html +38 -32
- data/spec/templates/examples/module001.html +343 -339
- data/spec/templates/examples/module002.html +147 -124
- data/spec/templates/examples/module003.html +94 -81
- data/spec/templates/examples/module004.html +40 -33
- data/spec/templates/helpers/base_helper_spec.rb +91 -95
- data/spec/templates/helpers/html_helper_spec.rb +276 -279
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +16 -15
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +27 -34
- data/spec/templates/helpers/markup_helper_spec.rb +57 -57
- data/spec/templates/helpers/method_helper_spec.rb +20 -20
- data/spec/templates/helpers/shared_signature_examples.rb +33 -31
- data/spec/templates/helpers/text_helper_spec.rb +6 -6
- data/spec/templates/method_spec.rb +7 -7
- data/spec/templates/module_spec.rb +7 -7
- data/spec/templates/onefile_spec.rb +7 -7
- data/spec/templates/section_spec.rb +66 -69
- data/spec/templates/spec_helper.rb +1 -1
- data/spec/templates/tag_spec.rb +5 -5
- data/spec/templates/template_spec.rb +158 -158
- data/spec/verifier_spec.rb +52 -52
- data/templates/default/fulldoc/html/css/full_list.css +32 -31
- data/templates/default/fulldoc/html/css/style.css +212 -77
- data/templates/default/fulldoc/html/frames.erb +6 -15
- data/templates/default/fulldoc/html/full_list.erb +14 -21
- data/templates/default/fulldoc/html/full_list_class.erb +1 -1
- data/templates/default/fulldoc/html/full_list_file.erb +6 -4
- data/templates/default/fulldoc/html/full_list_method.erb +8 -6
- data/templates/default/fulldoc/html/js/app.js +100 -76
- data/templates/default/fulldoc/html/js/full_list.js +170 -135
- data/templates/default/fulldoc/html/setup.rb +50 -7
- data/templates/default/layout/html/breadcrumb.erb +0 -2
- data/templates/default/layout/html/headers.erb +2 -1
- data/templates/default/layout/html/layout.erb +16 -10
- data/templates/default/layout/html/script_setup.erb +1 -2
- data/templates/default/layout/html/search.erb +7 -2
- data/templates/default/layout/html/setup.rb +16 -0
- data/templates/default/method/html/header.erb +7 -6
- data/templates/default/module/html/attribute_summary.erb +1 -1
- data/templates/default/module/html/box_info.erb +24 -18
- data/templates/default/module/html/constant_summary.erb +9 -11
- data/templates/default/module/html/item_summary.erb +1 -1
- data/templates/default/module/html/method_summary.erb +1 -1
- data/templates/guide/fulldoc/html/setup.rb +1 -1
- data/yard.gemspec +1 -2
- metadata +10 -7
- data/spec/handlers/examples/private_class_method_handler_001.rb.txt +0 -9
- data/spec/handlers/examples/private_class_method_handler_002.rb.txt +0 -18
- data/spec/handlers/examples/private_class_method_handler_003.rb.txt +0 -11
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe YARD::CodeObjects::ClassObject do
|
4
|
-
describe
|
4
|
+
describe "#inheritance_tree" do
|
5
5
|
before(:all) do
|
6
6
|
Registry.clear
|
7
7
|
@mixin = ModuleObject.new(:root, :SomeMixin)
|
@@ -19,28 +19,28 @@ describe YARD::CodeObjects::ClassObject do
|
|
19
19
|
@yard.instance_mixins << @mixin
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
23
|
-
@yard.inheritance_tree.
|
22
|
+
it "shows the proper inheritance tree" do
|
23
|
+
expect(@yard.inheritance_tree).to eq [@yard, @superyard, P(:String)]
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
27
|
-
@yard.inheritance_tree(true).
|
26
|
+
it "shows proper inheritance tree when mixins are included" do
|
27
|
+
expect(@yard.inheritance_tree(true)).to eq [@yard, @mixin, @superyard, @mixin4, @mixin2, @mixin3, P(:String)]
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "does not modify the object's mixin list when mixins are included" do
|
31
31
|
@class1 = ClassObject.new(:root, :A)
|
32
32
|
@class2 = ClassObject.new(:root, :B)
|
33
33
|
@class2.superclass = @class1
|
34
34
|
|
35
35
|
@class2.inheritance_tree(true)
|
36
|
-
@class2.mixins.
|
36
|
+
expect(@class2.mixins).to eq []
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "lists class mixins in inheritance tree" do
|
40
40
|
mod = ModuleObject.new(:root, :ClassMethods)
|
41
41
|
klass = ClassObject.new(:root, :ReceivingClass)
|
42
42
|
klass.class_mixins << mod
|
43
|
-
klass.inheritance_tree(true).
|
43
|
+
expect(klass.inheritance_tree(true)).to eq [klass, mod]
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -78,45 +78,45 @@ describe YARD::CodeObjects::ClassObject do
|
|
78
78
|
eof
|
79
79
|
end
|
80
80
|
|
81
|
-
it "
|
81
|
+
it "shows inherited methods by default" do
|
82
82
|
meths = P(:YARD).meths
|
83
|
-
meths.
|
84
|
-
meths.
|
85
|
-
meths.
|
86
|
-
meths.
|
83
|
+
expect(meths).to include(P("YARD#mymethod"))
|
84
|
+
expect(meths).to include(P("SuperYard#foo"))
|
85
|
+
expect(meths).to include(P("SuperYard#foo2"))
|
86
|
+
expect(meths).to include(P("SuperYard.bar"))
|
87
87
|
end
|
88
88
|
|
89
|
-
it "
|
89
|
+
it "allows :inherited to be set to false" do
|
90
90
|
meths = P(:YARD).meths(:inherited => false)
|
91
|
-
meths.
|
92
|
-
meths.
|
93
|
-
meths.
|
94
|
-
meths.
|
91
|
+
expect(meths).to include(P("YARD#mymethod"))
|
92
|
+
expect(meths).not_to include(P("SuperYard#foo"))
|
93
|
+
expect(meths).not_to include(P("SuperYard#foo2"))
|
94
|
+
expect(meths).not_to include(P("SuperYard.bar"))
|
95
95
|
end
|
96
96
|
|
97
|
-
it "
|
97
|
+
it "does not show overridden methods" do
|
98
98
|
meths = P(:YARD).meths
|
99
|
-
meths.
|
100
|
-
meths.
|
99
|
+
expect(meths).to include(P("YARD#bar"))
|
100
|
+
expect(meths).not_to include(P("SuperYard#bar"))
|
101
101
|
|
102
102
|
meths = P(:YARD).inherited_meths
|
103
|
-
meths.
|
104
|
-
meths.
|
105
|
-
meths.
|
106
|
-
meths.
|
107
|
-
meths.
|
103
|
+
expect(meths).not_to include(P("YARD#bar"))
|
104
|
+
expect(meths).not_to include(P("YARD#mymethod"))
|
105
|
+
expect(meths).to include(P("SuperYard#foo"))
|
106
|
+
expect(meths).to include(P("SuperYard#foo2"))
|
107
|
+
expect(meths).to include(P("SuperYard.bar"))
|
108
108
|
end
|
109
109
|
|
110
|
-
it "
|
110
|
+
it "does not show inherited methods overridden by other subclasses" do
|
111
111
|
meths = P(:YARD).inherited_meths
|
112
|
-
meths.
|
113
|
-
meths.
|
112
|
+
expect(meths).to include(P('MiddleYard#middle'))
|
113
|
+
expect(meths).not_to include(P('SuperYard#middle'))
|
114
114
|
end
|
115
115
|
|
116
|
-
it "
|
116
|
+
it "shows mixed in methods before superclass method" do
|
117
117
|
meths = P(:FinalYard).meths
|
118
|
-
meths.
|
119
|
-
meths.
|
118
|
+
expect(meths).to include(P('IncludedYard#foo'))
|
119
|
+
expect(meths).not_to include(P('SuperYard#foo'))
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -142,55 +142,55 @@ describe YARD::CodeObjects::ClassObject do
|
|
142
142
|
eof
|
143
143
|
end
|
144
144
|
|
145
|
-
it "
|
145
|
+
it "lists inherited constants by default" do
|
146
146
|
consts = P(:SubYard).constants
|
147
|
-
consts.
|
148
|
-
consts.
|
147
|
+
expect(consts).to include(P("YARD::CONST1"))
|
148
|
+
expect(consts).to include(P("SubYard::CONST3"))
|
149
149
|
|
150
150
|
consts = P(:SubYard).inherited_constants
|
151
|
-
consts.
|
152
|
-
consts.
|
153
|
-
consts.
|
154
|
-
consts.
|
151
|
+
expect(consts).to include(P("YARD::CONST1"))
|
152
|
+
expect(consts).not_to include(P("YARD::CONST2"))
|
153
|
+
expect(consts).not_to include(P("SubYard::CONST2"))
|
154
|
+
expect(consts).not_to include(P("SubYard::CONST3"))
|
155
155
|
end
|
156
156
|
|
157
|
-
it "
|
157
|
+
it "does not list inherited constants if turned off" do
|
158
158
|
consts = P(:SubYard).constants(:inherited => false)
|
159
|
-
consts.
|
160
|
-
consts.
|
159
|
+
expect(consts).not_to include(P("YARD::CONST1"))
|
160
|
+
expect(consts).to include(P("SubYard::CONST3"))
|
161
161
|
end
|
162
162
|
|
163
|
-
it "
|
163
|
+
it "does not include an inherited constant if it is overridden by the object" do
|
164
164
|
consts = P(:SubYard).constants
|
165
|
-
consts.
|
166
|
-
consts.
|
165
|
+
expect(consts).to include(P("SubYard::CONST2"))
|
166
|
+
expect(consts).not_to include(P("YARD::CONST2"))
|
167
167
|
end
|
168
168
|
|
169
|
-
it "
|
169
|
+
it "does not include an inherited constant if it is overridden by another subclass" do
|
170
170
|
consts = P(:SubYard).inherited_constants
|
171
|
-
consts.
|
172
|
-
consts.
|
171
|
+
expect(consts).to include(P("SUPERYARD::CONST4"))
|
172
|
+
expect(consts).not_to include(P("YARD::CONST4"))
|
173
173
|
end
|
174
174
|
|
175
|
-
it "
|
175
|
+
it "does not set a superclass on BasicObject class" do
|
176
176
|
o = ClassObject.new(:root, :Object)
|
177
|
-
o.superclass.
|
177
|
+
expect(o.superclass).to eq P(:BasicObject)
|
178
178
|
end
|
179
179
|
|
180
|
-
it "
|
180
|
+
it "sets superclass of Object to BasicObject" do
|
181
181
|
o = ClassObject.new(:root, :BasicObject)
|
182
|
-
o.superclass.
|
182
|
+
expect(o.superclass).to be nil
|
183
183
|
end
|
184
184
|
|
185
|
-
it "
|
186
|
-
|
185
|
+
it "raises ArgumentError if superclass == self" do
|
186
|
+
expect do
|
187
187
|
o = ClassObject.new(:root, :Object) do |o|
|
188
188
|
o.superclass = :Object
|
189
189
|
end
|
190
|
-
end.
|
190
|
+
end.to raise_error(ArgumentError)
|
191
191
|
end
|
192
192
|
|
193
|
-
it "
|
193
|
+
it "tells the world if it is an exception class" do
|
194
194
|
o = ClassObject.new(:root, :MyClass)
|
195
195
|
o2 = ClassObject.new(:root, :OtherClass)
|
196
196
|
o2.superclass = :SystemCallError
|
@@ -199,27 +199,27 @@ describe YARD::CodeObjects::ClassObject do
|
|
199
199
|
o4 = ClassObject.new(:root, :Object)
|
200
200
|
|
201
201
|
o.superclass = :Object
|
202
|
-
o.is_exception
|
202
|
+
expect(o.is_exception?).to be false
|
203
203
|
|
204
204
|
o.superclass = :Exception
|
205
|
-
o.is_exception
|
205
|
+
expect(o.is_exception?).to be true
|
206
206
|
|
207
207
|
o.superclass = :NoMethodError
|
208
|
-
o.is_exception
|
208
|
+
expect(o.is_exception?).to be true
|
209
209
|
|
210
210
|
o.superclass = o2
|
211
|
-
o.is_exception
|
211
|
+
expect(o.is_exception?).to be true
|
212
212
|
|
213
213
|
o.superclass = o3
|
214
|
-
o.is_exception
|
214
|
+
expect(o.is_exception?).to be true
|
215
215
|
end
|
216
216
|
|
217
|
-
it "
|
218
|
-
|
217
|
+
it "does not raise ArgumentError if superclass is proxy in different namespace" do
|
218
|
+
expect do
|
219
219
|
o = ClassObject.new(:root, :X) do |o|
|
220
220
|
o.superclass = P('OTHER::X')
|
221
221
|
end
|
222
|
-
end.
|
222
|
+
end.not_to raise_error
|
223
223
|
end
|
224
224
|
end
|
225
225
|
end
|
@@ -3,31 +3,33 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe YARD::CodeObjects::CodeObjectList do
|
4
4
|
before { Registry.clear }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
describe "#push" do
|
7
|
+
it "only allows CodeObjects::Base, String or Symbol" do
|
8
|
+
list = CodeObjectList.new(nil)
|
9
|
+
expect { list.push(:hash => 1) }.to raise_error(ArgumentError)
|
10
|
+
list << "Test"
|
11
|
+
list << :Test2
|
12
|
+
list << ModuleObject.new(nil, :YARD)
|
13
|
+
expect(list.size).to eq 3
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
it "added value should be a proxy if parameter was String or Symbol" do
|
16
18
|
list = CodeObjectList.new(nil)
|
17
19
|
list << "Test"
|
18
|
-
list.first.class.
|
20
|
+
expect(list.first.class).to eq Proxy
|
19
21
|
end
|
20
22
|
|
21
|
-
it "
|
23
|
+
it "contains a unique list of objects" do
|
22
24
|
obj = ModuleObject.new(nil, :YARD)
|
23
25
|
list = CodeObjectList.new(nil)
|
24
26
|
|
25
27
|
list << P(:YARD)
|
26
28
|
list << obj
|
27
|
-
list.size.
|
29
|
+
expect(list.size).to eq 1
|
28
30
|
|
29
31
|
list << :Test
|
30
32
|
list << "Test"
|
31
|
-
list.size.
|
33
|
+
expect(list.size).to eq 2
|
32
34
|
end
|
33
35
|
end
|
@@ -1,82 +1,92 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe YARD::CodeObjects
|
4
|
-
|
5
|
-
"
|
6
|
-
|
7
|
-
|
3
|
+
describe YARD::CodeObjects do
|
4
|
+
describe :CONSTANTMATCH do
|
5
|
+
it "matches a constant" do
|
6
|
+
expect("Constant"[CodeObjects::CONSTANTMATCH]).to eq "Constant"
|
7
|
+
expect("identifier"[CodeObjects::CONSTANTMATCH]).to be nil
|
8
|
+
expect("File.new"[CodeObjects::CONSTANTMATCH]).to eq "File"
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
describe
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
describe :CONSTANTSTART do
|
13
|
+
it "matches a constant" do
|
14
|
+
expect("Constant"[CodeObjects::CONSTANTSTART]).to eq "C"
|
15
|
+
expect("identifier"[CodeObjects::CONSTANTSTART]).to be nil
|
16
|
+
expect("File.new"[CodeObjects::CONSTANTSTART]).to eq "F"
|
17
|
+
end
|
15
18
|
end
|
16
|
-
end
|
17
19
|
|
18
|
-
describe
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"method?"[CodeObjects::METHODNAMEMATCH].should == "method?"
|
24
|
-
"method!!"[CodeObjects::METHODNAMEMATCH].should == "method!"
|
20
|
+
describe :NAMESPACEMATCH do
|
21
|
+
it "matches a namespace (multiple constants with ::)" do
|
22
|
+
expect("Constant"[CodeObjects::NAMESPACEMATCH]).to eq "Constant"
|
23
|
+
expect("A::B::C.new"[CodeObjects::NAMESPACEMATCH]).to eq "A::B::C"
|
24
|
+
end
|
25
25
|
end
|
26
|
-
end
|
27
26
|
|
28
|
-
describe
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
describe :METHODNAMEMATCH do
|
28
|
+
it "matches a method name" do
|
29
|
+
expect("method"[CodeObjects::METHODNAMEMATCH]).to eq "method"
|
30
|
+
expect("[]()"[CodeObjects::METHODNAMEMATCH]).to eq "[]"
|
31
|
+
expect("-@"[CodeObjects::METHODNAMEMATCH]).to eq "-@"
|
32
|
+
expect("method?"[CodeObjects::METHODNAMEMATCH]).to eq "method?"
|
33
|
+
expect("method!!"[CodeObjects::METHODNAMEMATCH]).to eq "method!"
|
34
|
+
end
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
describe :METHODMATCH do
|
38
|
+
it "matches a full class method path" do
|
39
|
+
expect("method"[CodeObjects::METHODMATCH]).to eq "method"
|
40
|
+
expect("A::B::C.method?"[CodeObjects::METHODMATCH]).to eq "A::B::C.method?"
|
41
|
+
expect("A::B::C :: method"[CodeObjects::METHODMATCH]).to eq "A::B::C :: method"
|
42
|
+
expect("SomeClass . method"[CodeObjects::METHODMATCH]).to eq "SomeClass . method"
|
43
|
+
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
eval(name).should <= Exception
|
45
|
+
it "matches self.method" do
|
46
|
+
expect("self :: method!"[CodeObjects::METHODMATCH]).to eq "self :: method!"
|
47
|
+
expect("self.is_a?"[CodeObjects::METHODMATCH]).to eq "self.is_a?"
|
46
48
|
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
describe
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
eval(name).should be_instance_of(Class)
|
51
|
+
describe :BUILTIN_EXCEPTIONS do
|
52
|
+
it "includes all base exceptions" do
|
53
|
+
YARD::CodeObjects::BUILTIN_EXCEPTIONS.each do |name|
|
54
|
+
expect(eval(name)).to be <= Exception
|
55
|
+
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
YARD::CodeObjects::BUILTIN_CLASSES.
|
59
|
+
describe :BUILTIN_CLASSES do
|
60
|
+
it "includes all base classes" do
|
61
|
+
YARD::CodeObjects::BUILTIN_CLASSES.each do |name|
|
62
|
+
next if name == "MatchingData" && !defined?(::MatchingData)
|
63
|
+
next if name == "Continuation"
|
64
|
+
expect(eval(name)).to be_instance_of(Class)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "includes all exceptions" do
|
69
|
+
YARD::CodeObjects::BUILTIN_EXCEPTIONS.each do |name|
|
70
|
+
expect(YARD::CodeObjects::BUILTIN_CLASSES).to include(name)
|
71
|
+
end
|
62
72
|
end
|
63
73
|
end
|
64
|
-
end
|
65
74
|
|
66
|
-
describe
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
describe :BUILTIN_ALL do
|
76
|
+
it "includes classes, modules, and exceptions" do
|
77
|
+
a = YARD::CodeObjects::BUILTIN_ALL
|
78
|
+
b = YARD::CodeObjects::BUILTIN_CLASSES
|
79
|
+
c = YARD::CodeObjects::BUILTIN_MODULES
|
80
|
+
expect(a).to eq b+c
|
81
|
+
end
|
72
82
|
end
|
73
|
-
end
|
74
83
|
|
75
|
-
describe
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
84
|
+
describe :BUILTIN_MODULES do
|
85
|
+
it "includes all base modules" do
|
86
|
+
YARD::CodeObjects::BUILTIN_MODULES.each do |name|
|
87
|
+
next if YARD.ruby19? && ["Precision"].include?(name)
|
88
|
+
expect(eval(name)).to be_instance_of(Module)
|
89
|
+
end
|
80
90
|
end
|
81
91
|
end
|
82
|
-
end
|
92
|
+
end
|
@@ -1,147 +1,159 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe YARD::CodeObjects::ExtraFileObject do
|
4
|
-
describe
|
5
|
-
it "
|
6
|
-
File.
|
4
|
+
describe "#initialize" do
|
5
|
+
it "attempts to read contents from filesystem if contents=nil" do
|
6
|
+
expect(File).to receive(:read).with('file.txt').and_return('')
|
7
7
|
ExtraFileObject.new('file.txt')
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
11
|
-
|
10
|
+
it "raises Errno::ENOENT if contents=nil and file does not exist" do
|
11
|
+
expect { ExtraFileObject.new('file.txt') }.to raise_error(Errno::ENOENT)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "does not attempt to read from disk if contents are provided" do
|
15
|
+
# TODO: no assertions here!
|
15
16
|
ExtraFileObject.new('file.txt', 'CONTENTS')
|
16
17
|
end
|
17
18
|
|
18
|
-
it "
|
19
|
+
it "sets filename to filename" do
|
19
20
|
file = ExtraFileObject.new('a/b/c/file.txt', 'CONTENTS')
|
20
|
-
file.filename.
|
21
|
+
expect(file.filename).to eq "a/b/c/file.txt"
|
21
22
|
end
|
22
23
|
|
23
|
-
it "
|
24
|
+
it "parses out attributes at top of the file" do
|
24
25
|
file = ExtraFileObject.new('file.txt', "# @title X\n# @some_attribute Y\nFOO BAR")
|
25
|
-
file.attributes[:title].
|
26
|
-
file.attributes[:some_attribute].
|
27
|
-
file.contents.
|
26
|
+
expect(file.attributes[:title]).to eq "X"
|
27
|
+
expect(file.attributes[:some_attribute]).to eq "Y"
|
28
|
+
expect(file.contents).to eq "FOO BAR"
|
28
29
|
end
|
29
30
|
|
30
|
-
it "
|
31
|
+
it "allows whitespace prior to '#' marker when parsing attributes" do
|
31
32
|
file = ExtraFileObject.new('file.txt', " \t # @title X\nFOO BAR")
|
32
|
-
file.attributes[:title].
|
33
|
-
file.contents.
|
33
|
+
expect(file.attributes[:title]).to eq "X"
|
34
|
+
expect(file.contents).to eq "FOO BAR"
|
34
35
|
end
|
35
36
|
|
36
|
-
it "
|
37
|
+
it "allows the attributes section to be wrapped in an HTML comment" do
|
38
|
+
file = ExtraFileObject.new('file.txt', "<!--\n# @title X\n-->\nFOO BAR")
|
39
|
+
expect(file.attributes[:title]).to eq "X"
|
40
|
+
expect(file.contents).to eq "FOO BAR"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "allows whitespace around ignored HTML comment" do
|
44
|
+
file = ExtraFileObject.new('file.txt', " \t <!-- \n# @title X\n \t --> \nFOO BAR")
|
45
|
+
expect(file.attributes[:title]).to eq "X"
|
46
|
+
expect(file.contents).to eq "FOO BAR"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses out old-style #!markup shebang format" do
|
37
50
|
file = ExtraFileObject.new('file.txt', "#!foobar\nHello")
|
38
|
-
file.attributes[:markup].
|
51
|
+
expect(file.attributes[:markup]).to eq "foobar"
|
39
52
|
end
|
40
53
|
|
41
|
-
it "
|
54
|
+
it "does not parse old-style #!markup if any whitespace is found" do
|
42
55
|
file = ExtraFileObject.new('file.txt', " #!foobar\nHello")
|
43
|
-
file.attributes[:markup].
|
44
|
-
file.contents.
|
56
|
+
expect(file.attributes[:markup]).to be nil
|
57
|
+
expect(file.contents).to eq " #!foobar\nHello"
|
45
58
|
end
|
46
59
|
|
47
|
-
it "
|
60
|
+
it "does not parse out attributes if there are newlines prior to attributes" do
|
48
61
|
file = ExtraFileObject.new('file.txt', "\n# @title\nFOO BAR")
|
49
|
-
file.attributes.
|
50
|
-
file.contents.
|
62
|
+
expect(file.attributes).to be_empty
|
63
|
+
expect(file.contents).to eq "\n# @title\nFOO BAR"
|
51
64
|
end
|
52
65
|
|
53
|
-
it "
|
66
|
+
it "sets contents to data after attributes" do
|
54
67
|
file = ExtraFileObject.new('file.txt', "# @title\nFOO BAR")
|
55
|
-
file.contents.
|
68
|
+
expect(file.contents).to eq "FOO BAR"
|
56
69
|
end
|
57
70
|
|
58
|
-
it "
|
71
|
+
it "preserves newlines" do
|
59
72
|
file = ExtraFileObject.new('file.txt', "FOO\r\nBAR\nBAZ")
|
60
|
-
file.contents.
|
73
|
+
expect(file.contents).to eq "FOO\r\nBAR\nBAZ"
|
61
74
|
end
|
62
75
|
|
63
|
-
it "
|
76
|
+
it "does not include newlines in attribute data" do
|
64
77
|
file = ExtraFileObject.new('file.txt', "# @title FooBar\r\nHello world")
|
65
|
-
file.attributes[:title].
|
78
|
+
expect(file.attributes[:title]).to eq "FooBar"
|
66
79
|
end
|
67
80
|
|
68
|
-
it "
|
69
|
-
log.
|
81
|
+
it "forces encoding to @encoding attribute if present" do
|
82
|
+
expect(log).not_to receive(:warn)
|
70
83
|
data = "# @encoding sjis\nFOO"
|
71
84
|
data.force_encoding('binary')
|
72
85
|
file = ExtraFileObject.new('file.txt', data)
|
73
|
-
['Shift_JIS', 'Windows-31J'].
|
86
|
+
expect(['Shift_JIS', 'Windows-31J']).to include(file.contents.encoding.to_s)
|
74
87
|
end if YARD.ruby19?
|
75
88
|
|
76
|
-
it "
|
77
|
-
log.
|
89
|
+
it "warns if @encoding is invalid" do
|
90
|
+
expect(log).to receive(:warn).with("Invalid encoding `INVALID' in file.txt")
|
78
91
|
data = "# @encoding INVALID\nFOO"
|
79
92
|
encoding = data.encoding
|
80
93
|
file = ExtraFileObject.new('file.txt', data)
|
81
|
-
file.contents.encoding.
|
94
|
+
expect(file.contents.encoding).to eq encoding
|
82
95
|
end if YARD.ruby19?
|
83
96
|
|
84
|
-
it "
|
85
|
-
log.
|
97
|
+
it "ignores encoding in 1.8.x (or encoding-unaware platforms)" do
|
98
|
+
expect(log).not_to receive(:warn)
|
86
99
|
file = ExtraFileObject.new('file.txt', "# @encoding INVALID\nFOO")
|
87
100
|
end if YARD.ruby18?
|
88
101
|
|
89
|
-
it "
|
90
|
-
log.
|
102
|
+
it "attempts to re-parse data as 8-bit ascii if parsing fails" do
|
103
|
+
expect(log).not_to receive(:warn)
|
91
104
|
str, out = *(["\xB0"] * 2)
|
92
105
|
if str.respond_to?(:force_encoding)
|
93
106
|
str.force_encoding('utf-8')
|
94
107
|
out.force_encoding('binary')
|
95
108
|
end
|
96
109
|
file = ExtraFileObject.new('file.txt', str)
|
97
|
-
file.contents.
|
110
|
+
expect(file.contents).to eq out
|
98
111
|
end
|
99
112
|
end
|
100
113
|
|
101
|
-
describe
|
102
|
-
it "
|
114
|
+
describe "#name" do
|
115
|
+
it "returns basename (not extension) of filename" do
|
103
116
|
file = ExtraFileObject.new('file.txt', '')
|
104
|
-
file.name.
|
117
|
+
expect(file.name).to eq 'file'
|
105
118
|
end
|
106
119
|
end
|
107
120
|
|
108
|
-
describe
|
109
|
-
it "
|
121
|
+
describe "#title" do
|
122
|
+
it "returns @title attribute if present" do
|
110
123
|
file = ExtraFileObject.new('file.txt', '# @title FOO')
|
111
|
-
file.title.
|
124
|
+
expect(file.title).to eq 'FOO'
|
112
125
|
end
|
113
126
|
|
114
|
-
it "
|
127
|
+
it "returns #name if no @title attribute exists" do
|
115
128
|
file = ExtraFileObject.new('file.txt', '')
|
116
|
-
file.title.
|
129
|
+
expect(file.title).to eq 'file'
|
117
130
|
end
|
118
131
|
end
|
119
132
|
|
120
|
-
describe
|
121
|
-
it "
|
133
|
+
describe "#locale=" do
|
134
|
+
it "translates contents" do
|
122
135
|
file = ExtraFileObject.new('file.txt', 'Hello')
|
123
136
|
file.locale = 'fr'
|
124
137
|
fr_locale = I18n::Locale.new('fr')
|
125
138
|
fr_messages = fr_locale.instance_variable_get(:@messages)
|
126
139
|
fr_messages["Hello"] = 'Bonjour'
|
127
|
-
Registry.
|
128
|
-
file.contents.
|
140
|
+
expect(Registry).to receive(:locale).with('fr').and_return(fr_locale)
|
141
|
+
expect(file.contents).to eq 'Bonjour'
|
129
142
|
end
|
130
143
|
end
|
131
144
|
|
132
|
-
describe
|
133
|
-
it "
|
145
|
+
describe "#==" do
|
146
|
+
it "defines equality based on filename alone" do
|
134
147
|
file1 = ExtraFileObject.new('file.txt', 'A')
|
135
148
|
file2 = ExtraFileObject.new('file.txt', 'B')
|
136
|
-
file1.
|
137
|
-
file1.
|
138
|
-
file1.
|
149
|
+
expect(file1).to eq file2
|
150
|
+
expect(file1).to eql file2
|
151
|
+
expect(file1).to equal file2
|
139
152
|
|
140
153
|
# Another way to test the equality interface
|
141
154
|
a = [file1]
|
142
155
|
a |= [file2]
|
143
|
-
a.size.
|
156
|
+
expect(a.size).to eq 1
|
144
157
|
end
|
145
|
-
|
146
158
|
end
|
147
159
|
end
|