yard 0.9.24 → 0.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +37 -24
- data/CHANGELOG.md +18 -3
- data/README.md +96 -101
- data/Rakefile +2 -0
- data/lib/yard/cli/diff.rb +4 -1
- data/lib/yard/cli/server.rb +22 -13
- data/lib/yard/code_objects/proxy.rb +2 -1
- data/lib/yard/globals.rb +1 -1
- data/lib/yard/handlers/c/base.rb +164 -129
- data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
- data/lib/yard/registry_store.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +10 -3
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
- data/lib/yard/version.rb +1 -1
- data/tasks/update_error_map.rake +53 -0
- data/yard.gemspec +1 -1
- metadata +3 -207
- data/spec/cli/command_parser_spec.rb +0 -43
- data/spec/cli/command_spec.rb +0 -36
- data/spec/cli/config_spec.rb +0 -148
- data/spec/cli/diff_spec.rb +0 -254
- data/spec/cli/display_spec.rb +0 -30
- data/spec/cli/gems_spec.rb +0 -81
- data/spec/cli/graph_spec.rb +0 -18
- data/spec/cli/help_spec.rb +0 -22
- data/spec/cli/i18n_spec.rb +0 -107
- data/spec/cli/list_spec.rb +0 -8
- data/spec/cli/markup_types_spec.rb +0 -22
- data/spec/cli/server_spec.rb +0 -324
- data/spec/cli/stats_spec.rb +0 -96
- data/spec/cli/yard_on_yard_spec.rb +0 -38
- data/spec/cli/yardoc_spec.rb +0 -896
- data/spec/cli/yri_spec.rb +0 -101
- data/spec/code_objects/base_spec.rb +0 -485
- data/spec/code_objects/class_object_spec.rb +0 -226
- data/spec/code_objects/code_object_list_spec.rb +0 -36
- data/spec/code_objects/constants_spec.rb +0 -116
- data/spec/code_objects/extra_file_object_spec.rb +0 -161
- data/spec/code_objects/macro_object_spec.rb +0 -150
- data/spec/code_objects/method_object_spec.rb +0 -184
- data/spec/code_objects/module_object_spec.rb +0 -142
- data/spec/code_objects/namespace_mapper_spec.rb +0 -32
- data/spec/code_objects/namespace_object_spec.rb +0 -171
- data/spec/code_objects/proxy_spec.rb +0 -147
- data/spec/code_objects/spec_helper.rb +0 -3
- data/spec/config_spec.rb +0 -171
- data/spec/core_ext/array_spec.rb +0 -13
- data/spec/core_ext/file_spec.rb +0 -72
- data/spec/core_ext/hash_spec.rb +0 -14
- data/spec/core_ext/insertion_spec.rb +0 -37
- data/spec/core_ext/module_spec.rb +0 -9
- data/spec/core_ext/string_spec.rb +0 -42
- data/spec/core_ext/symbol_hash_spec.rb +0 -89
- data/spec/docstring_parser_spec.rb +0 -280
- data/spec/docstring_spec.rb +0 -373
- data/spec/handlers/alias_handler_spec.rb +0 -82
- data/spec/handlers/attribute_handler_spec.rb +0 -96
- data/spec/handlers/base_spec.rb +0 -216
- data/spec/handlers/c/alias_handler_spec.rb +0 -34
- data/spec/handlers/c/attribute_handler_spec.rb +0 -41
- data/spec/handlers/c/class_handler_spec.rb +0 -78
- data/spec/handlers/c/constant_handler_spec.rb +0 -71
- data/spec/handlers/c/init_handler_spec.rb +0 -48
- data/spec/handlers/c/method_handler_spec.rb +0 -327
- data/spec/handlers/c/mixin_handler_spec.rb +0 -44
- data/spec/handlers/c/module_handler_spec.rb +0 -71
- data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
- data/spec/handlers/c/path_handler_spec.rb +0 -36
- data/spec/handlers/c/spec_helper.rb +0 -23
- data/spec/handlers/c/struct_handler_spec.rb +0 -16
- data/spec/handlers/class_condition_handler_spec.rb +0 -87
- data/spec/handlers/class_handler_spec.rb +0 -247
- data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
- data/spec/handlers/class_variable_handler_spec.rb +0 -12
- data/spec/handlers/constant_handler_spec.rb +0 -112
- data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
- data/spec/handlers/dsl_handler_spec.rb +0 -226
- data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
- data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
- data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
- data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
- data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
- data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
- data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
- data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
- data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
- data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
- data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
- data/spec/handlers/exception_handler_spec.rb +0 -49
- data/spec/handlers/extend_handler_spec.rb +0 -28
- data/spec/handlers/legacy_base_spec.rb +0 -128
- data/spec/handlers/method_condition_handler_spec.rb +0 -15
- data/spec/handlers/method_handler_spec.rb +0 -214
- data/spec/handlers/mixin_handler_spec.rb +0 -60
- data/spec/handlers/module_function_handler_spec.rb +0 -106
- data/spec/handlers/module_handler_spec.rb +0 -35
- data/spec/handlers/private_class_method_handler_spec.rb +0 -11
- data/spec/handlers/private_constant_handler_spec.rb +0 -25
- data/spec/handlers/processor_spec.rb +0 -35
- data/spec/handlers/public_class_method_handler_spec.rb +0 -11
- data/spec/handlers/ruby/base_spec.rb +0 -95
- data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
- data/spec/handlers/spec_helper.rb +0 -33
- data/spec/handlers/visibility_handler_spec.rb +0 -44
- data/spec/handlers/yield_handler_spec.rb +0 -52
- data/spec/i18n/locale_spec.rb +0 -81
- data/spec/i18n/message_spec.rb +0 -52
- data/spec/i18n/messages_spec.rb +0 -67
- data/spec/i18n/pot_generator_spec.rb +0 -295
- data/spec/i18n/text_spec.rb +0 -184
- data/spec/logging_spec.rb +0 -44
- data/spec/options_spec.rb +0 -171
- data/spec/parser/base_spec.rb +0 -24
- data/spec/parser/c_parser_spec.rb +0 -236
- data/spec/parser/examples/array.c.txt +0 -6267
- data/spec/parser/examples/example1.rb.txt +0 -8
- data/spec/parser/examples/extrafile.c.txt +0 -8
- data/spec/parser/examples/file.c.txt +0 -28
- data/spec/parser/examples/multifile.c.txt +0 -22
- data/spec/parser/examples/namespace.cpp.txt +0 -68
- data/spec/parser/examples/override.c.txt +0 -424
- data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
- data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
- data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
- data/spec/parser/ruby/ast_node_spec.rb +0 -33
- data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
- data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
- data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
- data/spec/parser/ruby/token_resolver_spec.rb +0 -165
- data/spec/parser/source_parser_spec.rb +0 -727
- data/spec/parser/tag_parsing_spec.rb +0 -17
- data/spec/rake/yardoc_task_spec.rb +0 -118
- data/spec/registry_resolver_spec.rb +0 -15
- data/spec/registry_spec.rb +0 -463
- data/spec/registry_store_spec.rb +0 -327
- data/spec/rubygems/doc_manager_spec.rb +0 -112
- data/spec/serializers/data/serialized_yardoc/checksums +0 -1
- data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
- data/spec/serializers/file_system_serializer_spec.rb +0 -145
- data/spec/serializers/spec_helper.rb +0 -2
- data/spec/serializers/yardoc_serializer_spec.rb +0 -90
- data/spec/server/adapter_spec.rb +0 -39
- data/spec/server/commands/base_spec.rb +0 -91
- data/spec/server/commands/library_command_spec.rb +0 -39
- data/spec/server/doc_server_helper_spec.rb +0 -72
- data/spec/server/doc_server_serializer_spec.rb +0 -60
- data/spec/server/rack_adapter_spec.rb +0 -21
- data/spec/server/router_spec.rb +0 -123
- data/spec/server/spec_helper.rb +0 -22
- data/spec/server/static_caching_spec.rb +0 -47
- data/spec/server/webrick_servlet_spec.rb +0 -20
- data/spec/server_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -212
- data/spec/tags/default_factory_spec.rb +0 -168
- data/spec/tags/default_tag_spec.rb +0 -11
- data/spec/tags/directives_spec.rb +0 -463
- data/spec/tags/library_spec.rb +0 -48
- data/spec/tags/overload_tag_spec.rb +0 -53
- data/spec/tags/ref_tag_list_spec.rb +0 -53
- data/spec/tags/types_explainer_spec.rb +0 -203
- data/spec/templates/class_spec.rb +0 -45
- data/spec/templates/constant_spec.rb +0 -41
- data/spec/templates/engine_spec.rb +0 -131
- data/spec/templates/examples/class001.html +0 -308
- data/spec/templates/examples/class001.txt +0 -36
- data/spec/templates/examples/class002.html +0 -39
- data/spec/templates/examples/constant001.txt +0 -25
- data/spec/templates/examples/constant002.txt +0 -7
- data/spec/templates/examples/constant003.txt +0 -11
- data/spec/templates/examples/method001.html +0 -137
- data/spec/templates/examples/method001.txt +0 -35
- data/spec/templates/examples/method002.html +0 -91
- data/spec/templates/examples/method002.txt +0 -20
- data/spec/templates/examples/method003.html +0 -165
- data/spec/templates/examples/method003.txt +0 -45
- data/spec/templates/examples/method004.html +0 -48
- data/spec/templates/examples/method004.txt +0 -10
- data/spec/templates/examples/method005.html +0 -105
- data/spec/templates/examples/method005.txt +0 -33
- data/spec/templates/examples/method006.html +0 -108
- data/spec/templates/examples/method006.txt +0 -20
- data/spec/templates/examples/module001.dot +0 -33
- data/spec/templates/examples/module001.html +0 -833
- data/spec/templates/examples/module001.txt +0 -33
- data/spec/templates/examples/module002.html +0 -341
- data/spec/templates/examples/module003.html +0 -202
- data/spec/templates/examples/module004.html +0 -394
- data/spec/templates/examples/module005.html +0 -82
- data/spec/templates/examples/tag001.txt +0 -82
- data/spec/templates/helpers/base_helper_spec.rb +0 -171
- data/spec/templates/helpers/html_helper_spec.rb +0 -666
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
- data/spec/templates/helpers/markup_helper_spec.rb +0 -136
- data/spec/templates/helpers/method_helper_spec.rb +0 -107
- data/spec/templates/helpers/module_helper_spec.rb +0 -35
- data/spec/templates/helpers/shared_signature_examples.rb +0 -126
- data/spec/templates/helpers/text_helper_spec.rb +0 -65
- data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
- data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
- data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
- data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
- data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
- data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
- data/spec/templates/method_spec.rb +0 -118
- data/spec/templates/module_spec.rb +0 -203
- data/spec/templates/onefile_spec.rb +0 -66
- data/spec/templates/section_spec.rb +0 -144
- data/spec/templates/spec_helper.rb +0 -76
- data/spec/templates/tag_spec.rb +0 -52
- data/spec/templates/template_spec.rb +0 -410
- data/spec/verifier_spec.rb +0 -106
data/spec/cli/yri_spec.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class TestYRI < YARD::CLI::YRI
|
4
|
-
public :optparse, :find_object, :cache_object
|
5
|
-
def test_stub; end
|
6
|
-
def print_object(*args) test_stub; super end
|
7
|
-
end
|
8
|
-
|
9
|
-
RSpec.describe YARD::CLI::YRI do
|
10
|
-
before do
|
11
|
-
@yri = TestYRI.new
|
12
|
-
allow(Registry).to receive(:load)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#find_object" do
|
16
|
-
it "uses cache if available" do
|
17
|
-
allow(@yri).to receive(:cache_object)
|
18
|
-
expect(File).to receive(:exist?).with('.yardoc').and_return(false)
|
19
|
-
expect(File).to receive(:exist?).with('bar.yardoc').and_return(true)
|
20
|
-
expect(Registry).to receive(:load).with('bar.yardoc')
|
21
|
-
expect(Registry).to receive(:at).ordered.with('Foo').and_return(nil)
|
22
|
-
expect(Registry).to receive(:at).ordered.with('Foo').and_return('OBJ')
|
23
|
-
@yri.instance_variable_set("@cache", 'Foo' => 'bar.yardoc')
|
24
|
-
expect(@yri.find_object('Foo')).to eq 'OBJ'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "never uses cache ahead of current directory's .yardoc" do
|
28
|
-
allow(@yri).to receive(:cache_object)
|
29
|
-
expect(File).to receive(:exist?).with('.yardoc').and_return(true)
|
30
|
-
expect(Registry).to receive(:load).with('.yardoc')
|
31
|
-
expect(Registry).to receive(:at).ordered.with('Foo').and_return(nil)
|
32
|
-
expect(Registry).to receive(:at).ordered.with('Foo').and_return('OBJ')
|
33
|
-
@yri.instance_variable_set("@cache", 'Foo' => 'bar.yardoc')
|
34
|
-
expect(@yri.find_object('Foo')).to eq 'OBJ'
|
35
|
-
expect(@yri.instance_variable_get("@search_paths")[0]).to eq '.yardoc'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#cache_object" do
|
40
|
-
it "skips caching for Registry.yardoc_file" do
|
41
|
-
expect(File).not_to receive(:open).with(CLI::YRI::CACHE_FILE, 'w')
|
42
|
-
@yri.cache_object('Foo', Registry.yardoc_file)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#initialize" do
|
47
|
-
it "loads search paths" do
|
48
|
-
path = %r{/\.yard/yri_search_paths$}
|
49
|
-
allow(File).to receive(:file?).and_call_original
|
50
|
-
allow(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false)
|
51
|
-
allow(File).to receive(:file?).with(path).and_return(true)
|
52
|
-
allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2))
|
53
|
-
@yri = YARD::CLI::YRI.new
|
54
|
-
spaths = @yri.instance_variable_get("@search_paths")
|
55
|
-
expect(spaths).to include('line1')
|
56
|
-
expect(spaths).to include('line2')
|
57
|
-
end
|
58
|
-
|
59
|
-
it "uses DEFAULT_SEARCH_PATHS prior to other paths" do
|
60
|
-
YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.push('foo', 'bar')
|
61
|
-
path = %r{/\.yard/yri_search_paths$}
|
62
|
-
allow(File).to receive(:file?).and_call_original
|
63
|
-
allow(File).to receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false)
|
64
|
-
allow(File).to receive(:file?).with(path).and_return(true)
|
65
|
-
allow(File).to receive(:readlines).with(path).and_return(%w(line1 line2))
|
66
|
-
@yri = YARD::CLI::YRI.new
|
67
|
-
spaths = @yri.instance_variable_get("@search_paths")
|
68
|
-
expect(spaths[0, 4]).to eq %w(foo bar line1 line2)
|
69
|
-
YARD::CLI::YRI::DEFAULT_SEARCH_PATHS.replace([])
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#run" do
|
74
|
-
it "searches for objects and print their documentation" do
|
75
|
-
obj = YARD::CodeObjects::ClassObject.new(:root, 'Foo')
|
76
|
-
expect(@yri).to receive(:print_object).with(obj)
|
77
|
-
@yri.run('Foo')
|
78
|
-
Registry.clear
|
79
|
-
end
|
80
|
-
|
81
|
-
it "prints usage if no object is provided" do
|
82
|
-
expect(@yri).to receive(:print_usage)
|
83
|
-
expect(@yri).to receive(:exit).with(1)
|
84
|
-
@yri.run('')
|
85
|
-
end
|
86
|
-
|
87
|
-
it "prints 'no documentation exists for object' if object is not found" do
|
88
|
-
expect(STDERR).to receive(:puts).with("No documentation for `Foo'")
|
89
|
-
expect(@yri).to receive(:exit).with(1)
|
90
|
-
@yri.run('Foo')
|
91
|
-
end
|
92
|
-
|
93
|
-
it "ensures output is serialized" do
|
94
|
-
YARD::CodeObjects::ClassObject.new(:root, 'Foo')
|
95
|
-
allow(@yri).to receive(:test_stub) do
|
96
|
-
expect(@yri.instance_variable_get(:@serializer)).to receive(:serialize).once
|
97
|
-
end
|
98
|
-
@yri.run('Foo')
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,485 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe YARD::CodeObjects::Base do
|
5
|
-
before { Registry.clear }
|
6
|
-
|
7
|
-
it "does not allow empty object name" do
|
8
|
-
expect { Base.new(:root, '') }.to raise_error(ArgumentError)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "returns a unique instance of any registered object" do
|
12
|
-
obj = ClassObject.new(:root, :Me)
|
13
|
-
obj2 = ClassObject.new(:root, :Me)
|
14
|
-
expect(obj.object_id).to eq obj2.object_id
|
15
|
-
|
16
|
-
obj3 = ModuleObject.new(obj, :Too)
|
17
|
-
obj4 = CodeObjects::Base.new(obj3, :Hello)
|
18
|
-
obj4.parent = obj
|
19
|
-
|
20
|
-
obj5 = CodeObjects::Base.new(obj3, :hello)
|
21
|
-
expect(obj4.object_id).not_to eq obj5.object_id
|
22
|
-
end
|
23
|
-
|
24
|
-
it "creates a new object if cached object is not of the same class" do
|
25
|
-
expect(ConstantObject.new(:root, "MYMODULE")).to be_instance_of(ConstantObject)
|
26
|
-
expect(ModuleObject.new(:root, "MYMODULE")).to be_instance_of(ModuleObject)
|
27
|
-
expect(ClassObject.new(:root, "MYMODULE")).to be_instance_of(ClassObject)
|
28
|
-
expect(YARD::Registry.at("MYMODULE")).to be_instance_of(ClassObject)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "simplifies complex namespace paths" do
|
32
|
-
obj = ClassObject.new(:root, "A::B::C::D")
|
33
|
-
expect(obj.name).to eq :D
|
34
|
-
expect(obj.path).to eq "A::B::C::D"
|
35
|
-
expect(obj.namespace).to eq P("A::B::C")
|
36
|
-
end
|
37
|
-
|
38
|
-
# @bug gh-552
|
39
|
-
it "simplifies complex namespace paths when path starts with ::" do
|
40
|
-
obj = ClassObject.new(:root, "::A::B::C::D")
|
41
|
-
expect(obj.name).to eq :D
|
42
|
-
expect(obj.path).to eq "A::B::C::D"
|
43
|
-
expect(obj.namespace).to eq P("A::B::C")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "calls the block again if #new is called on an existing object" do
|
47
|
-
o1 = ClassObject.new(:root, :Me) do |o|
|
48
|
-
o.docstring = "DOCSTRING"
|
49
|
-
end
|
50
|
-
|
51
|
-
o2 = ClassObject.new(:root, :Me) do |o|
|
52
|
-
o.docstring = "NOT_DOCSTRING"
|
53
|
-
end
|
54
|
-
|
55
|
-
expect(o1.object_id).to eq o2.object_id
|
56
|
-
expect(o1.docstring).to eq "NOT_DOCSTRING"
|
57
|
-
expect(o2.docstring).to eq "NOT_DOCSTRING"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "allows complex name and converts it to namespace" do
|
61
|
-
obj = CodeObjects::Base.new(nil, "A::B")
|
62
|
-
expect(obj.namespace.path).to eq "A"
|
63
|
-
expect(obj.name).to eq :B
|
64
|
-
end
|
65
|
-
|
66
|
-
it "allows namespace to be nil and not register in the Registry" do
|
67
|
-
obj = CodeObjects::Base.new(nil, :Me)
|
68
|
-
expect(obj.namespace).to eq nil
|
69
|
-
expect(Registry.at(:Me)).to eq nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "allows namespace to be a NamespaceObject" do
|
73
|
-
ns = ModuleObject.new(:root, :Name)
|
74
|
-
obj = CodeObjects::Base.new(ns, :Me)
|
75
|
-
expect(obj.namespace).to eq ns
|
76
|
-
end
|
77
|
-
|
78
|
-
it "allows :root to be the shorthand namespace of `Registry.root`" do
|
79
|
-
obj = CodeObjects::Base.new(:root, :Me)
|
80
|
-
expect(obj.namespace).to eq Registry.root
|
81
|
-
end
|
82
|
-
|
83
|
-
it "does not allow any other types as namespace" do
|
84
|
-
expect { CodeObjects::Base.new("ROOT!", :Me) }.to raise_error(ArgumentError)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "allows constants to be used as a namespace" do
|
88
|
-
a = ConstantObject.new(:root, :A)
|
89
|
-
a.value = "B::C"
|
90
|
-
b = ClassObject.new(:root, :B)
|
91
|
-
c = ClassObject.new(b, :C)
|
92
|
-
klass = ClassObject.new(a, "MyClass")
|
93
|
-
expect(klass.path).to eq "B::C::MyClass"
|
94
|
-
end
|
95
|
-
|
96
|
-
it "does not allow constants to be used as a namespace if they do not resolve to a valid namespace" do
|
97
|
-
a = ConstantObject.new(:root, :A)
|
98
|
-
a.value = "$$INVALID$$"
|
99
|
-
expect { ClassObject.new(a, "MyClass") }.to raise_error(Parser::UndocumentableError)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "registers itself in the registry if namespace is supplied" do
|
103
|
-
obj = ModuleObject.new(:root, :Me)
|
104
|
-
expect(Registry.at(:Me)).to eq obj
|
105
|
-
|
106
|
-
obj2 = ModuleObject.new(obj, :Too)
|
107
|
-
expect(Registry.at(:"Me::Too")).to eq obj2
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#[]=" do
|
111
|
-
it "sets any attribute" do
|
112
|
-
obj = ModuleObject.new(:root, :YARD)
|
113
|
-
obj[:some_attr] = "hello"
|
114
|
-
expect(obj[:some_attr]).to eq "hello"
|
115
|
-
end
|
116
|
-
|
117
|
-
it "uses the accessor method if available" do
|
118
|
-
obj = CodeObjects::Base.new(:root, :YARD)
|
119
|
-
obj[:source] = "hello"
|
120
|
-
expect(obj.source).to eq "hello"
|
121
|
-
obj.source = "unhello"
|
122
|
-
expect(obj[:source]).to eq "unhello"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "sets attributes via attr= through method_missing" do
|
127
|
-
obj = CodeObjects::Base.new(:root, :YARD)
|
128
|
-
obj.something = 2
|
129
|
-
expect(obj.something).to eq 2
|
130
|
-
expect(obj[:something]).to eq 2
|
131
|
-
end
|
132
|
-
|
133
|
-
it "exists in the parent's #children after creation" do
|
134
|
-
obj = ModuleObject.new(:root, :YARD)
|
135
|
-
obj2 = MethodObject.new(obj, :testing)
|
136
|
-
expect(obj.children).to include(obj2)
|
137
|
-
end
|
138
|
-
|
139
|
-
# @bug gh-1209
|
140
|
-
it "removes prior defined objects at the same path from namespace's children" do
|
141
|
-
Registry.clear
|
142
|
-
obj = ModuleObject.new(:root, :YARD)
|
143
|
-
ConstantObject.new(obj, :Testing)
|
144
|
-
ClassObject.new(obj, :Testing)
|
145
|
-
expect(obj.children.map {|o| o.type.to_sym }).to eq [:class]
|
146
|
-
expect(Registry.at('YARD::Testing').type).to eq :class
|
147
|
-
end
|
148
|
-
|
149
|
-
it "properly re-indents source starting from 0 indentation" do
|
150
|
-
obj = CodeObjects::Base.new(nil, :test)
|
151
|
-
obj.source = <<-eof
|
152
|
-
def mymethod
|
153
|
-
if x == 2 &&
|
154
|
-
5 == 5
|
155
|
-
3
|
156
|
-
else
|
157
|
-
1
|
158
|
-
end
|
159
|
-
end
|
160
|
-
eof
|
161
|
-
expect(obj.source).to eq "def mymethod\n if x == 2 &&\n 5 == 5\n 3\n else\n 1\n end\nend"
|
162
|
-
|
163
|
-
Registry.clear
|
164
|
-
Parser::SourceParser.parse_string <<-eof
|
165
|
-
def key?(key)
|
166
|
-
super(key)
|
167
|
-
end
|
168
|
-
eof
|
169
|
-
expect(Registry.at('#key?').source).to eq "def key?(key)\n super(key)\nend"
|
170
|
-
|
171
|
-
Registry.clear
|
172
|
-
Parser::SourceParser.parse_string <<-eof
|
173
|
-
def key?(key)
|
174
|
-
if x == 2
|
175
|
-
puts key
|
176
|
-
else
|
177
|
-
exit
|
178
|
-
end
|
179
|
-
end
|
180
|
-
eof
|
181
|
-
expect(Registry.at('#key?').source).to eq "def key?(key)\n if x == 2\n puts key\n else\n exit\n end\nend"
|
182
|
-
end
|
183
|
-
|
184
|
-
it "does not add newlines to source when parsing sub blocks" do
|
185
|
-
Parser::SourceParser.parse_string <<-eof
|
186
|
-
module XYZ
|
187
|
-
module ZYX
|
188
|
-
class ABC
|
189
|
-
def msg
|
190
|
-
hello_world
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
eof
|
196
|
-
expect(Registry.at('XYZ::ZYX::ABC#msg').source).to eq "def msg\n hello_world\nend"
|
197
|
-
end
|
198
|
-
|
199
|
-
it "handles source for 'def x; end'" do
|
200
|
-
Registry.clear
|
201
|
-
Parser::SourceParser.parse_string "def x; 2 end"
|
202
|
-
expect(Registry.at('#x').source).to eq "def x; 2 end"
|
203
|
-
end
|
204
|
-
|
205
|
-
it "sets file and line information" do
|
206
|
-
Parser::SourceParser.parse_string <<-eof
|
207
|
-
class X; end
|
208
|
-
eof
|
209
|
-
expect(Registry.at(:X).file).to eq '(stdin)'
|
210
|
-
expect(Registry.at(:X).line).to eq 1
|
211
|
-
end
|
212
|
-
|
213
|
-
it "maintains all file associations when objects are defined multiple times in one file" do
|
214
|
-
Parser::SourceParser.parse_string <<-eof
|
215
|
-
class X; end
|
216
|
-
class X; end
|
217
|
-
class X; end
|
218
|
-
eof
|
219
|
-
|
220
|
-
expect(Registry.at(:X).file).to eq '(stdin)'
|
221
|
-
expect(Registry.at(:X).line).to eq 1
|
222
|
-
expect(Registry.at(:X).files).to eq [['(stdin)', 1], ['(stdin)', 2], ['(stdin)', 3]]
|
223
|
-
end
|
224
|
-
|
225
|
-
it "maintains all file associations when objects are defined multiple times in multiple files" do
|
226
|
-
3.times do |i|
|
227
|
-
allow(File).to receive(:read_binary).and_return("class X; end")
|
228
|
-
Parser::SourceParser.new.parse("file#{i + 1}.rb")
|
229
|
-
end
|
230
|
-
|
231
|
-
expect(Registry.at(:X).file).to eq 'file1.rb'
|
232
|
-
expect(Registry.at(:X).line).to eq 1
|
233
|
-
expect(Registry.at(:X).files).to eq [['file1.rb', 1], ['file2.rb', 1], ['file3.rb', 1]]
|
234
|
-
end
|
235
|
-
|
236
|
-
it "prioritizes the definition with a docstring when returning #file" do
|
237
|
-
Parser::SourceParser.parse_string <<-eof
|
238
|
-
class X; end
|
239
|
-
class X; end
|
240
|
-
# docstring
|
241
|
-
class X; end
|
242
|
-
eof
|
243
|
-
|
244
|
-
expect(Registry.at(:X).file).to eq '(stdin)'
|
245
|
-
expect(Registry.at(:X).line).to eq 4
|
246
|
-
expect(Registry.at(:X).files).to eq [['(stdin)', 4], ['(stdin)', 1], ['(stdin)', 2]]
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "#format" do
|
250
|
-
it "sends object to Templates.render" do
|
251
|
-
object = MethodObject.new(:root, :method)
|
252
|
-
expect(Templates::Engine).to receive(:render).with(:x => 1, :object => object, :type => object.type)
|
253
|
-
object.format :x => 1
|
254
|
-
end
|
255
|
-
|
256
|
-
it "does not change options object class" do
|
257
|
-
opts = YARD::Templates::TemplateOptions.new
|
258
|
-
opts.type = "test"
|
259
|
-
object = MethodObject.new(:root, :method)
|
260
|
-
expect(Templates::Engine).to receive(:render).with kind_of(YARD::Templates::TemplateOptions)
|
261
|
-
object.format(opts)
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "#source_type" do
|
266
|
-
it "defaults to :ruby" do
|
267
|
-
object = MethodObject.new(:root, :method)
|
268
|
-
expect(object.source_type).to eq :ruby
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
describe "#relative_path" do
|
273
|
-
it "accepts a string" do
|
274
|
-
YARD.parse_string "module A; class B; end; class C; end; end"
|
275
|
-
expect(Registry.at('A::B').relative_path(Registry.at('A::C'))).to eq(
|
276
|
-
Registry.at('A::B').relative_path('A::C')
|
277
|
-
)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "returns full class name when objects share a common class prefix" do
|
281
|
-
YARD.parse_string "module User; end; module UserManager; end"
|
282
|
-
expect(Registry.at('User').relative_path('UserManager')).to eq 'UserManager'
|
283
|
-
expect(Registry.at('User').relative_path(Registry.at('UserManager'))).to eq 'UserManager'
|
284
|
-
end
|
285
|
-
|
286
|
-
it "returns the relative path when they share a common namespace" do
|
287
|
-
YARD.parse_string "module A; class B; end; class C; end; end"
|
288
|
-
expect(Registry.at('A::B').relative_path(Registry.at('A::C'))).to eq 'C'
|
289
|
-
YARD.parse_string "module Foo; module A; end; module B; def foo; end end end"
|
290
|
-
expect(Registry.at('Foo::A').relative_path(Registry.at('Foo::B#foo'))).to eq 'B#foo'
|
291
|
-
end
|
292
|
-
|
293
|
-
it "returns the full path if they don't have a common namespace" do
|
294
|
-
YARD.parse_string "module A; class B; end; end; module D; class C; end; end"
|
295
|
-
expect(Registry.at('A::B').relative_path('D::C')).to eq 'D::C'
|
296
|
-
YARD.parse_string 'module C::B::C; module Apple; end; module Ant; end end'
|
297
|
-
expect(Registry.at('C::B::C::Apple').relative_path('C::B::C::Ant')).to eq 'Ant'
|
298
|
-
YARD.parse_string 'module OMG::ABC; end; class Object; end'
|
299
|
-
expect(Registry.at('OMG::ABC').relative_path('Object')).to eq "Object"
|
300
|
-
YARD.parse_string("class YARD::Config; MYCONST = 1; end")
|
301
|
-
expect(Registry.at('YARD::Config').relative_path('YARD::Config::MYCONST')).to eq "MYCONST"
|
302
|
-
end
|
303
|
-
|
304
|
-
it "returns a relative path for class methods" do
|
305
|
-
YARD.parse_string "module A; def self.b; end; def self.c; end; end"
|
306
|
-
expect(Registry.at('A.b').relative_path('A.c')).to eq 'c'
|
307
|
-
expect(Registry.at('A').relative_path('A.c')).to eq 'c'
|
308
|
-
end
|
309
|
-
|
310
|
-
it "returns a relative path for instance methods" do
|
311
|
-
YARD.parse_string "module A; def b; end; def c; end; end"
|
312
|
-
expect(Registry.at('A#b').relative_path('A#c')).to eq '#c'
|
313
|
-
expect(Registry.at('A').relative_path('A#c')).to eq '#c'
|
314
|
-
end
|
315
|
-
|
316
|
-
it "returns full path if relative path is to parent namespace" do
|
317
|
-
YARD.parse_string "module A; module B; end end"
|
318
|
-
expect(Registry.at('A::B').relative_path('A')).to eq 'A'
|
319
|
-
end
|
320
|
-
|
321
|
-
it "only returns name for relative path to self" do
|
322
|
-
YARD.parse_string("class A::B::C; def foo; end end")
|
323
|
-
expect(Registry.at('A::B::C').relative_path('A::B::C')).to eq 'C'
|
324
|
-
expect(Registry.at('A::B::C#foo').relative_path('A::B::C#foo')).to eq '#foo'
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
describe "#docstring=" do
|
329
|
-
it "converts string into Docstring when #docstring= is set" do
|
330
|
-
o = ClassObject.new(:root, :Me)
|
331
|
-
o.docstring = "DOCSTRING"
|
332
|
-
expect(o.docstring).to be_instance_of(Docstring)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "sets docstring to docstring of other object if docstring is '(see Path)'" do
|
336
|
-
ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
|
337
|
-
o = ClassObject.new(:root, :Me)
|
338
|
-
o.docstring = '(see AnotherObject)'
|
339
|
-
expect(o.docstring).to eq "FOO"
|
340
|
-
end
|
341
|
-
|
342
|
-
it "does not copy docstring mid-docstring" do
|
343
|
-
doc = "Hello.\n(see file.rb)\nmore documentation"
|
344
|
-
o = ClassObject.new(:root, :Me)
|
345
|
-
o.docstring = doc
|
346
|
-
expect(o.docstring).to eq doc
|
347
|
-
end
|
348
|
-
|
349
|
-
it "allows extra docstring after (see Path)" do
|
350
|
-
ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
|
351
|
-
o = ClassObject.new(:root, :Me)
|
352
|
-
o.docstring = Docstring.new("(see AnotherObject)\n\nEXTRA\n@api private", o)
|
353
|
-
expect(o.docstring).to eq "FOO\n\nEXTRA"
|
354
|
-
expect(o.docstring).to have_tag(:api)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe "#docstring" do
|
359
|
-
it "returns an empty string if docstring was '(see Path)' and Path is not resolved" do
|
360
|
-
o = ClassObject.new(:root, :Me)
|
361
|
-
o.docstring = '(see AnotherObject)'
|
362
|
-
expect(o.docstring).to eq ""
|
363
|
-
end
|
364
|
-
|
365
|
-
it "returns docstring when object is resolved" do
|
366
|
-
o = ClassObject.new(:root, :Me)
|
367
|
-
o.docstring = '(see AnotherObject)'
|
368
|
-
expect(o.docstring).to eq ""
|
369
|
-
ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
|
370
|
-
expect(o.docstring).to eq "FOO"
|
371
|
-
end
|
372
|
-
|
373
|
-
describe "localization" do
|
374
|
-
it "returns localized docstring" do
|
375
|
-
fr_locale = YARD::I18n::Locale.new('fr')
|
376
|
-
allow(fr_locale).to receive(:translate).with('Hello').and_return('Bonjour')
|
377
|
-
|
378
|
-
o = ClassObject.new(:root, :Me)
|
379
|
-
o.docstring = 'Hello'
|
380
|
-
expect(o.docstring).to eq 'Hello'
|
381
|
-
|
382
|
-
allow(Registry).to receive(:locale).with('fr').and_return(fr_locale)
|
383
|
-
expect(o.docstring('fr')).to eq "Bonjour"
|
384
|
-
end
|
385
|
-
|
386
|
-
it "returns localized docstring tag" do
|
387
|
-
o = CodeObjects::MethodObject.new(:root, 'Hello#message')
|
388
|
-
o.docstring.add_tag(Tags::Tag.new('return', 'Hello'))
|
389
|
-
|
390
|
-
fr_locale = YARD::I18n::Locale.new('fr')
|
391
|
-
allow(fr_locale).to receive(:translate).with('Hello').and_return('Bonjour')
|
392
|
-
allow(Registry).to receive(:locale).with('fr').and_return(fr_locale)
|
393
|
-
|
394
|
-
expect(o.docstring('fr').tags.map(&:text)).to eq ['Bonjour']
|
395
|
-
end
|
396
|
-
|
397
|
-
it "returns updated localized docstring" do
|
398
|
-
fr_locale = YARD::I18n::Locale.new('fr')
|
399
|
-
allow(Registry).to receive(:locale).with('fr').and_return(fr_locale)
|
400
|
-
|
401
|
-
o = ClassObject.new(:root, :Me)
|
402
|
-
o.docstring = 'Hello'
|
403
|
-
expect(o.docstring).to eq 'Hello'
|
404
|
-
|
405
|
-
allow(fr_locale).to receive(:translate).with('Hello').and_return('Bonjour')
|
406
|
-
expect(o.docstring('fr')).to eq "Bonjour"
|
407
|
-
|
408
|
-
o.docstring = 'World'
|
409
|
-
allow(fr_locale).to receive(:translate).with('World').and_return('Monde')
|
410
|
-
expect(o.docstring('fr')).to eq "Monde"
|
411
|
-
expect(o.docstring).to eq 'World'
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
describe "#add_file" do
|
417
|
-
it "only adds a file/line combination once" do
|
418
|
-
o = ClassObject.new(:root, :Me)
|
419
|
-
o.add_file('filename', 12)
|
420
|
-
expect(o.files).to eq [['filename', 12]]
|
421
|
-
o.add_file('filename', 12)
|
422
|
-
expect(o.files).to eq [['filename', 12]]
|
423
|
-
o.add_file('filename', 40) # different line
|
424
|
-
expect(o.files).to eq [['filename', 12], ['filename', 40]]
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe "#copy_to" do
|
429
|
-
it "copies all data to new object" do
|
430
|
-
YARD.parse_string <<-eof
|
431
|
-
private
|
432
|
-
# A docstring
|
433
|
-
# @return [String] a tag
|
434
|
-
def foo(a, b, c)
|
435
|
-
source_code_here
|
436
|
-
end
|
437
|
-
eof
|
438
|
-
foo_c = MethodObject.new(:root, :foo, :class)
|
439
|
-
Registry.at('#foo').copy_to(foo_c)
|
440
|
-
expect(foo_c.scope).to eq :class
|
441
|
-
expect(foo_c.visibility).to eq :private
|
442
|
-
expect(foo_c.type).to eq :method
|
443
|
-
expect(foo_c.class).to eq MethodObject
|
444
|
-
expect(foo_c.path).to eq '::foo'
|
445
|
-
expect(foo_c.docstring).to eq "A docstring"
|
446
|
-
expect(foo_c.tag(:return).types).to eq ['String']
|
447
|
-
expect(foo_c.file).to eq '(stdin)'
|
448
|
-
expect(foo_c.line).to eq 4
|
449
|
-
expect(foo_c.source).to match(/source_code_here/)
|
450
|
-
expect(foo_c.signature).to eq 'def foo(a, b, c)'
|
451
|
-
expect(foo_c.parameters).to eq [['a', nil], ['b', nil], ['c', nil]]
|
452
|
-
end
|
453
|
-
|
454
|
-
it "returns the copied object" do
|
455
|
-
YARD.parse_string 'def foo; end'
|
456
|
-
foo_c = MethodObject.new(:root, :foo, :class)
|
457
|
-
expect(Registry.at('#foo').copy_to(foo_c)).to eq foo_c
|
458
|
-
end
|
459
|
-
|
460
|
-
it "copies docstring and rewrite tags to new object" do
|
461
|
-
YARD.parse_string <<-eof
|
462
|
-
# @return [String] a tag
|
463
|
-
def foo; end
|
464
|
-
eof
|
465
|
-
foo_c = MethodObject.new(:root, :foo, :class)
|
466
|
-
foo_i = Registry.at('#foo')
|
467
|
-
foo_i.copy_to(foo_c)
|
468
|
-
expect(foo_i.tags).not_to eq foo_c.tags
|
469
|
-
expect(foo_c.tags.first.object).to eq foo_c
|
470
|
-
end
|
471
|
-
|
472
|
-
it "only copies #copyable_attributes" do
|
473
|
-
foo = MethodObject.new(:root, :foo)
|
474
|
-
expect(foo).to receive(:copyable_attributes).and_return %w(a b c)
|
475
|
-
expect(foo).to receive(:instance_variable_get).with('@a').and_return(1)
|
476
|
-
expect(foo).to receive(:instance_variable_get).with('@b').and_return(2)
|
477
|
-
expect(foo).to receive(:instance_variable_get).with('@c').and_return(3)
|
478
|
-
bar = MethodObject.new(:root, :bar)
|
479
|
-
expect(bar).to receive(:instance_variable_set).with('@a', 1)
|
480
|
-
expect(bar).to receive(:instance_variable_set).with('@b', 2)
|
481
|
-
expect(bar).to receive(:instance_variable_set).with('@c', 3)
|
482
|
-
foo.copy_to(bar)
|
483
|
-
end
|
484
|
-
end
|
485
|
-
end
|