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
@@ -5,7 +5,7 @@ describe YARD::Templates::Helpers::TextHelper do
|
|
5
5
|
include YARD::Templates::Helpers::TextHelper
|
6
6
|
include YARD::Templates::Helpers::MethodHelper
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe "#signature" do
|
9
9
|
before do
|
10
10
|
@results = {
|
11
11
|
:regular => "root.foo -> Object",
|
@@ -30,15 +30,15 @@ describe YARD::Templates::Helpers::TextHelper do
|
|
30
30
|
it_should_behave_like "signature"
|
31
31
|
end
|
32
32
|
|
33
|
-
describe
|
34
|
-
it "
|
33
|
+
describe "#align_right" do
|
34
|
+
it "aligns text right" do
|
35
35
|
text = "Method: #some_method (SomeClass)"
|
36
|
-
align_right(text).
|
36
|
+
expect(align_right(text)).to eq ' ' * 40 + text
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "truncates text that is longer than allowed width" do
|
40
40
|
text = "(Defined in: /home/user/.rip/.packages/some_gem-2460672e333ac07b9190ade88ec9a91c/long/path.rb)"
|
41
|
-
align_right(text).
|
41
|
+
expect(align_right(text)).to eq ' ' + text[0,68] + '...'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -7,16 +7,16 @@ describe YARD::Templates::Engine.template(:default, :method) do
|
|
7
7
|
before { Registry.clear }
|
8
8
|
|
9
9
|
shared_examples_for "all formats" do
|
10
|
-
it "
|
10
|
+
it "renders html format correctly" do
|
11
11
|
html_equals(Registry.at('#m').format(html_options), @template)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "renders text format correctly" do
|
15
15
|
text_equals(Registry.at('#m').format(text_options), @template)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
19
|
+
describe "regular (deprecated) method" do
|
20
20
|
before do
|
21
21
|
@template = :method001
|
22
22
|
YARD.parse_string <<-'eof'
|
@@ -36,7 +36,7 @@ describe YARD::Templates::Engine.template(:default, :method) do
|
|
36
36
|
it_should_behave_like "all formats"
|
37
37
|
end
|
38
38
|
|
39
|
-
describe
|
39
|
+
describe "method with 1 overload" do
|
40
40
|
before do
|
41
41
|
@template = :method002
|
42
42
|
YARD.parse_string <<-'eof'
|
@@ -52,7 +52,7 @@ describe YARD::Templates::Engine.template(:default, :method) do
|
|
52
52
|
it_should_behave_like "all formats"
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe "method with 2 overloads" do
|
56
56
|
before do
|
57
57
|
@template = :method003
|
58
58
|
YARD.parse_string <<-'eof'
|
@@ -73,7 +73,7 @@ describe YARD::Templates::Engine.template(:default, :method) do
|
|
73
73
|
it_should_behave_like "all formats"
|
74
74
|
end
|
75
75
|
|
76
|
-
describe
|
76
|
+
describe "method void return" do
|
77
77
|
before do
|
78
78
|
@template = :method004
|
79
79
|
YARD.parse_string <<-'eof'
|
@@ -85,7 +85,7 @@ describe YARD::Templates::Engine.template(:default, :method) do
|
|
85
85
|
it_should_behave_like "all formats"
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
88
|
+
describe "method void return in an overload" do
|
89
89
|
before do
|
90
90
|
@template = :method005
|
91
91
|
YARD.parse_string <<-'eof'
|
@@ -65,13 +65,13 @@ describe YARD::Templates::Engine.template(:default, :module) do
|
|
65
65
|
eof
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "renders html format correctly" do
|
69
69
|
html_equals(Registry.at('A').format(html_options(:hide_void_return => true,
|
70
70
|
:verifier => Verifier.new('object.type != :method || object.visibility == :public'))),
|
71
71
|
:module001)
|
72
72
|
end
|
73
73
|
|
74
|
-
it "
|
74
|
+
it "renders text format correctly" do
|
75
75
|
YARD.parse_string <<-'eof'
|
76
76
|
module A
|
77
77
|
include D, E, F, A::B::C
|
@@ -81,11 +81,11 @@ describe YARD::Templates::Engine.template(:default, :module) do
|
|
81
81
|
text_equals(Registry.at('A').format(text_options), :module001)
|
82
82
|
end
|
83
83
|
|
84
|
-
it "
|
85
|
-
Registry.at('A').format(:format => :dot, :dependencies => true, :full => true).
|
84
|
+
it "renders dot format correctly" do
|
85
|
+
expect(Registry.at('A').format(:format => :dot, :dependencies => true, :full => true)).to eq example_contents(:module001, 'dot')
|
86
86
|
end
|
87
87
|
|
88
|
-
it "
|
88
|
+
it "renders groups correctly in html" do
|
89
89
|
Registry.clear
|
90
90
|
YARD.parse_string <<-'eof'
|
91
91
|
module A
|
@@ -106,7 +106,7 @@ describe YARD::Templates::Engine.template(:default, :module) do
|
|
106
106
|
html_equals(Registry.at('A').format(html_options), :module002)
|
107
107
|
end
|
108
108
|
|
109
|
-
it "
|
109
|
+
it "ignores overwritten/private attributes/constants from inherited list" do
|
110
110
|
Registry.clear
|
111
111
|
YARD.parse_string <<-'eof'
|
112
112
|
module B
|
@@ -128,7 +128,7 @@ describe YARD::Templates::Engine.template(:default, :module) do
|
|
128
128
|
:verifier => Verifier.new('!@private'))), :module003)
|
129
129
|
end
|
130
130
|
|
131
|
-
it "
|
131
|
+
it "embeds mixins with :embed_mixins = ['Foo', 'Bar', 'Baz::A*']" do
|
132
132
|
Registry.clear
|
133
133
|
YARD.parse_string <<-'eof'
|
134
134
|
class A
|
@@ -52,13 +52,13 @@ describe YARD::Templates::Engine.template(:default, :onefile) do
|
|
52
52
|
]
|
53
53
|
end
|
54
54
|
|
55
|
-
it "
|
55
|
+
it "renders html" do
|
56
56
|
render
|
57
|
-
@files.
|
58
|
-
@output.
|
59
|
-
@output.
|
60
|
-
@output.
|
61
|
-
@output.
|
62
|
-
@output.
|
57
|
+
expect(@files).to eq ['index.html']
|
58
|
+
expect(@output).to include("This is a code comment")
|
59
|
+
expect(@output).to include("This is a license!")
|
60
|
+
expect(@output).to include("Class: A")
|
61
|
+
expect(@output).to include("Foo method")
|
62
|
+
expect(@output).to include("Bar method")
|
63
63
|
end
|
64
64
|
end
|
@@ -3,144 +3,141 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe YARD::Templates::Section do
|
4
4
|
include YARD::Templates
|
5
5
|
|
6
|
-
describe
|
7
|
-
it "
|
6
|
+
describe "#initialize" do
|
7
|
+
it "converts first argument to splat if it is array" do
|
8
8
|
s = Section.new(:name, [:foo, :bar])
|
9
|
-
s.name.
|
10
|
-
s[0].name.
|
11
|
-
s[1].name.
|
9
|
+
expect(s.name).to eq :name
|
10
|
+
expect(s[0].name).to eq :foo
|
11
|
+
expect(s[1].name).to eq :bar
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "allows initialization with Section objects" do
|
15
15
|
s = Section.new(:name, [:foo, Section.new(:bar)])
|
16
|
-
s.name.
|
17
|
-
s[0].
|
18
|
-
s[1].
|
16
|
+
expect(s.name).to eq :name
|
17
|
+
expect(s[0]).to eq Section.new(:foo)
|
18
|
+
expect(s[1]).to eq Section.new(:bar)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "makes a list of sections" do
|
22
22
|
s = Section.new(:name, [:foo, [:bar]])
|
23
|
-
s.
|
23
|
+
expect(s).to eq Section.new(:name, Section.new(:foo, Section.new(:bar)))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
28
|
-
it "
|
29
|
-
Section.new(:name, [:foo, :bar])[0].name.
|
27
|
+
describe "#[]" do
|
28
|
+
it "uses Array#[] if argument is integer" do
|
29
|
+
expect(Section.new(:name, [:foo, :bar])[0].name).to eq :foo
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
33
|
-
Section.new(:name, :foo, :bar, :baz)[1, 2].
|
34
|
-
Section.new(:name, :bar, :baz)
|
32
|
+
it "returns new Section object if more than one argument" do
|
33
|
+
expect(Section.new(:name, :foo, :bar, :baz)[1, 2]).to eq Section.new(:name, :bar, :baz)
|
35
34
|
end
|
36
35
|
|
37
|
-
it "
|
38
|
-
Section.new(:name, :foo, :bar, :baz)[1..2].
|
39
|
-
Section.new(:name, :bar, :baz)
|
36
|
+
it "returns new Section object if arg is Range" do
|
37
|
+
expect(Section.new(:name, :foo, :bar, :baz)[1..2]).to eq Section.new(:name, :bar, :baz)
|
40
38
|
end
|
41
39
|
|
42
|
-
it "
|
43
|
-
Section.new(:name, :foo, :bar, [:baz])[:bar][:baz].
|
44
|
-
Section.new(:baz)
|
40
|
+
it "looks for section by name if arg is object" do
|
41
|
+
expect(Section.new(:name, :foo, :bar, [:baz])[:bar][:baz]).to eq Section.new(:baz)
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
48
|
-
describe
|
49
|
-
it "
|
50
|
-
Section.new(:foo, [:a, :b]).
|
51
|
-
Section.new(:foo, [:a, :b]).
|
45
|
+
describe "#eql?" do
|
46
|
+
it "checks for equality of two equal sections" do
|
47
|
+
expect(Section.new(:foo, [:a, :b])).to eql(Section.new(:foo, :a, :b))
|
48
|
+
expect(Section.new(:foo, [:a, :b])).to eq Section.new(:foo, :a, :b)
|
52
49
|
end
|
53
50
|
|
54
|
-
it "
|
55
|
-
Section.new(:foo, [:a, :b]).
|
56
|
-
Section.new(:foo, [:a, :b]).
|
51
|
+
it "is not equal if section names are different" do
|
52
|
+
expect(Section.new(:foo, [:a, :b])).not_to eql(Section.new(:bar, :a, :b))
|
53
|
+
expect(Section.new(:foo, [:a, :b])).not_to eq Section.new(:bar, :a, :b)
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
describe
|
61
|
-
it "
|
62
|
-
Section.new(:foo, 2, 3).
|
57
|
+
describe "#==" do
|
58
|
+
it "allows comparison to Symbol" do
|
59
|
+
expect(Section.new(:foo, 2, 3)).to eq :foo
|
63
60
|
end
|
64
61
|
|
65
|
-
it "
|
66
|
-
Section.new("foo", 2, 3).
|
62
|
+
it "allows comparison to String" do
|
63
|
+
expect(Section.new("foo", 2, 3)).to eq "foo"
|
67
64
|
end
|
68
65
|
|
69
|
-
it "
|
66
|
+
it "allows comparison to Template" do
|
70
67
|
t = YARD::Templates::Engine.template!(:xyzzy, '/full/path/xyzzy')
|
71
|
-
Section.new(t, 2, 3).
|
68
|
+
expect(Section.new(t, 2, 3)).to eq t
|
72
69
|
end
|
73
70
|
|
74
|
-
it "
|
75
|
-
Section.new(1, [2, 3]).
|
71
|
+
it "allows comparison to Section" do
|
72
|
+
expect(Section.new(1, [2, 3])).to eq Section.new(1, 2, 3)
|
76
73
|
end
|
77
74
|
|
78
|
-
it "
|
79
|
-
Section.new(1, [2, 3]).
|
75
|
+
it "allows comparison to Object" do
|
76
|
+
expect(Section.new(1, [2, 3])).to eq 1
|
80
77
|
end
|
81
78
|
|
82
|
-
it "
|
83
|
-
Section.new(1, 2, [3]).
|
79
|
+
it "allows comparison to Array" do
|
80
|
+
expect(Section.new(1, 2, [3])).to eq [1, [2, [3]]]
|
84
81
|
end
|
85
82
|
end
|
86
83
|
|
87
|
-
describe
|
88
|
-
it "
|
84
|
+
describe "#to_a" do
|
85
|
+
it "converts Section to regular Array list" do
|
89
86
|
arr = Section.new(1, 2, [3, [4]]).to_a
|
90
|
-
arr.class.
|
91
|
-
arr.
|
87
|
+
expect(arr.class).to eq Array
|
88
|
+
expect(arr).to eq [1, [2, [3, [4]]]]
|
92
89
|
end
|
93
90
|
end
|
94
91
|
|
95
|
-
describe
|
96
|
-
it "
|
97
|
-
Section.new(1, 2, 3).place(4).before(3).
|
92
|
+
describe "#place" do
|
93
|
+
it "places objects as Sections" do
|
94
|
+
expect(Section.new(1, 2, 3).place(4).before(3)).to eq [1, [2, 4, 3]]
|
98
95
|
end
|
99
96
|
|
100
|
-
it "
|
101
|
-
Section.new(1, 2, [3, [4]]).place(5).after_any(4).
|
102
|
-
Section.new(1, 2, [3, [4]]).place(5).before_any(4).
|
97
|
+
it "places objects anywhere inside Section with before/after_any" do
|
98
|
+
expect(Section.new(1, 2, [3, [4]]).place(5).after_any(4)).to eq [1, [2, [3, [4, 5]]]]
|
99
|
+
expect(Section.new(1, 2, [3, [4]]).place(5).before_any(4)).to eq [1, [2, [3, [5, 4]]]]
|
103
100
|
end
|
104
101
|
|
105
|
-
it "
|
106
|
-
Section.new(1, 2, 3).place(4, 5).after(3).to_a.
|
107
|
-
Section.new(1, 2, 3).place(4, [5]).after(3).to_a.
|
102
|
+
it "allows multiple sections to be placed" do
|
103
|
+
expect(Section.new(1, 2, 3).place(4, 5).after(3).to_a).to eq [1, [2, 3, 4, 5]]
|
104
|
+
expect(Section.new(1, 2, 3).place(4, [5]).after(3).to_a).to eq [1, [2, 3, 4, [5]]]
|
108
105
|
end
|
109
106
|
end
|
110
107
|
|
111
|
-
describe
|
112
|
-
it "
|
108
|
+
describe "#push" do
|
109
|
+
it "pushes objects as Sections" do
|
113
110
|
s = Section.new(:foo)
|
114
111
|
s.push :bar
|
115
|
-
s[0].
|
112
|
+
expect(s[0]).to eq Section.new(:bar)
|
116
113
|
end
|
117
114
|
|
118
|
-
it "
|
115
|
+
it "is aliased as #<<" do
|
119
116
|
s = Section.new(1)
|
120
117
|
s << :index
|
121
|
-
s[:index].
|
118
|
+
expect(s[:index]).to be_a(Section)
|
122
119
|
end
|
123
120
|
end
|
124
121
|
|
125
|
-
describe
|
126
|
-
it "
|
122
|
+
describe "#unshift" do
|
123
|
+
it "unshifts objects as Sections" do
|
127
124
|
s = Section.new(:foo)
|
128
125
|
s.unshift :bar
|
129
|
-
s[0].
|
126
|
+
expect(s[0]).to eq Section.new(:bar)
|
130
127
|
end
|
131
128
|
end
|
132
129
|
|
133
|
-
describe
|
134
|
-
it "
|
130
|
+
describe "#any" do
|
131
|
+
it "finds item inside sections" do
|
135
132
|
s = Section.new(:foo, Section.new(:bar, Section.new(:bar)))
|
136
133
|
s.any(:bar).push(:baz)
|
137
|
-
s.to_a.
|
134
|
+
expect(s.to_a).to eq [:foo, [:bar, [:bar, :baz]]]
|
138
135
|
end
|
139
136
|
|
140
|
-
it "
|
137
|
+
it "finds item in any deeply nested set of sections" do
|
141
138
|
s = Section.new(:foo, Section.new(:bar, Section.new(:baz)))
|
142
139
|
s.any(:baz).push(:qux)
|
143
|
-
s.to_a.
|
140
|
+
expect(s.to_a).to eq [:foo, [:bar, [:baz, [:qux]]]]
|
144
141
|
end
|
145
142
|
end
|
146
143
|
end
|
data/spec/templates/tag_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe YARD::Templates::Engine.template(:default, :tags) do
|
4
4
|
before { Registry.clear }
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe "all known tags" do
|
7
7
|
before do
|
8
8
|
YARD.parse_string <<-'eof'
|
9
9
|
# Comments
|
@@ -32,20 +32,20 @@ describe YARD::Templates::Engine.template(:default, :tags) do
|
|
32
32
|
eof
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "renders text format correctly" do
|
36
36
|
text_equals(Registry.at('#m').format(text_options), :tag001)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
41
|
-
it
|
40
|
+
describe "param tags on non-methods" do
|
41
|
+
it "does not display @param tags on non-method objects" do
|
42
42
|
YARD.parse_string <<-'eof'
|
43
43
|
# @param [#to_s] name the name
|
44
44
|
module Foo; end
|
45
45
|
eof
|
46
46
|
|
47
47
|
proc = lambda { Registry.at('Foo').format(html_options) }
|
48
|
-
proc.
|
48
|
+
expect(proc).not_to raise_error
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -9,282 +9,282 @@ describe YARD::Templates::Template do
|
|
9
9
|
YARD::Templates::ErbCache.clear!
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it "
|
12
|
+
describe ".include_parent" do
|
13
|
+
it "does not include parent directory if parent directory is a template root path" do
|
14
14
|
mod = template('q')
|
15
|
-
mod.
|
15
|
+
expect(mod).not_to include(template(''))
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
19
|
-
Engine.
|
20
|
-
File.
|
21
|
-
File.
|
22
|
-
File.
|
23
|
-
File.
|
18
|
+
it "includes overridden parent directory" do
|
19
|
+
allow(Engine).to receive(:template_paths).and_return(['/foo', '/bar'])
|
20
|
+
expect(File).to receive(:directory?).with('/foo/a/b').and_return(true)
|
21
|
+
expect(File).to receive(:directory?).with('/bar/a/b').and_return(false)
|
22
|
+
expect(File).to receive(:directory?).with('/foo/a').at_least(1).times.and_return(true)
|
23
|
+
expect(File).to receive(:directory?).with('/bar/a').at_least(1).times.and_return(true)
|
24
24
|
ancestors = Engine.template('a/b').ancestors.map {|c| c.class_name }
|
25
|
-
ancestors[0, 3].
|
25
|
+
expect(ancestors[0, 3]).to eq %w( Template__foo_a_b Template__bar_a Template__foo_a )
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "includes parent directory template if exists" do
|
29
29
|
mod1 = template('x')
|
30
30
|
mod2 = template('x/y')
|
31
|
-
mod2.
|
31
|
+
expect(mod2).to include(mod1)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
36
|
-
it "
|
35
|
+
describe ".full_paths" do
|
36
|
+
it "lists full_path" do
|
37
37
|
mod = template(:a)
|
38
|
-
mod.full_paths.
|
38
|
+
expect(mod.full_paths).to eq ['/full/path/a']
|
39
39
|
end
|
40
40
|
|
41
|
-
it "
|
41
|
+
it "lists paths of included modules" do
|
42
42
|
mod = template(:a)
|
43
43
|
mod.send(:include, template(:b))
|
44
|
-
mod.full_paths.
|
44
|
+
expect(mod.full_paths).to eq ['/full/path/a', '/full/path/b']
|
45
45
|
end
|
46
46
|
|
47
|
-
it "
|
47
|
+
it "lists paths from modules of included modules" do
|
48
48
|
mod = template(:c)
|
49
49
|
mod.send(:include, template(:d))
|
50
50
|
mod.send(:include, template(:a))
|
51
|
-
mod.full_paths.
|
51
|
+
expect(mod.full_paths).to eq ['c', 'a', 'b', 'd'].map {|o| '/full/path/' + o }
|
52
52
|
end
|
53
53
|
|
54
|
-
it "
|
54
|
+
it "only lists full paths of modules that respond to full_paths" do
|
55
55
|
mod = template(:d)
|
56
56
|
mod.send(:include, Enumerable)
|
57
|
-
mod.full_paths.
|
57
|
+
expect(mod.full_paths).to eq ['/full/path/d']
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe
|
62
|
-
it "
|
63
|
-
File.
|
64
|
-
File.
|
65
|
-
template(:e).new.
|
61
|
+
describe ".load_setup_rb" do
|
62
|
+
it "loads setup.rb file for module" do
|
63
|
+
expect(File).to receive(:file?).with('/full/path/e/setup.rb').and_return(true)
|
64
|
+
expect(File).to receive(:read).with('/full/path/e/setup.rb').and_return('def success; end')
|
65
|
+
expect(template(:e).new).to respond_to(:success)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe
|
70
|
-
it "
|
69
|
+
describe ".T" do
|
70
|
+
it "loads template from absolute path" do
|
71
71
|
mod = template(:a)
|
72
|
-
Engine.
|
72
|
+
expect(Engine).to receive(:template).with('other')
|
73
73
|
mod.T('other')
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
78
|
-
it "
|
79
|
-
File.
|
80
|
-
File.
|
81
|
-
template(:a).find_file('basename').
|
77
|
+
describe ".find_file" do
|
78
|
+
it "finds file in the module's full_path" do
|
79
|
+
expect(File).to receive(:file?).with('/full/path/a/basename').and_return(false)
|
80
|
+
expect(File).to receive(:file?).with('/full/path/b/basename').and_return(true)
|
81
|
+
expect(template(:a).find_file('basename')).to eq '/full/path/b/basename'
|
82
82
|
end
|
83
83
|
|
84
|
-
it "
|
85
|
-
File.
|
86
|
-
File.
|
87
|
-
template(:a).find_file('basename').
|
84
|
+
it "returns nil if no file is found" do
|
85
|
+
expect(File).to receive(:file?).with('/full/path/a/basename').and_return(false)
|
86
|
+
expect(File).to receive(:file?).with('/full/path/b/basename').and_return(false)
|
87
|
+
expect(template(:a).find_file('basename')).to be nil
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
describe
|
92
|
-
it "
|
93
|
-
File.
|
94
|
-
File.
|
95
|
-
template(:a).find_nth_file('basename', 2).
|
91
|
+
describe ".find_nth_file" do
|
92
|
+
it "finds 2nd existing file in template paths" do
|
93
|
+
expect(File).to receive(:file?).with('/full/path/a/basename').and_return(true)
|
94
|
+
expect(File).to receive(:file?).with('/full/path/b/basename').and_return(true)
|
95
|
+
expect(template(:a).find_nth_file('basename', 2)).to eq '/full/path/b/basename'
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
99
|
-
File.
|
100
|
-
File.
|
101
|
-
template(:a).find_nth_file('basename', 3).
|
98
|
+
it "returns nil if no file is found" do
|
99
|
+
expect(File).to receive(:file?).with('/full/path/a/basename').and_return(true)
|
100
|
+
expect(File).to receive(:file?).with('/full/path/b/basename').and_return(true)
|
101
|
+
expect(template(:a).find_nth_file('basename', 3)).to be nil
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe
|
106
|
-
it "
|
105
|
+
describe ".extra_includes" do
|
106
|
+
it "is included when a module is initialized" do
|
107
107
|
module MyModule; end
|
108
108
|
Template.extra_includes << MyModule
|
109
|
-
template(:e).new.
|
109
|
+
expect(template(:e).new).to be_kind_of(MyModule)
|
110
110
|
end
|
111
111
|
|
112
|
-
it "
|
112
|
+
it "supports lambdas in list" do
|
113
113
|
module MyModule2; end
|
114
114
|
Template.extra_includes << lambda {|opts| MyModule2 if opts.format == :html }
|
115
|
-
template(:f).new(:format => :html).
|
115
|
+
expect(template(:f).new(:format => :html)).to be_kind_of(MyModule2)
|
116
116
|
metaclass = (class << template(:g).new(:format => :text); self end)
|
117
|
-
metaclass.ancestors.
|
117
|
+
expect(metaclass.ancestors).not_to include(MyModule2)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
describe
|
122
|
-
it "
|
123
|
-
template(:e).is_a?(Template).
|
121
|
+
describe ".is_a?" do
|
122
|
+
it "is kind of Template" do
|
123
|
+
expect(template(:e).is_a?(Template)).to be true
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
describe
|
128
|
-
it "
|
129
|
-
template(:e).
|
127
|
+
describe "#T" do
|
128
|
+
it "delegates to class method" do
|
129
|
+
expect(template(:e)).to receive(:T).with('test')
|
130
130
|
template(:e).new.T('test')
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe
|
135
|
-
it "
|
134
|
+
describe "#init" do
|
135
|
+
it "is called during initialization" do
|
136
136
|
module YARD::Templates::Engine::Template__full_path_e
|
137
137
|
def init; sections 1, 2, 3 end
|
138
138
|
end
|
139
|
-
template(:e).new.sections.
|
139
|
+
expect(template(:e).new.sections).to eq Section.new(nil, 1, 2, 3)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
describe
|
144
|
-
it "
|
145
|
-
File.
|
146
|
-
IO.
|
147
|
-
template(:e).new.file('abc').
|
143
|
+
describe "#file" do
|
144
|
+
it "reads the file if it exists" do
|
145
|
+
expect(File).to receive(:file?).with('/full/path/e/abc').and_return(true)
|
146
|
+
expect(IO).to receive(:read).with('/full/path/e/abc').and_return('hello world')
|
147
|
+
expect(template(:e).new.file('abc')).to eq 'hello world'
|
148
148
|
end
|
149
149
|
|
150
|
-
it "
|
151
|
-
File.
|
152
|
-
|
150
|
+
it "raises ArgumentError if the file does not exist" do
|
151
|
+
expect(File).to receive(:file?).with('/full/path/e/abc').and_return(false)
|
152
|
+
expect { template(:e).new.file('abc') }.to raise_error(ArgumentError)
|
153
153
|
end
|
154
154
|
|
155
|
-
it "
|
156
|
-
File.
|
157
|
-
File.
|
158
|
-
IO.
|
159
|
-
IO.
|
160
|
-
template(:a).new.file('abc', true).
|
155
|
+
it "replaces {{{__super__}}} with inherited template contents if allow_inherited=true" do
|
156
|
+
expect(File).to receive(:file?).with('/full/path/a/abc').twice.and_return(true)
|
157
|
+
expect(File).to receive(:file?).with('/full/path/b/abc').and_return(true)
|
158
|
+
expect(IO).to receive(:read).with('/full/path/a/abc').and_return('foo {{{__super__}}}')
|
159
|
+
expect(IO).to receive(:read).with('/full/path/b/abc').and_return('bar')
|
160
|
+
expect(template(:a).new.file('abc', true)).to eq "foo bar"
|
161
161
|
end
|
162
162
|
|
163
|
-
it "
|
164
|
-
File.
|
165
|
-
IO.
|
166
|
-
template(:a).new.file('abc').
|
163
|
+
it "does not replace {{{__super__}}} with inherited template contents if allow_inherited=false" do
|
164
|
+
expect(File).to receive(:file?).with('/full/path/a/abc').and_return(true)
|
165
|
+
expect(IO).to receive(:read).with('/full/path/a/abc').and_return('foo {{{__super__}}}')
|
166
|
+
expect(template(:a).new.file('abc')).to eq "foo {{{__super__}}}"
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
describe
|
171
|
-
it "
|
172
|
-
File.
|
173
|
-
File.
|
174
|
-
IO.
|
170
|
+
describe "#superb" do
|
171
|
+
it "returns the inherited erb template contents" do
|
172
|
+
expect(File).to receive(:file?).with('/full/path/a/test.erb').and_return(true)
|
173
|
+
expect(File).to receive(:file?).with('/full/path/b/test.erb').and_return(true)
|
174
|
+
expect(IO).to receive(:read).with('/full/path/b/test.erb').and_return('bar')
|
175
175
|
template = template(:a).new
|
176
176
|
template.section = :test
|
177
|
-
template.superb.
|
177
|
+
expect(template.superb).to eq "bar"
|
178
178
|
end
|
179
179
|
|
180
|
-
it "
|
181
|
-
File.
|
182
|
-
File.
|
183
|
-
IO.
|
184
|
-
IO.
|
180
|
+
it "works inside an erb template" do
|
181
|
+
expect(File).to receive(:file?).with('/full/path/a/test.erb').twice.and_return(true)
|
182
|
+
expect(File).to receive(:file?).with('/full/path/b/test.erb').and_return(true)
|
183
|
+
expect(IO).to receive(:read).with('/full/path/a/test.erb').and_return('foo<%= superb %>!')
|
184
|
+
expect(IO).to receive(:read).with('/full/path/b/test.erb').and_return('bar')
|
185
185
|
template = template(:a).new
|
186
186
|
template.section = :test
|
187
|
-
template.erb(:test).
|
187
|
+
expect(template.erb(:test)).to eq "foobar!"
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
describe
|
192
|
-
it "
|
191
|
+
describe "#sections" do
|
192
|
+
it "allows sections to be set if arguments are provided" do
|
193
193
|
mod = template(:e).new
|
194
194
|
mod.sections 1, 2, [3]
|
195
|
-
mod.sections.
|
195
|
+
expect(mod.sections).to eq Section.new(nil, 1, 2, [3])
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
-
describe
|
200
|
-
it "
|
199
|
+
describe "#run" do
|
200
|
+
it "renders all sections" do
|
201
201
|
mod = template(:e).new
|
202
|
-
mod.
|
203
|
-
mod.should_receive(:render_section).with(Section.new(:b)).and_return('b')
|
204
|
-
mod.should_receive(:render_section).with(Section.new(:c)).and_return('c')
|
202
|
+
allow(mod).to receive(:render_section) { |section| section.name.to_s }
|
205
203
|
mod.sections :a, :b, :c
|
206
|
-
mod.run.
|
204
|
+
expect(mod.run).to eq 'abc'
|
207
205
|
end
|
208
206
|
|
209
|
-
it "
|
207
|
+
it "renders all sections with options" do
|
210
208
|
mod = template(:e).new
|
211
|
-
mod.
|
212
|
-
mod.
|
209
|
+
allow(mod).to receive(:render_section) { |section| section.name.to_s }
|
210
|
+
expect(mod).to receive(:add_options).with(:a => 1).and_yield
|
213
211
|
mod.sections :a
|
214
|
-
mod.run(:a => 1).
|
212
|
+
expect(mod.run(:a => 1)).to eq 'a'
|
215
213
|
end
|
216
214
|
|
217
|
-
it "
|
215
|
+
it "runs section list if provided" do
|
218
216
|
mod = template(:e).new
|
219
|
-
mod.
|
220
|
-
|
217
|
+
expect(mod).to receive(:render_section).exactly(2).times do |section|
|
218
|
+
expect([:q, :x]).to include(section.name)
|
219
|
+
section.name.to_s
|
220
|
+
end
|
221
221
|
mod.run({}, [:q, :x])
|
222
222
|
end
|
223
223
|
|
224
|
-
it "
|
224
|
+
it "accepts a nil section as empty string" do
|
225
225
|
mod = template(:e).new
|
226
|
-
mod.
|
226
|
+
allow(mod).to receive(:render_section) { nil }
|
227
227
|
mod.sections :a
|
228
|
-
mod.run.
|
228
|
+
expect(mod.run).to eq ""
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
-
describe
|
233
|
-
it "
|
232
|
+
describe "#add_options" do
|
233
|
+
it "sets instance variables in addition to options" do
|
234
234
|
mod = template(:f).new
|
235
235
|
mod.send(:add_options, {:a => 1, :b => 2})
|
236
|
-
mod.options.
|
237
|
-
mod.instance_variable_get("@a").
|
238
|
-
mod.instance_variable_get("@b").
|
236
|
+
expect(mod.options).to eq({:a => 1, :b => 2})
|
237
|
+
expect(mod.instance_variable_get("@a")).to eq 1
|
238
|
+
expect(mod.instance_variable_get("@b")).to eq 2
|
239
239
|
end
|
240
240
|
|
241
|
-
it "
|
241
|
+
it "sets instance variables and options only for the block" do
|
242
242
|
mod = template(:f).new
|
243
243
|
mod.send(:add_options, {:a => 100, :b => 200}) do
|
244
|
-
mod.options.
|
244
|
+
expect(mod.options).to eq({:a => 100, :b => 200})
|
245
245
|
end
|
246
|
-
mod.options.
|
246
|
+
expect(mod.options).not_to eq({:a => 100, :b => 200})
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
describe
|
251
|
-
it "
|
250
|
+
describe "#render_section" do
|
251
|
+
it "calls method if method exists by section name as Symbol" do
|
252
252
|
mod = template(:f).new
|
253
|
-
mod.
|
254
|
-
mod.
|
255
|
-
mod.
|
256
|
-
mod.
|
257
|
-
mod.run({}, [:a, 'a']).
|
253
|
+
expect(mod).to receive(:respond_to?).with(:a).and_return(true)
|
254
|
+
expect(mod).to receive(:respond_to?).with('a').and_return(true)
|
255
|
+
expect(mod).to receive(:send).with(:a).and_return('a')
|
256
|
+
expect(mod).to receive(:send).with('a').and_return('a')
|
257
|
+
expect(mod.run({}, [:a, 'a'])).to eq 'aa'
|
258
258
|
end
|
259
259
|
|
260
|
-
it "
|
260
|
+
it "calls erb if no method exists by section name" do
|
261
261
|
mod = template(:f).new
|
262
|
-
mod.
|
263
|
-
mod.
|
264
|
-
mod.
|
265
|
-
mod.
|
266
|
-
mod.run({}, [:a, 'a']).
|
262
|
+
expect(mod).to receive(:respond_to?).with(:a).and_return(false)
|
263
|
+
expect(mod).to receive(:respond_to?).with('a').and_return(false)
|
264
|
+
expect(mod).to receive(:erb).with(:a).and_return('a')
|
265
|
+
expect(mod).to receive(:erb).with('a').and_return('a')
|
266
|
+
expect(mod.run({}, [:a, 'a'])).to eq 'aa'
|
267
267
|
end
|
268
268
|
|
269
|
-
it "
|
269
|
+
it "runs a template if section is one" do
|
270
270
|
mod2 = template(:g)
|
271
|
-
mod2.
|
271
|
+
expect(mod2).to receive(:run)
|
272
272
|
mod = template(:f).new
|
273
273
|
mod.sections mod2
|
274
274
|
mod.run
|
275
275
|
end
|
276
276
|
|
277
|
-
it "
|
277
|
+
it "runs a template instance if section is one" do
|
278
278
|
mod2 = template(:g).new
|
279
|
-
mod2.
|
279
|
+
expect(mod2).to receive(:run)
|
280
280
|
mod = template(:f).new
|
281
281
|
mod.sections mod2
|
282
282
|
mod.run
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
|
-
describe
|
287
|
-
it "
|
286
|
+
describe "#yield" do
|
287
|
+
it "yields a subsection" do
|
288
288
|
mod = template(:e).new
|
289
289
|
mod.sections :a, [:b, :c]
|
290
290
|
class << mod
|
@@ -293,10 +293,10 @@ describe YARD::Templates::Template do
|
|
293
293
|
def c; "c" end
|
294
294
|
end
|
295
295
|
|
296
|
-
mod.run.
|
296
|
+
expect(mod.run).to eq "(b)"
|
297
297
|
end
|
298
298
|
|
299
|
-
it "
|
299
|
+
it "yields a subsection within a yielded subsection" do
|
300
300
|
mod = template(:e).new
|
301
301
|
mod.sections :a, [:b, [:c]]
|
302
302
|
class << mod
|
@@ -305,10 +305,10 @@ describe YARD::Templates::Template do
|
|
305
305
|
def c; "c" end
|
306
306
|
end
|
307
307
|
|
308
|
-
mod.run.
|
308
|
+
expect(mod.run).to eq "(c)"
|
309
309
|
end
|
310
310
|
|
311
|
-
it "
|
311
|
+
it "supports arbitrary nesting" do
|
312
312
|
mod = template(:e).new
|
313
313
|
mod.sections :a, [:b, [:c, [:d, [:e]]]]
|
314
314
|
class << mod
|
@@ -319,10 +319,10 @@ describe YARD::Templates::Template do
|
|
319
319
|
def e; "e" end
|
320
320
|
end
|
321
321
|
|
322
|
-
mod.run.
|
322
|
+
expect(mod.run).to eq "(e)"
|
323
323
|
end
|
324
324
|
|
325
|
-
it "
|
325
|
+
it "yields first two elements if yield is called twice" do
|
326
326
|
mod = template(:e).new
|
327
327
|
mod.sections :a, [:b, :c, :d]
|
328
328
|
class << mod
|
@@ -331,10 +331,10 @@ describe YARD::Templates::Template do
|
|
331
331
|
def c; "c" end
|
332
332
|
end
|
333
333
|
|
334
|
-
mod.run.
|
334
|
+
expect(mod.run).to eq "(bc)"
|
335
335
|
end
|
336
336
|
|
337
|
-
it "
|
337
|
+
it "ignores any subsections inside subsection yields" do
|
338
338
|
mod = template(:e).new
|
339
339
|
mod.sections :a, [:b, [:c], :d]
|
340
340
|
class << mod
|
@@ -343,10 +343,10 @@ describe YARD::Templates::Template do
|
|
343
343
|
def d; "d" end
|
344
344
|
end
|
345
345
|
|
346
|
-
mod.run.
|
346
|
+
expect(mod.run).to eq "(bd)"
|
347
347
|
end
|
348
348
|
|
349
|
-
it "
|
349
|
+
it "allows extra options passed via yield" do
|
350
350
|
mod = template(:e).new
|
351
351
|
mod.sections :a, [:b]
|
352
352
|
class << mod
|
@@ -354,12 +354,12 @@ describe YARD::Templates::Template do
|
|
354
354
|
def b; options.x + @x end
|
355
355
|
end
|
356
356
|
|
357
|
-
mod.run.
|
357
|
+
expect(mod.run).to eq "(aa)"
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
-
describe
|
362
|
-
it "
|
361
|
+
describe "#yieldall" do
|
362
|
+
it "yields all subsections" do
|
363
363
|
mod = template(:e).new
|
364
364
|
mod.sections :a, [:b, [:d, [:e]], :c]
|
365
365
|
class << mod
|
@@ -370,10 +370,10 @@ describe YARD::Templates::Template do
|
|
370
370
|
def e; 'e' end
|
371
371
|
end
|
372
372
|
|
373
|
-
mod.run.
|
373
|
+
expect(mod.run).to eq "(bdec)"
|
374
374
|
end
|
375
375
|
|
376
|
-
it "
|
376
|
+
it "yields options to all subsections" do
|
377
377
|
mod = template(:e).new
|
378
378
|
mod.sections :a, [:b, :c]
|
379
379
|
class << mod
|
@@ -381,10 +381,10 @@ describe YARD::Templates::Template do
|
|
381
381
|
def b; @x end
|
382
382
|
def c; @x end
|
383
383
|
end
|
384
|
-
mod.run.
|
384
|
+
expect(mod.run).to eq "(22)"
|
385
385
|
end
|
386
386
|
|
387
|
-
it "
|
387
|
+
it "yields all subsections more than once" do
|
388
388
|
mod = template(:e).new
|
389
389
|
mod.sections :a, [:b]
|
390
390
|
class << mod
|
@@ -392,10 +392,10 @@ describe YARD::Templates::Template do
|
|
392
392
|
def b; "b" end
|
393
393
|
end
|
394
394
|
|
395
|
-
mod.run.
|
395
|
+
expect(mod.run).to eq "(bb)"
|
396
396
|
end
|
397
397
|
|
398
|
-
it "
|
398
|
+
it "does not yield if no yieldall is called" do
|
399
399
|
mod = template(:e).new
|
400
400
|
mod.sections :a, [:b]
|
401
401
|
class << mod
|
@@ -403,7 +403,7 @@ describe YARD::Templates::Template do
|
|
403
403
|
def b; "b" end
|
404
404
|
end
|
405
405
|
|
406
|
-
mod.run.
|
406
|
+
expect(mod.run).to eq "()"
|
407
407
|
end
|
408
408
|
end
|
409
409
|
end
|