puppet-strings 2.1.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -4
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +13 -4
  6. data/lib/puppet-strings/describe.rb +68 -0
  7. data/lib/puppet-strings/json.rb +2 -38
  8. data/lib/puppet-strings/markdown.rb +3 -1
  9. data/lib/puppet-strings/markdown/base.rb +37 -16
  10. data/lib/puppet-strings/markdown/data_type.rb +34 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +41 -0
  12. data/lib/puppet-strings/markdown/function.rb +2 -2
  13. data/lib/puppet-strings/markdown/resource_type.rb +19 -2
  14. data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
  15. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +12 -4
  16. data/lib/puppet-strings/markdown/templates/data_type.erb +93 -0
  17. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  18. data/lib/puppet-strings/markdown/templates/function.erb +36 -1
  19. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  20. data/lib/puppet-strings/markdown/templates/resource_type.erb +32 -12
  21. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  22. data/lib/puppet-strings/tasks/generate.rb +10 -3
  23. data/lib/puppet-strings/version.rb +1 -1
  24. data/lib/puppet-strings/yard.rb +16 -0
  25. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  26. data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
  27. data/lib/puppet-strings/yard/code_objects/data_type.rb +100 -0
  28. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
  29. data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
  30. data/lib/puppet-strings/yard/code_objects/function.rb +4 -4
  31. data/lib/puppet-strings/yard/code_objects/plan.rb +2 -2
  32. data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
  33. data/lib/puppet-strings/yard/code_objects/task.rb +1 -1
  34. data/lib/puppet-strings/yard/code_objects/type.rb +48 -6
  35. data/lib/puppet-strings/yard/handlers.rb +3 -0
  36. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
  37. data/lib/puppet-strings/yard/handlers/ruby/base.rb +12 -1
  38. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +393 -0
  39. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +2 -12
  40. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
  41. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +3 -3
  42. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +135 -0
  43. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
  44. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +9 -115
  45. data/lib/puppet-strings/yard/parsers/json/parser.rb +4 -2
  46. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
  47. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
  48. data/lib/puppet-strings/yard/tags.rb +2 -0
  49. data/lib/puppet-strings/yard/tags/enum_tag.rb +12 -0
  50. data/lib/puppet-strings/yard/tags/factory.rb +16 -0
  51. data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
  52. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  53. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  54. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  55. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  56. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  75. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  77. data/lib/puppet-strings/yard/util.rb +48 -0
  78. data/lib/puppet/face/strings.rb +68 -3
  79. metadata +36 -45
  80. data/Gemfile +0 -37
  81. data/HISTORY.md +0 -218
  82. data/JSON.md +0 -802
  83. data/Rakefile +0 -93
  84. data/codecov.yml +0 -3
  85. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  86. data/spec/acceptance/emit_json_options.rb +0 -71
  87. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  88. data/spec/acceptance/lib/util.rb +0 -163
  89. data/spec/acceptance/running_strings_generate.rb +0 -54
  90. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  91. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  92. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  93. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  94. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  95. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  96. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  97. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  98. data/spec/fixtures/unit/json/output.json +0 -660
  99. data/spec/fixtures/unit/json/output_with_plan.json +0 -697
  100. data/spec/fixtures/unit/json/output_without_puppet_function.json +0 -480
  101. data/spec/fixtures/unit/markdown/output.md +0 -444
  102. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -478
  103. data/spec/spec_helper.rb +0 -45
  104. data/spec/spec_helper_acceptance.rb +0 -28
  105. data/spec/unit/puppet-strings/json_spec.rb +0 -229
  106. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  107. data/spec/unit/puppet-strings/markdown_spec.rb +0 -283
  108. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  109. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -124
  110. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  111. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  112. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  113. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  114. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  115. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -214
  116. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -269
  117. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -70
  118. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  119. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  120. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Ruby::ProviderHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :ruby)
