puppet-strings 2.4.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +97 -5
  3. data/COMMITTERS.md +17 -17
  4. data/CONTRIBUTING.md +6 -6
  5. data/README.md +10 -10
  6. data/lib/puppet-strings.rb +4 -2
  7. data/lib/puppet-strings/describe.rb +2 -0
  8. data/lib/puppet-strings/json.rb +2 -0
  9. data/lib/puppet-strings/markdown.rb +12 -10
  10. data/lib/puppet-strings/markdown/base.rb +17 -3
  11. data/lib/puppet-strings/markdown/data_type.rb +18 -0
  12. data/lib/puppet-strings/markdown/data_types.rb +3 -1
  13. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  14. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  15. data/lib/puppet-strings/markdown/function.rb +9 -7
  16. data/lib/puppet-strings/markdown/functions.rb +3 -1
  17. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  18. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  19. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  20. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  21. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  22. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  23. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  24. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  25. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  26. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +10 -6
  27. data/lib/puppet-strings/markdown/templates/data_type.erb +22 -7
  28. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  29. data/lib/puppet-strings/markdown/templates/function.erb +2 -1
  30. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  31. data/lib/puppet-strings/markdown/templates/resource_type.erb +19 -13
  32. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  33. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  34. data/lib/puppet-strings/tasks.rb +2 -0
  35. data/lib/puppet-strings/tasks/generate.rb +2 -0
  36. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  37. data/lib/puppet-strings/version.rb +3 -1
  38. data/lib/puppet-strings/yard.rb +3 -0
  39. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  41. data/lib/puppet-strings/yard/code_objects/class.rb +4 -2
  42. data/lib/puppet-strings/yard/code_objects/data_type.rb +30 -8
  43. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +2 -0
  44. data/lib/puppet-strings/yard/code_objects/defined_type.rb +4 -2
  45. data/lib/puppet-strings/yard/code_objects/function.rb +6 -3
  46. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  47. data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
  48. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  49. data/lib/puppet-strings/yard/code_objects/task.rb +2 -0
  50. data/lib/puppet-strings/yard/code_objects/type.rb +50 -5
  51. data/lib/puppet-strings/yard/handlers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  59. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  60. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  61. data/lib/puppet-strings/yard/handlers/ruby/base.rb +5 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +223 -60
  63. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -7
  64. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  65. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +4 -1
  66. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +20 -6
  67. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +16 -6
  68. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  69. data/lib/puppet-strings/yard/parsers.rb +2 -0
  70. data/lib/puppet-strings/yard/parsers/json/parser.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  72. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +18 -14
  73. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +4 -0
  74. data/lib/puppet-strings/yard/tags.rb +2 -0
  75. data/lib/puppet-strings/yard/tags/enum_tag.rb +2 -0
  76. data/lib/puppet-strings/yard/tags/factory.rb +2 -0
  77. data/lib/puppet-strings/yard/tags/overload_tag.rb +4 -1
  78. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  80. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  81. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  82. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +9 -1
  83. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  85. data/lib/puppet-strings/yard/util.rb +4 -1
  86. data/lib/puppet/application/strings.rb +2 -0
  87. data/lib/puppet/face/strings.rb +4 -1
  88. data/lib/puppet/feature/rgen.rb +2 -0
  89. data/lib/puppet/feature/yard.rb +2 -0
  90. metadata +11 -52
  91. data/CODEOWNERS +0 -1
  92. data/Gemfile +0 -53
  93. data/HISTORY.md +0 -218
  94. data/JSON.md +0 -832
  95. data/Rakefile +0 -160
  96. data/codecov.yml +0 -3
  97. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  98. data/spec/acceptance/emit_json_options_spec.rb +0 -69
  99. data/spec/acceptance/generate_markdown_spec.rb +0 -47
  100. data/spec/acceptance/running_strings_generate_spec.rb +0 -88
  101. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  102. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  103. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  104. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  105. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  106. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -31
  107. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  108. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -10
  109. data/spec/fixtures/acceptance/modules/test/types/elephant.pp +0 -2
  110. data/spec/fixtures/unit/markdown/output.md +0 -561
  111. data/spec/fixtures/unit/markdown/output_with_data_types.md +0 -606
  112. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -595
  113. data/spec/spec_helper.rb +0 -49
  114. data/spec/spec_helper_acceptance.rb +0 -58
  115. data/spec/spec_helper_acceptance_local.rb +0 -10
  116. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  117. data/spec/unit/puppet-strings/json_spec.rb +0 -302
  118. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  119. data/spec/unit/puppet-strings/markdown_spec.rb +0 -374
  120. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  121. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  122. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  123. data/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb +0 -65
  124. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  125. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  126. data/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb +0 -309
  127. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -746
  128. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -158
  129. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  130. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -311
  131. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  132. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  133. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -251
  134. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,158 +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 definition with a string based name' do
