puppet-strings 2.2.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +87 -1
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +5 -3
  6. data/lib/puppet-strings/describe.rb +2 -0
  7. data/lib/puppet-strings/json.rb +4 -0
  8. data/lib/puppet-strings/markdown.rb +13 -9
  9. data/lib/puppet-strings/markdown/base.rb +30 -3
  10. data/lib/puppet-strings/markdown/data_type.rb +36 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +43 -0
  12. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  13. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  14. data/lib/puppet-strings/markdown/function.rb +9 -7
  15. data/lib/puppet-strings/markdown/functions.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  20. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  21. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  22. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  23. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  24. data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
  25. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
  26. data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
  27. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  28. data/lib/puppet-strings/markdown/templates/function.erb +10 -1
  29. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  30. data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
  31. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  32. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  33. data/lib/puppet-strings/tasks.rb +2 -0
  34. data/lib/puppet-strings/tasks/generate.rb +5 -2
  35. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  36. data/lib/puppet-strings/version.rb +3 -1
  37. data/lib/puppet-strings/yard.rb +19 -0
  38. data/lib/puppet-strings/yard/code_objects.rb +4 -0
  39. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
  41. data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
  42. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
  43. data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
  44. data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
  45. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  46. data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
  47. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  48. data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
  49. data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
  50. data/lib/puppet-strings/yard/handlers.rb +4 -0
  51. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  59. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  60. data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
  61. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
  63. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  64. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
  65. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
  66. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
  67. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  68. data/lib/puppet-strings/yard/parsers.rb +2 -0
  69. data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
  70. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
  72. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
  73. data/lib/puppet-strings/yard/tags.rb +4 -0
  74. data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
  75. data/lib/puppet-strings/yard/tags/factory.rb +18 -0
  76. data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
  77. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  78. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  80. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  81. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  82. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  83. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  85. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  86. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  87. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  88. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  89. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  90. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  91. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  92. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  93. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  94. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  95. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  96. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  97. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  98. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  99. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  100. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  101. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  102. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  103. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  104. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  105. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  106. data/lib/puppet-strings/yard/util.rb +7 -4
  107. data/lib/puppet/application/strings.rb +2 -0
  108. data/lib/puppet/face/strings.rb +7 -4
  109. data/lib/puppet/feature/rgen.rb +2 -0
  110. data/lib/puppet/feature/yard.rb +2 -0
  111. metadata +35 -45
  112. data/Gemfile +0 -38
  113. data/HISTORY.md +0 -218
  114. data/JSON.md +0 -802
  115. data/Rakefile +0 -98
  116. data/codecov.yml +0 -3
  117. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  118. data/spec/acceptance/emit_json_options.rb +0 -71
  119. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  120. data/spec/acceptance/lib/util.rb +0 -163
  121. data/spec/acceptance/running_strings_generate.rb +0 -54
  122. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  123. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  124. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  125. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  126. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  127. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  128. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  129. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  130. data/spec/fixtures/unit/markdown/output.md +0 -508
  131. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
  132. data/spec/spec_helper.rb +0 -46
  133. data/spec/spec_helper_acceptance.rb +0 -28
  134. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  135. data/spec/unit/puppet-strings/json_spec.rb +0 -283
  136. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  137. data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
  138. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  139. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  140. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  141. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  142. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  143. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  144. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  145. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  146. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
  147. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  148. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  149. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  150. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::JSON::TaskHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :json)