7
- YARD::Registry.all(:puppet_provider)
8
- }
9
-
10
- describe 'parsing source without a provider definition' do
11
- let(:source) { 'puts "hi"' }
12
-
13
- it 'no providers should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing a provider with a missing description' do
19
- let(:source) { <<-SOURCE
20
- Puppet::Type.type(:custom).provide :linux do
21
- end
22
- SOURCE
23
- }
24
-
25
- it 'should log a warning' do
26
- expect{ subject }.to output(/\[warn\]: Missing a description for Puppet provider 'linux' \(resource type 'custom'\) at \(stdin\):1\./).to_stdout_from_any_process
27
- end
28
- end
29
-
30
- describe 'parsing a provider with an invalid docstring assignment' do
31
- let(:source) { <<-SOURCE
32
- Puppet::Type.type(:custom).provide :linux do
33
- @doc = 123
34
- end
35
- SOURCE
36
- }
37
-
38
- it 'should log an error' do
39
- expect { subject }.to output(/Failed to parse docstring/).to_stdout_from_any_process
40
- end
41
- end
42
-
43
- describe 'parsing a provider with a valid docstring assignment' do
44
- let(:source) { <<-SOURCE
45
- Puppet::Type.type(:custom).provide :linux do
46
- @doc = 'An example provider on Linux.'
47
- end
48
- SOURCE
49
- }
50
-
51
- it 'should correctly detect the docstring' do
52
- expect(subject.size).to eq(1)
53
- object = subject.first
54
- expect(object.docstring).to eq('An example provider on Linux.')
55
- end
56
- end
57
-
58
- describe 'parsing a provider with a docstring which uses ruby `%Q` notation' do
59
- let(:source) { <<-'SOURCE'
60
- Puppet::Type.type(:custom).provide :linux do
61
- test = 'hello world!'
62
- desc %Q{This is a multi-line
63
- doc in %Q with #{test}}
64
- end
65
- SOURCE
66
- }
67
-
68
- it 'should strip the `%Q{}` and render the interpolation expression literally' do
69
- expect(subject.size).to eq(1)
70
- object = subject.first
71
- expect(object.docstring).to eq("This is a multi-line\ndoc in %Q with \#{test}")
72
- end
73
- end
74
-
75
- describe 'parsing a provider definition' do
76
- let(:source) { <<-SOURCE
77
- Puppet::Type.type(:custom).provide :linux do
78
- desc 'An example provider on Linux.'
79
- confine kernel: 'Linux'
80
- confine osfamily: 'RedHat'
81
- defaultfor :kernel => 'Linux'
82
- defaultfor :osfamily => 'RedHat', :operatingsystemmajrelease => '7'
83
- has_feature :implements_some_feature
84
- has_feature :some_other_feature
85
- commands foo: '/usr/bin/foo'
86
- end
87
- SOURCE
88
- }
89
-
90
- it 'should register a provider object' do
91
- expect(subject.size).to eq(1)
92
- object = subject.first
93
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Provider)
94
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Providers.instance('custom'))
95
- expect(object.name).to eq(:linux)
96
- expect(object.type_name).to eq('custom')
97
- expect(object.docstring).to eq('An example provider on Linux.')
98
- expect(object.docstring.tags.size).to eq(1)
99
- tags = object.docstring.tags(:api)
100
- expect(tags.size).to eq(1)
101
- expect(tags[0].text).to eq('public')
102
- expect(object.confines).to eq({ 'kernel' => 'Linux', 'osfamily' => 'RedHat'})
103
- expect(object.defaults).to eq([[["kernel", "Linux"]], [["osfamily", "RedHat"], ["operatingsystemmajrelease", "7"]]])
104
- expect(object.features).to eq(['implements_some_feature', 'some_other_feature'])
105
- expect(object.commands).to eq({'foo' => '/usr/bin/foo'})
106
- end
107
- end
108
-
109
- describe 'parsing a provider with a summary' do
110
- context 'when the summary has fewer than 140 characters' do
111
- let(:source) { <<-SOURCE
112
- Puppet::Type.type(:custom).provide :linux do
113
- @doc = '@summary A short summary.'
114
- end
115
- SOURCE
116
- }
117
-
118
- it 'should parse the summary' do
119
- expect{ subject }.to output('').to_stdout_from_any_process
120
- expect(subject.size).to eq(1)
121
- summary = subject.first.tags(:summary)
122
- expect(summary.first.text).to eq('A short summary.')
123
- end
124
- end
125
-
126
- context 'when the summary has more than 140 characters' do
127
- let(:source) { <<-SOURCE
128
- Puppet::Type.type(:custom).provide :linux do
129
- @doc = '@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!!'
130
- end
131
- SOURCE
132
- }
133
-
134
- it 'should log a warning' do
135
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_provider 'linux' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
136
- end
137
- end
138
- end
139
- end
@@ -1,214 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Ruby::RsapiHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :ruby)
7
- YARD::Registry.all(:puppet_type)
8
- }
9
-
10
- describe 'parsing source without a type definition' do
11
- let(:source) { 'puts "hi"' }
12
-
13
- it 'no types should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing a type with a missing description' do
19
- let(:source) { <<-SOURCE
20
- Puppet::ResourceApi.register_type(
21
- name: 'database'
22
- )
23
- SOURCE
24
- }
25
-
26
- it 'should log a warning' do
27
- expect{ subject }.to output(/\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\./).to_stdout_from_any_process
28
- end
29
- end
30
-
31
- describe 'parsing a type with a valid docstring assignment' do
32
- let(:source) { <<-SOURCE
33
- Puppet::ResourceApi.register_type(
34
- name: 'database',
35
- docs: 'An example database server resource type.',
36
- )
37
- SOURCE
38
- }
39
-
40
- it 'should correctly detect the docstring' do
41
- expect(subject.size).to eq(1)
42
- object = subject.first
43
- expect(object.docstring).to eq('An example database server resource type.')
44
- end
45
- end
46
-
47
- describe 'parsing a type with a docstring which uses ruby `%Q` notation' do
48
- let(:source) { <<-'SOURCE'
49
- test = 'hello world!'
50
-
51
- Puppet::ResourceApi.register_type(
52
- name: 'database',
53
- docs: %Q{This is a multi-line
54
- doc in %Q with #{test}},
55
- )
56
- SOURCE
57
- }
58
-
59
- it 'should strip the `%Q{}` and render the interpolation expression literally' do
60
- expect(subject.size).to eq(1)
61
- object = subject.first
62
- expect(object.docstring).to eq("This is a multi-line\ndoc in %Q with \#{test}")
63
- end
64
- end
65
-
66
- describe 'parsing a type definition' do
67
- let(:source) { <<-SOURCE
68
- # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter.
69
- # @!puppet.type.property [foo, bar] dynamic_prop Documentation for a dynamic property.
70
- Puppet::ResourceApi.register_type(
71
- name: 'database',
72
- docs: 'An example database server resource type.',
73
- features: ['remote-resource'],
74
- attributes: {
75
- ensure: {
76
- type: 'Enum[present, absent, up, down]',
77
- desc: 'What state the database should be in.',
78
- default: 'up',
79
- },
80
- address: {
81
- type: 'String',
82
- desc: 'The database server name.',
83
- behaviour: :namevar,
84
- },
85
- encrypt: {
86
- type: 'Boolean',
87
- desc: 'Whether or not to encrypt the database.',
88
- default: false,
89
- behaviour: :parameter,
90
- },
91
- encryption_key: {
92
- type: 'Optional[String]',
93
- desc: 'The encryption key to use.',
94
- behaviour: :parameter,
95
- },
96
- backup: {
97
- type: 'Enum[daily, monthly, never]',
98
- desc: 'How often to backup the database.',
99
- default: 'never',
100
- behaviour: :parameter,
101
- },
102
- file: {
103
- type: 'String',
104
- desc: 'The database file to use.',
105
- },
106
- log_level: {
107
- type: 'Enum[debug, warn, error]',
108
- desc: 'The log level to use.',
109
- default: 'warn',
110
- },
111
- },
112
- )
113
- SOURCE
114
- }
115
-
116
- it 'should register a type object' do
117
- expect(subject.size).to eq(1)
118
- object = subject.first
119
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Type)
120
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Types.instance)
121
- expect(object.name).to eq(:database)
122
- expect(object.docstring).to eq('An example database server resource type.')
123
- expect(object.docstring.tags.size).to eq(1)
124
- tags = object.docstring.tags(:api)
125
- expect(tags.size).to eq(1)
126
- expect(tags[0].text).to eq('public')
127
- expect(object.properties.map(&:name)).to eq(['dynamic_prop', 'ensure', 'file', 'log_level'])
128
- expect(object.properties.size).to eq(4)
129
- expect(object.properties[0].name).to eq('dynamic_prop')
130
- expect(object.properties[0].docstring).to eq('Documentation for a dynamic property.')
131
- expect(object.properties[0].isnamevar).to eq(false)
132
- expect(object.properties[0].values).to eq(%w(foo bar))
133
- expect(object.properties[1].name).to eq('ensure')
134
- expect(object.properties[1].docstring).to eq('What state the database should be in.')
135
- expect(object.properties[1].isnamevar).to eq(false)
136
- expect(object.properties[1].default).to eq('up')
137
- expect(object.properties[1].data_type).to eq('Enum[present, absent, up, down]')
138
- expect(object.properties[1].aliases).to eq({})
139
- expect(object.properties[2].name).to eq('file')
140
- expect(object.properties[2].docstring).to eq('The database file to use.')
141
- expect(object.properties[2].isnamevar).to eq(false)
142
- expect(object.properties[2].default).to be_nil
143
- expect(object.properties[2].data_type).to eq('String')
144
- expect(object.properties[2].aliases).to eq({})
145
- expect(object.properties[3].name).to eq('log_level')
146
- expect(object.properties[3].docstring).to eq('The log level to use.')
147
- expect(object.properties[3].isnamevar).to eq(false)
148
- expect(object.properties[3].default).to eq('warn')
149
- expect(object.properties[3].data_type).to eq('Enum[debug, warn, error]')
150
- expect(object.properties[3].aliases).to eq({})
151
- expect(object.parameters.size).to eq(5)
152
- expect(object.parameters[0].name).to eq('dynamic_param')
153
- expect(object.parameters[0].docstring).to eq('Documentation for a dynamic parameter.')
154
- expect(object.parameters[0].isnamevar).to eq(false)
155
- expect(object.parameters[0].values).to eq(%w(value1 value2))
156
- expect(object.parameters[1].name).to eq('address')
157
- expect(object.parameters[1].docstring).to eq('The database server name.')
158
- expect(object.parameters[1].isnamevar).to eq(true)
159
- expect(object.parameters[1].default).to be_nil
160
- expect(object.parameters[1].data_type).to eq('String')
161
- expect(object.parameters[1].aliases).to eq({})
162
- expect(object.parameters[2].name).to eq('encrypt')
163
- expect(object.parameters[2].docstring).to eq('Whether or not to encrypt the database.')
164
- expect(object.parameters[2].isnamevar).to eq(false)
165
- expect(object.parameters[2].default).to eq(false)
166
- expect(object.parameters[2].data_type).to eq("Boolean")
167
- expect(object.parameters[2].aliases).to eq({})
168
- expect(object.parameters[3].name).to eq('encryption_key')
169
- expect(object.parameters[3].docstring).to eq('The encryption key to use.')
170
- expect(object.parameters[3].isnamevar).to eq(false)
171
- expect(object.parameters[3].default).to be_nil
172
- expect(object.parameters[3].data_type).to eq("Optional[String]")
173
- expect(object.parameters[3].aliases).to eq({})
174
- expect(object.parameters[4].name).to eq('backup')
175
- expect(object.parameters[4].docstring).to eq('How often to backup the database.')
176
- expect(object.parameters[4].isnamevar).to eq(false)
177
- expect(object.parameters[4].default).to eq('never')
178
- expect(object.parameters[4].data_type).to eq("Enum[daily, monthly, never]")
179
- end
180
- end
181
-
182
- describe 'parsing a type with a summary' do
183
- context 'when the summary has fewer than 140 characters' do
184
- let(:source) { <<-SOURCE
185
- Puppet::ResourceApi.register_type(
186
- name: 'database',
187
- docs: '@summary A short summary.',
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
- Puppet::ResourceApi.register_type(
203
- name: 'database',
204
- docs: '@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!!',
205
- )
206
- SOURCE
207
- }
208
-
209
- it 'should log a warning' do
210
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
211
- end
212
- end
213
- end
214
- end
@@ -1,269 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Ruby::TypeHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :ruby)
7
- YARD::Registry.all(:puppet_type)
8
- }
9
-
10
- describe 'parsing source without a type definition' do
11
- let(:source) { 'puts "hi"' }
12
-
13
- it 'no types should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing a type with a missing description' do
19
- let(:source) { <<-SOURCE
20
- Puppet::Type.newtype(:database) do
21
- end
22
- SOURCE
23
- }
24
-
25
- it 'should log a warning' do
26
- expect{ subject }.to output(/\[warn\]: Missing a description for Puppet resource type 'database' at \(stdin\):1\./).to_stdout_from_any_process
27
- end
28
- end
29
-
30
- describe 'parsing a type with an invalid docstring assignment' do
31
- let(:source) { <<-SOURCE
32
- Puppet::Type.newtype(:database) do
33
- @doc = 123
34
- end
35
- SOURCE
36
- }
37
-
38
- it 'should log an error' do
39
- expect { subject }.to output(/Failed to parse docstring/).to_stdout_from_any_process
40
- end
41
- end
42
-
43
- describe 'parsing a type with a valid docstring assignment' do
44
- let(:source) { <<-SOURCE
45
- Puppet::Type.newtype(:database) do
46
- @doc = 'An example database server resource type.'
47
- end
48
- SOURCE
49
- }
50
-
51
- it 'should correctly detect the docstring' do
52
- expect(subject.size).to eq(1)
53
- object = subject.first
54
- expect(object.docstring).to eq('An example database server resource type.')
55
- end
56
- end
57
-
58
- describe 'parsing a type with a docstring which uses ruby `%Q` notation' do
59
- let(:source) { <<-'SOURCE'
60
- Puppet::Type.newtype(:database) do
61
- test = 'hello world!'
62
- desc %Q{This is a multi-line
63
- doc in %Q with #{test}}
64
- end
65
- SOURCE
66
- }
67
-
68
- it 'should strip the `%Q{}` and render the interpolation expression literally' do
69
- expect(subject.size).to eq(1)
70
- object = subject.first
71
- expect(object.docstring).to eq("This is a multi-line\ndoc in %Q with \#{test}")
72
- end
73
- end
74
-
75
- describe 'parsing a type definition' do
76
- let(:source) { <<-SOURCE
77
- # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter.
78
- # @!puppet.type.property [foo, bar] dynamic_prop Documentation for a dynamic property.
79
- Puppet::Type.newtype(:database) do
80
- desc 'An example database server resource type.'
81
- feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
82
-
83
- feature :magic,
84
- 'The feature docstring should have
85
- whitespace and newlines stripped out.'
86
-
87
- ensurable do
88
- desc 'What state the database should be in.'
89
- defaultvalues
90
- aliasvalue(:up, :present)
91
- aliasvalue(:down, :absent)
92
- defaultto :up
93
- end
94
-
95
- newparam(:address) do
96
- isnamevar
97
- desc 'The database server name.'
98
- end
99
-
100
- newparam(:encryption_key, required_features: :encryption) do
101
- desc 'The encryption key to use.'
102
- end
103
-
104
- newparam(:encrypt, :parent => Puppet::Parameter::Boolean) do
105
- desc 'Whether or not to encrypt the database.'
106
- defaultto false
107
- end
108
-
109
- newparam(:backup) do
110
- desc 'How often to backup the database.'
111
- defaultto :never
112
- newvalues(:daily, :monthly, :never)
113
- end
114
-
115
- newproperty(:file) do
116
- desc 'The database file to use.'
117
- end
118
-
119
- newproperty(:log_level) do
120
- desc 'The log level to use.'
121
- newvalue(:debug)
122
- newvalue(:warn)
123
- newvalue(:error)
124
- defaultto 'warn'
125
- end
126
- end
127
- SOURCE
128
- }
129
-
130
- it 'should register a type object' do
131
- expect(subject.size).to eq(1)
132
- object = subject.first
133
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Type)
134
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Types.instance)
135
- expect(object.name).to eq(:database)
136
- expect(object.docstring).to eq('An example database server resource type.')
137
- expect(object.docstring.tags.size).to eq(1)
138
- tags = object.docstring.tags(:api)
139
- expect(tags.size).to eq(1)
140
- expect(tags[0].text).to eq('public')
141
- expect(object.properties.size).to eq(4)
142
- expect(object.properties[0].name).to eq('dynamic_prop')
143
- expect(object.properties[0].docstring).to eq('Documentation for a dynamic property.')
144
- expect(object.properties[0].isnamevar).to eq(false)
145
- expect(object.properties[0].values).to eq(%w(foo bar))
146
- expect(object.properties[1].name).to eq('ensure')
147
- expect(object.properties[1].docstring).to eq('What state the database should be in.')
148
- expect(object.properties[1].isnamevar).to eq(false)
149
- expect(object.properties[1].default).to eq('up')
150
- expect(object.properties[1].values).to eq(%w(present absent up down))
151
- expect(object.properties[1].aliases).to eq({ 'down' => 'absent', 'up' => 'present' })
152
- expect(object.properties[2].name).to eq('file')
153
- expect(object.properties[2].docstring).to eq('The database file to use.')
154
- expect(object.properties[2].isnamevar).to eq(false)
155
- expect(object.properties[2].default).to be_nil
156
- expect(object.properties[2].values).to eq([])
157
- expect(object.properties[2].aliases).to eq({})
158
- expect(object.properties[3].name).to eq('log_level')
159
- expect(object.properties[3].docstring).to eq('The log level to use.')
160
- expect(object.properties[3].isnamevar).to eq(false)
161
- expect(object.properties[3].default).to eq('warn')
162
- expect(object.properties[3].values).to eq(%w(debug warn error))
163
- expect(object.properties[3].aliases).to eq({})
164
- expect(object.parameters.size).to eq(5)
165
- expect(object.parameters[0].name).to eq('dynamic_param')
166
- expect(object.parameters[0].docstring).to eq('Documentation for a dynamic parameter.')
167
- expect(object.parameters[0].isnamevar).to eq(false)
168
- expect(object.parameters[0].values).to eq(%w(value1 value2))
169
- expect(object.parameters[1].name).to eq('address')
170
- expect(object.parameters[1].docstring).to eq('The database server name.')
171
- expect(object.parameters[1].isnamevar).to eq(true)
172
- expect(object.parameters[1].default).to be_nil
173
- expect(object.parameters[1].values).to eq([])
174
- expect(object.parameters[1].aliases).to eq({})
175
- expect(object.parameters[2].name).to eq('encryption_key')
176
- expect(object.parameters[2].docstring).to eq('The encryption key to use.')
177
- expect(object.parameters[2].isnamevar).to eq(false)
178
- expect(object.parameters[2].default).to be_nil
179
- expect(object.parameters[2].values).to eq([])
180
- expect(object.parameters[2].aliases).to eq({})
181
- expect(object.parameters[3].name).to eq('encrypt')
182
- expect(object.parameters[3].docstring).to eq('Whether or not to encrypt the database.')
183
- expect(object.parameters[3].isnamevar).to eq(false)
184
- expect(object.parameters[3].default).to eq('false')
185
- expect(object.parameters[3].values).to eq(%w(true false yes no))
186
- expect(object.parameters[3].aliases).to eq({})
187
- expect(object.parameters[4].name).to eq('backup')
188
- expect(object.parameters[4].docstring).to eq('How often to backup the database.')
189
- expect(object.parameters[4].isnamevar).to eq(false)
190
- expect(object.parameters[4].default).to eq('never')
191
- expect(object.parameters[4].values).to eq(%w(daily monthly never))
192
- expect(object.features.size).to eq(2)
193
- expect(object.features[0].name).to eq('encryption')
194
- expect(object.features[0].docstring).to eq('The provider supports encryption.')
195
- expect(object.features[1].name).to eq('magic')
196
- expect(object.features[1].docstring).to eq('The feature docstring should have whitespace and newlines stripped out.')
197
- end
198
- end
199
-
200
- describe 'parsing an ensurable type with default ensure values' do
201
- let(:source) { <<-SOURCE
202
- Puppet::Type.newtype(:database) do
203
- desc 'An example database server resource type.'
204
- ensurable
205
- end
206
- SOURCE
207
- }
208
-
209
- it 'should register a type object with default ensure values' do
210
- expect(subject.size).to eq(1)
211
- object = subject.first
212
- expect(object.properties[0].name).to eq('ensure')
213
- expect(object.properties[0].docstring).to eq('The basic property that the resource should be in.')
214
- expect(object.properties[0].default).to eq('present')
215
- expect(object.properties[0].values).to eq(%w(present absent))
216
- end
217
- end
218
-
219
- describe 'parsing a type with a parameter with the name of "name"' do
220
- let(:source) { <<-SOURCE
221
- Puppet::Type.newtype(:database) do
222
- desc 'An example database server resource type.'
223
- newparam(:name) do
224
- desc 'The database server name.'
225
- end
226
- end
227
- SOURCE
228
- }
229
-
230
- it 'should register a type object with the "name" parameter as the namevar' do
231
- expect(subject.size).to eq(1)
232
- object = subject.first
233
- expect(object.parameters.size).to eq(1)
234
- expect(object.parameters[0].name).to eq('name')
235
- expect(object.parameters[0].isnamevar).to eq(true)
236
- end
237
- end
238
-
239
- describe 'parsing a type with a summary' do
240
- context 'when the summary has fewer than 140 characters' do
241
- let(:source) { <<-SOURCE
242
- Puppet::Type.newtype(:database) do
243
- @doc = '@summary A short summary.'
244
- end
245
- SOURCE
246
- }
247
-
248
- it 'should parse the summary' do
249
- expect{ subject }.to output('').to_stdout_from_any_process
250
- expect(subject.size).to eq(1)
251
- summary = subject.first.tags(:summary)
252
- expect(summary.first.text).to eq('A short summary.')
253
- end
254
- end
255
-
256
- context 'when the summary has more than 140 characters' do
257
- let(:source) { <<-SOURCE
258
- Puppet::Type.newtype(:database) do
259
- @doc = '@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!!'
260
- end
261
- SOURCE
262
- }
263
-
264
- it 'should log a warning' do
265
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_type 'database' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
266
- end
267
- end
268
- end
269
- end