110
- let(:source) { <<-SOURCE
111
- Puppet::Type.type(:'custom').provide :'linux' do
112
- desc 'An example provider on Linux.'
113
- end
114
- SOURCE
115
- }
116
-
117
- it 'should register a provider object' do
118
- expect(subject.size).to eq(1)
119
- object = subject.first
120
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Provider)
121
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Providers.instance('custom'))
122
- expect(object.name).to eq(:linux)
123
- expect(object.type_name).to eq('custom')
124
- expect(object.docstring).to eq('An example provider on Linux.')
125
- end
126
- end
127
-
128
- describe 'parsing a provider with a summary' do
129
- context 'when the summary has fewer than 140 characters' do
130
- let(:source) { <<-SOURCE
131
- Puppet::Type.type(:custom).provide :linux do
132
- @doc = '@summary A short summary.'
133
- end
134
- SOURCE
135
- }
136
-
137
- it 'should parse the summary' do
138
- expect{ subject }.to output('').to_stdout_from_any_process
139
- expect(subject.size).to eq(1)
140
- summary = subject.first.tags(:summary)
141
- expect(summary.first.text).to eq('A short summary.')
142
- end
143
- end
144
-
145
- context 'when the summary has more than 140 characters' do
146
- let(:source) { <<-SOURCE
147
- Puppet::Type.type(:custom).provide :linux do
148
- @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!!'
149
- end
150
- SOURCE
151
- }
152
-
153
- it 'should log a warning' do
154
- 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
155
- end
156
- end
157
- end
158
- end
@@ -1,235 +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
-
215
- describe 'parsing a type with title_patterns' do
216
- let(:source) { <<-SOURCE
217
- Puppet::ResourceApi.register_type(
218
- name: 'database',
219
- docs: 'An example database server resource type.',
220
- title_patterns: [
221
- {
222
- pattern: %r{(?<name>.*)},
223
- desc: 'Generic title match',
224
- }
225
- ]
226
- )
227
- SOURCE
228
- }
229
-
230
- it 'should not emit a warning' do
231
- expect{ subject }.not_to output(/\[warn\].*unexpected construct regexp_literal/).to_stdout_from_any_process
232
- end
233
- end
234
-
235
- end
@@ -1,311 +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 with a param with arguments' do
76
- let(:source) { <<-SOURCE
77
- Puppet::Type.newtype(:database) do
78
- feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
79
-
80
- newparam(:encryption_key, :parent => Puppet::Parameter::Boolean, required_features: :encryption) do
81
- desc 'The encryption key to use.'
82
- defaultto false
83
- end
84
- end
85
- SOURCE
86
- }
87
-
88
- it 'should correctly detect the required_feature' do
89
- expect(subject.size).to eq(1)
90
- object = subject.first
91
- expect(object.parameters[0].required_features).to eq('encryption')
92
- end
93
-
94
- it 'should correctly detect a boolean parent' do
95
- expect(subject.size).to eq(1)
96
- object = subject.first
97
- expect(object.parameters[0].default).to eq('false')
98
- end
99
- end
100
-
101
- describe 'parsing a type definition' do
102
- let(:source) { <<-SOURCE
103
- # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter.
104
- # @!puppet.type.property [foo, bar] dynamic_prop Documentation for a dynamic property.
105
- Puppet::Type.newtype(:database) do
106
- desc 'An example database server resource type.'
107
- feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
108
-
109
- feature :magic,
110
- 'The feature docstring should have
111
- whitespace and newlines stripped out.'
112
-
113
- ensurable do
114
- desc 'What state the database should be in.'
115
- defaultvalues
116
- aliasvalue(:up, :present)
117
- aliasvalue(:down, :absent)
118
- defaultto :up
119
- end
120
-
121
- newparam(:address) do
122
- isnamevar
123
- desc 'The database server name.'
124
- end
125
-
126
- newparam(:encryption_key, required_features: :encryption) do
127
- desc 'The encryption key to use.'
128
- end
129
-
130
- newparam(:encrypt, :parent => Puppet::Parameter::Boolean) do
131
- desc 'Whether or not to encrypt the database.'
132
- defaultto false
133
- end
134
-
135
- newparam(:backup) do
136
- desc 'How often to backup the database.'
137
- defaultto :never
138
- newvalues(:daily, :monthly, :never)
139
- end
140
-
141
- newproperty(:file) do
142
- desc 'The database file to use.'
143
- end
144
-
145
- newproperty(:log_level) do
146
- desc 'The log level to use.'
147
- newvalue(:debug)
148
- newvalue(:warn)
149
- newvalue(:error)
150
- defaultto 'warn'
151
- end
152
- end
153
- SOURCE
154
- }
155
-
156
- it 'should register a type object' do
157
- expect(subject.size).to eq(1)
158
- object = subject.first
159
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Type)
160
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Types.instance)
161
- expect(object.name).to eq(:database)
162
- expect(object.docstring).to eq('An example database server resource type.')
163
- expect(object.docstring.tags.size).to eq(1)
164
- tags = object.docstring.tags(:api)
165
- expect(tags.size).to eq(1)
166
- expect(tags[0].text).to eq('public')
167
- expect(object.properties.size).to eq(4)
168
- expect(object.properties[0].name).to eq('dynamic_prop')
169
- expect(object.properties[0].docstring).to eq('Documentation for a dynamic property.')
170
- expect(object.properties[0].isnamevar).to eq(false)
171
- expect(object.properties[0].values).to eq(%w(foo bar))
172
- expect(object.properties[1].name).to eq('ensure')
173
- expect(object.properties[1].docstring).to eq('What state the database should be in.')
174
- expect(object.properties[1].isnamevar).to eq(false)
175
- expect(object.properties[1].default).to eq('up')
176
- expect(object.properties[1].values).to eq(%w(present absent up down))
177
- expect(object.properties[1].aliases).to eq({ 'down' => 'absent', 'up' => 'present' })
178
- expect(object.properties[2].name).to eq('file')
179
- expect(object.properties[2].docstring).to eq('The database file to use.')
180
- expect(object.properties[2].isnamevar).to eq(false)
181
- expect(object.properties[2].default).to be_nil
182
- expect(object.properties[2].values).to eq([])
183
- expect(object.properties[2].aliases).to eq({})
184
- expect(object.properties[3].name).to eq('log_level')
185
- expect(object.properties[3].docstring).to eq('The log level to use.')
186
- expect(object.properties[3].isnamevar).to eq(false)
187
- expect(object.properties[3].default).to eq('warn')
188
- expect(object.properties[3].values).to eq(%w(debug warn error))
189
- expect(object.properties[3].aliases).to eq({})
190
- expect(object.parameters.size).to eq(5)
191
- expect(object.parameters[0].name).to eq('dynamic_param')
192
- expect(object.parameters[0].docstring).to eq('Documentation for a dynamic parameter.')
193
- expect(object.parameters[0].isnamevar).to eq(false)
194
- expect(object.parameters[0].values).to eq(%w(value1 value2))
195
- expect(object.parameters[1].name).to eq('address')
196
- expect(object.parameters[1].docstring).to eq('The database server name.')
197
- expect(object.parameters[1].isnamevar).to eq(true)
198
- expect(object.parameters[1].default).to be_nil
199
- expect(object.parameters[1].values).to eq([])
200
- expect(object.parameters[1].aliases).to eq({})
201
- expect(object.parameters[2].name).to eq('encryption_key')
202
- expect(object.parameters[2].docstring).to eq('The encryption key to use.')
203
- expect(object.parameters[2].isnamevar).to eq(false)
204
- expect(object.parameters[2].default).to be_nil
205
- expect(object.parameters[2].values).to eq([])
206
- expect(object.parameters[2].aliases).to eq({})
207
- expect(object.parameters[3].name).to eq('encrypt')
208
- expect(object.parameters[3].docstring).to eq('Whether or not to encrypt the database.')
209
- expect(object.parameters[3].isnamevar).to eq(false)
210
- expect(object.parameters[3].default).to eq('false')
211
- expect(object.parameters[3].values).to eq(%w(true false yes no))
212
- expect(object.parameters[3].aliases).to eq({})
213
- expect(object.parameters[4].name).to eq('backup')
214
- expect(object.parameters[4].docstring).to eq('How often to backup the database.')
215
- expect(object.parameters[4].isnamevar).to eq(false)
216
- expect(object.parameters[4].default).to eq('never')
217
- expect(object.parameters[4].values).to eq(%w(daily monthly never))
218
- expect(object.features.size).to eq(2)
219
- expect(object.features[0].name).to eq('encryption')
220
- expect(object.features[0].docstring).to eq('The provider supports encryption.')
221
- expect(object.features[1].name).to eq('magic')
222
- expect(object.features[1].docstring).to eq('The feature docstring should have whitespace and newlines stripped out.')
223
- end
224
- end
225
-
226
- describe 'parsing a valid type with string based name' do
227
- let(:source) { <<-SOURCE
228
- Puppet::Type.newtype(:'database') do
229
- desc 'An example database server resource type.'
230
- ensurable
231
- end
232
- SOURCE
233
- }
234
-
235
- it 'should register a type object with default ensure values' do
236
- expect(subject.size).to eq(1)
237
- object = subject.first
238
- expect(object.name).to eq(:database)
239
- end
240
- end
241
-
242
- describe 'parsing an ensurable type with default ensure values' do
243
- let(:source) { <<-SOURCE
244
- Puppet::Type.newtype(:database) do
245
- desc 'An example database server resource type.'
246
- ensurable
247
- end
248
- SOURCE
249
- }
250
-
251
- it 'should register a type object with default ensure values' do
252
- expect(subject.size).to eq(1)
253
- object = subject.first
254
- expect(object.properties[0].name).to eq('ensure')
255
- expect(object.properties[0].docstring).to eq('The basic property that the resource should be in.')
256
- expect(object.properties[0].default).to eq('present')
257
- expect(object.properties[0].values).to eq(%w(present absent))
258
- end
259
- end
260
-
261
- describe 'parsing a type with a parameter with the name of "name"' do
262
- let(:source) { <<-SOURCE
263
- Puppet::Type.newtype(:database) do
264
- desc 'An example database server resource type.'
265
- newparam(:name) do
266
- desc 'The database server name.'
267
- end
268
- end
269
- SOURCE
270
- }
271
-
272
- it 'should register a type object with the "name" parameter as the namevar' do
273
- expect(subject.size).to eq(1)
274
- object = subject.first
275
- expect(object.parameters.size).to eq(1)
276
- expect(object.parameters[0].name).to eq('name')
277
- expect(object.parameters[0].isnamevar).to eq(true)
278
- end
279
- end
280
-
281
- describe 'parsing a type with a summary' do
282
- context 'when the summary has fewer than 140 characters' do
283
- let(:source) { <<-SOURCE
284
- Puppet::Type.newtype(:database) do
285
- @doc = '@summary A short summary.'
286
- end
287
- SOURCE
288
- }
289
-
290
- it 'should parse the summary' do
291
- expect{ subject }.to output('').to_stdout_from_any_process
292
- expect(subject.size).to eq(1)
293
- summary = subject.first.tags(:summary)
294
- expect(summary.first.text).to eq('A short summary.')
295
- end
296
- end
297
-
298
- context 'when the summary has more than 140 characters' do
299
- let(:source) { <<-SOURCE
300
- Puppet::Type.newtype(:database) do
301
- @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!!'
302
- end
303
- SOURCE
304
- }
305
-
306
- it 'should log a warning' do
307
- 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
308
- end
309
- end
310
- end
311
- end