7
- YARD::Registry.all(:puppet_task)
8
- }
9
-
10
- describe 'parsing task metadata with a syntax error' do
11
- let(:source) { <<-SOURCE
12
- {
13
- "input_method": "stdin",
14
- "parameters":
15
- "database": {
16
- "description": "Database to connect to",
17
- "type": "Optional[String[1]]"
18
- }
19
- }
20
- }
21
- SOURCE
22
- }
23
-
24
- it 'should log an error' do
25
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\):/).to_stdout_from_any_process
26
- expect(subject.empty?).to eq(true)
27
- end
28
- end
29
-
30
- describe 'parsing task metadata with a missing description' do
31
- let(:source) { <<-SOURCE
32
- {
33
- "input_method": "stdin",
34
- "parameters": {
35
- "database": {
36
- "description": "Database to connect to",
37
- "type": "Optional[String[1]]"
38
- },
39
- "user": {
40
- "description": "The user",
41
- "type": "Optional[String[1]]"
42
- },
43
- "password": {
44
- "description": "The password",
45
- "type": "Optional[String[1]]"
46
- },
47
- "sql": {
48
- "description": "Path to file you want backup to",
49
- "type": "String[1]"
50
- }
51
- }
52
- }
53
- SOURCE
54
- }
55
-
56
- it 'should log a warning' do
57
- expect{ subject }.to output(/\[warn\]: Missing a description for Puppet Task \(stdin\)/).to_stdout_from_any_process
58
- end
59
- end
60
-
61
- describe 'parsing task metadata with a description' do
62
- let(:source) { <<-SOURCE
63
- {
64
- "description": "Allows you to backup your database to local file.",
65
- "input_method": "stdin",
66
- "parameters": {
67
- "database": {
68
- "description": "Database to connect to",
69
- "type": "Optional[String[1]]"
70
- },
71
- "user": {
72
- "description": "The user",
73
- "type": "Optional[String[1]]"
74
- },
75
- "password": {
76
- "description": "The password",
77
- "type": "Optional[String[1]]"
78
- },
79
- "sql": {
80
- "description": "Path to file you want backup to",
81
- "type": "String[1]"
82
- }
83
- }
84
- }
85
-
86
- SOURCE
87
- }
88
-
89
- it 'should register a task object' do
90
- expect(subject.size).to eq(1)
91
- object = subject.first
92
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Task)
93
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Tasks.instance)
94
- end
95
- end
96
-
97
- describe 'parsing task metadata with a missing parameter description' do
98
- let(:source) { <<-SOURCE
99
- {
100
- "description": "Allows you to backup your database to local file.",
101
- "input_method": "stdin",
102
- "parameters": {
103
- "database": {
104
- "type": "Optional[String[1]]"
105
- }
106
- }
107
- }
108
- SOURCE
109
- }
110
-
111
- it 'should output a warning' do
112
- expect{ subject }.to output(/\[warn\]: Missing description for param 'database' in Puppet Task \(stdin\)/).to_stdout_from_any_process
113
- end
114
- end
115
-
116
- end
@@ -1,217 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Puppet::ClassHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :puppet)
7
- YARD::Registry.all(:puppet_class)
8
- }
9
-
10
- describe 'parsing source without a class definition' do
11
- let(:source) { 'notice hi' }
12
-
13
- it 'no classes should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing source with a syntax error' do
19
- let(:source) { 'class foo{' }
20
-
21
- it 'should log an error' do
22
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process
23
- expect(subject.empty?).to eq(true)
24
- end
25
- end
26
-
27
- describe 'parsing a class with a missing docstring' do
28
- let(:source) { 'class foo{}' }
29
-
30
- it 'should log a warning' do
31
- expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet class 'foo' at \(stdin\):1\./).to_stdout_from_any_process
32
- end
33
- end
34
-
35
- describe 'parsing a class with a docstring' do
36
- let(:source) { <<-SOURCE
37
- # A simple foo class.
38
- # @param param1 First param.
39
- # @param param2 Second param.
40
- # @param param3 Third param.
41
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
42
- file { '/tmp/foo':
43
- ensure => present
44
- }
45
- }
46
- SOURCE
47
- }
48
-
49
- it 'should register a class object' do
50
- expect(subject.size).to eq(1)
51
- object = subject.first
52
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Class)
53
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Classes.instance)
54
- expect(object.name).to eq(:foo)
55
- expect(object.statement).not_to eq(nil)
56
- expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
57
- expect(object.docstring).to eq('A simple foo class.')
58
- expect(object.docstring.tags.size).to eq(4)
59
- tags = object.docstring.tags(:param)
60
- expect(tags.size).to eq(3)
61
- expect(tags[0].name).to eq('param1')
62
- expect(tags[0].text).to eq('First param.')
63
- expect(tags[0].types).to eq(['Integer'])
64
- expect(tags[1].name).to eq('param2')
65
- expect(tags[1].text).to eq('Second param.')
66
- expect(tags[1].types).to eq(['Any'])
67
- expect(tags[2].name).to eq('param3')
68
- expect(tags[2].text).to eq('Third param.')
69
- expect(tags[2].types).to eq(['String'])
70
- tags = object.docstring.tags(:api)
71
- expect(tags.size).to eq(1)
72
- expect(tags[0].text).to eq('public')
73
- end
74
- end
75
-
76
- describe 'parsing a class with a missing parameter' do
77
- let(:source) { <<-SOURCE
78
- # A simple foo class.
79
- # @param param1 First param.
80
- # @param param2 Second param.
81
- # @param param3 Third param.
82
- # @param param4 missing!
83
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
84
- file { '/tmp/foo':
85
- ensure => present
86
- }
87
- }
88
- SOURCE
89
- }
90
-
91
- it 'should output a warning' do
92
- expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
93
- end
94
- end
95
-
96
- describe 'parsing a class with a missing @param tag' do
97
- let(:source) { <<-SOURCE
98
- # A simple foo class.
99
- # @param param1 First param.
100
- # @param param2 Second param.
101
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
102
- file { '/tmp/foo':
103
- ensure => present
104
- }
105
- }
106
- SOURCE
107
- }
108
-
109
- it 'should output a warning' do
110
- expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
111
- end
112
- end
113
-
114
- describe 'parsing a class with a typed parameter that also has a @param tag type which matches' do
115
- let(:source) { <<-SOURCE
116
- # A simple foo class.
117
- # @param [Integer] param1 First param.
118
- # @param param2 Second param.
119
- # @param param3 Third param.
120
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
121
- file { '/tmp/foo':
122
- ensure => present
123
- }
124
- }
125
- SOURCE
126
- }
127
-
128
- it 'should respect the type that was documented' do
129
- expect{ subject }.to output('').to_stdout_from_any_process
130
- expect(subject.size).to eq(1)
131
- tags = subject.first.tags(:param)
132
- expect(tags.size).to eq(3)
133
- expect(tags[0].types).to eq(['Integer'])
134
- end
135
- end
136
-
137
- describe 'parsing a class with a typed parameter that also has a @param tag type which does not match' do
138
- let(:source) { <<-SOURCE
139
- # A simple foo class.
140
- # @param [Boolean] param1 First param.
141
- # @param param2 Second param.
142
- # @param param3 Third param.
143
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
144
- file { '/tmp/foo':
145
- ensure => present
146
- }
147
- }
148
- SOURCE
149
- }
150
-
151
- it 'should output a warning' do
152
- expect{ subject }.to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./).to_stdout_from_any_process
153
- end
154
- end
155
-
156
- describe 'parsing a class with a untyped parameter that also has a @param tag type' do
157
- let(:source) { <<-SOURCE
158
- # A simple foo class.
159
- # @param param1 First param.
160
- # @param [Boolean] param2 Second param.
161
- # @param param3 Third param.
162
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
163
- file { '/tmp/foo':
164
- ensure => present
165
- }
166
- }
167
- SOURCE
168
- }
169
-
170
- it 'should respect the type that was documented' do
171
- expect{ subject }.to output('').to_stdout_from_any_process
172
- expect(subject.size).to eq(1)
173
- tags = subject.first.tags(:param)
174
- expect(tags.size).to eq(3)
175
- expect(tags[1].types).to eq(['Boolean'])
176
- end
177
- end
178
-
179
- describe 'parsing a class with a summary' do
180
- context 'when the summary has fewer than 140 characters' do
181
- let(:source) { <<-SOURCE
182
- # A simple foo class.
183
- # @summary A short summary.
184
- class foo() {
185
- file { '/tmp/foo':
186
- ensure => present
187
- }
188
- }
189
- SOURCE
190
- }
191
-
192
- it 'should parse the summary' do
193
- expect{ subject }.to output('').to_stdout_from_any_process
194
- expect(subject.size).to eq(1)
195
- summary = subject.first.tags(:summary)
196
- expect(summary.first.text).to eq('A short summary.')
197
- end
198
- end
199
-
200
- context 'when the summary has more than 140 characters' do
201
- let(:source) { <<-SOURCE
202
- # A simple foo class.
203
- # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!
204
- class foo() {
205
- file { '/tmp/foo':
206
- ensure => present
207
- }
208
- }
209
- SOURCE
210
- }
211
-
212
- it 'should log a warning' do
213
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_class 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
214
- end
215
- end
216
- end
217
- end
@@ -1,231 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Puppet::DefinedTypeHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :puppet)
7
- YARD::Registry.all(:puppet_defined_type)
8
- }
9
-
10
- describe 'parsing source without a defined type definition' do
11
- let(:source) { 'notice hi' }
12
-
13
- it 'no defined types should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing source with a syntax error' do
19
- let(:source) { 'define foo{' }
20
-
21
- it 'should log an error' do
22
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process
23
- expect(subject.empty?).to eq(true)
24
- end
25
- end
26
-
27
- describe 'parsing a defined type with a missing docstring' do
28
- let(:source) { 'define foo{}' }
29
-
30
- it 'should log a warning' do
31
- expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet defined type 'foo' at \(stdin\):1\./).to_stdout_from_any_process
32
- end
33
- end
34
-
35
- describe 'parsing a defined type with a docstring' do
36
- let(:source) { <<-SOURCE
37
- # A simple foo defined type.
38
- # @param name The type name.
39
- # @param param1 First param.
40
- # @param param2 Second param.
41
- # @param param3 Third param.
42
- define foo(Integer $param1, $param2, String $param3 = hi) {
43
- file { '/tmp/foo':
44
- ensure => present
45
- }
46
- }
47
- SOURCE
48
- }
49
- it 'does not output a warning for title/name' do
50
- expect{ subject }.not_to output(/\[warn\].*(name|title).*/).to_stdout_from_any_process
51
- end
52
-
53
- it 'should register a defined type object' do
54
- expect(subject.size).to eq(1)
55
- object = subject.first
56
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::DefinedType)
57
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance)
58
- expect(object.name).to eq(:foo)
59
- expect(object.statement).not_to eq(nil)
60
- expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
61
- expect(object.docstring).to eq('A simple foo defined type.')
62
- expect(object.docstring.tags.size).to eq(5)
63
- tags = object.docstring.tags(:param)
64
- expect(tags.size).to eq(4)
65
- expect(tags[0].name).to eq('name')
66
- expect(tags[0].text).to eq('The type name.')
67
- expect(tags[0].types).to eq(nil)
68
- expect(tags[1].name).to eq('param1')
69
- expect(tags[1].text).to eq('First param.')
70
- expect(tags[1].types).to eq(['Integer'])
71
- expect(tags[2].name).to eq('param2')
72
- expect(tags[2].text).to eq('Second param.')
73
- expect(tags[2].types).to eq(['Any'])
74
- expect(tags[3].name).to eq('param3')
75
- expect(tags[3].text).to eq('Third param.')
76
- expect(tags[3].types).to eq(['String'])
77
- tags = object.docstring.tags(:api)
78
- expect(tags.size).to eq(1)
79
- expect(tags[0].text).to eq('public')
80
- end
81
- end
82
-
83
- describe 'parsing a defined type with a missing parameter' do
84
- let(:source) { <<-SOURCE
85
- # A simple foo defined type.
86
- # @param param1 First param.
87
- # @param param2 Second param.
88
- # @param param3 Third param.
89
- # @param param4 missing!
90
- define foo(Integer $param1, $param2, String $param3 = hi) {
91
- file { '/tmp/foo':
92
- ensure => present
93
- }
94
- }
95
- SOURCE
96
- }
97
-
98
- it 'should output a warning' do
99
- expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
100
- end
101
- end
102
-
103
- describe 'parsing a defined type with a missing @param tag' do
104
- let(:source) { <<-SOURCE
105
- # A simple foo defined type.
106
- # @param param1 First param.
107
- # @param param2 Second param.
108
- define foo(Integer $param1, $param2, String $param3 = hi) {
109
- file { '/tmp/foo':
110
- ensure => present
111
- }
112
- }
113
- SOURCE
114
- }
115
-
116
- it 'should output a warning' do
117
- expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
118
- end
119
- end
120
-
121
- describe 'parsing a defined type with a typed parameter that also has a @param tag type which matches' do
122
- let(:source) { <<-SOURCE
123
- # A simple foo defined type.
124
- # @param [Integer] param1 First param.
125
- # @param param2 Second param.
126
- # @param param3 Third param.
127
- define foo(Integer $param1, $param2, String $param3 = hi) {
128
- file { '/tmp/foo':
129
- ensure => present
130
- }
131
- }
132
- SOURCE
133
- }
134
-
135
- it 'should respect the type that was documented' do
136
- expect{ subject }.to output('').to_stdout_from_any_process
137
- expect(subject.size).to eq(1)
138
- tags = subject.first.tags(:param)
139
- expect(tags.size).to eq(3)
140
- expect(tags[0].types).to eq(['Integer'])
141
- end
142
- end
143
-
144
- describe 'parsing a defined type with a typed parameter that also has a @param tag type which does not match' do
145
- let(:source) { <<-SOURCE
146
- # A simple foo defined type.
147
- # @param [Boolean] param1 First param.
148
- # @param param2 Second param.
149
- # @param param3 Third param.
150
- define foo(Integer $param1, $param2, String $param3 = hi) {
151
- file { '/tmp/foo':
152
- ensure => present
153
- }
154
- }
155
- SOURCE
156
- }
157
-
158
- it 'should output a warning' do
159
- expect{ subject }.to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./).to_stdout_from_any_process
160
- end
161
- end
162
-
163
- describe 'parsing a defined type with a untyped parameter that also has a @param tag type' do
164
- let(:source) { <<-SOURCE
165
- # A simple foo defined type.
166
- # @param param1 First param.
167
- # @param [Boolean] param2 Second param.
168
- # @param param3 Third param.
169
- define foo(Integer $param1, $param2, String $param3 = hi) {
170
- file { '/tmp/foo':
171
- ensure => present
172
- }
173
- }
174
- SOURCE
175
- }
176
-
177
- it 'should respect the type that was documented' do
178
- expect{ subject }.to output('').to_stdout_from_any_process
179
- expect(subject.size).to eq(1)
180
- tags = subject.first.tags(:param)
181
- expect(tags.size).to eq(3)
182
- expect(tags[1].types).to eq(['Boolean'])
183
- end
184
- end
185
-
186
- describe 'parsing a defined type with a summary' do
187
-
188
- context 'when the summary has fewer than 140 characters' do
189
- let(:source) { <<-SOURCE
190
- # A simple foo defined type.
191
- # @summary A short summary.
192
- # @param param1 First param.
193
- # @param [Boolean] param2 Second param.
194
- # @param param3 Third param.
195
- define foo(Integer $param1, $param2, String $param3 = hi) {
196
- file { '/tmp/foo':
197
- ensure => present
198
- }
199
- }
200
- SOURCE
201
- }
202
-
203
- it 'should parse the summary' do
204
- expect{ subject }.to output('').to_stdout_from_any_process
205
- expect(subject.size).to eq(1)
206
- summary = subject.first.tags(:summary)
207
- expect(summary.first.text).to eq('A short summary.')
208
- end
209
- end
210
-
211
- context 'when the summary has more than 140 characters' do
212
- let(:source) { <<-SOURCE
213
- # A simple foo defined type.
214
- # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!
215
- # @param param1 First param.
216
- # @param [Boolean] param2 Second param.
217
- # @param param3 Third param.
218
- define foo(Integer $param1, $param2, String $param3 = hi) {
219
- file { '/tmp/foo':
220
- ensure => present
221
- }
222
- }
223
- SOURCE
224
- }
225
-
226
- it 'should log a warning' do
227
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_defined_type 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
228
- end
229
- end
230
- end
231
- end