Skip to content

Commit 0129234

Browse files
committed
Add specs for type_extras_handler
1 parent 7f96be1 commit 0129234

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'puppet-strings/yard'
5+
6+
describe PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler do
7+
subject {
8+
YARD::Parser::SourceParser.parse_string(source, :ruby)
9+
YARD::Registry.all(:puppet_type)
10+
}
11+
12+
describe 'parsing source with newproperty' do
13+
let(:source) { <<~SOURCE
14+
Puppet::Type.newtype(:database) do
15+
desc 'database'
16+
end
17+
Puppet::Type.type(:database).newproperty(:file) do
18+
desc 'The database file to use.'
19+
end
20+
SOURCE
21+
}
22+
23+
it 'generates a doc string for a property' do
24+
expect(subject.size).to eq(1)
25+
object = subject.first
26+
expect(object.properties.size).to eq(1)
27+
expect(object.properties[0].name).to eq('file')
28+
expect(object.properties[0].docstring).to eq('The database file to use.')
29+
end
30+
end
31+
32+
describe 'parsing source with newparam' do
33+
let(:source) { <<~SOURCE
34+
Puppet::Type.newtype(:database) do
35+
desc 'database'
36+
end
37+
Puppet::Type.type(:database).newparam(:name) do
38+
desc 'The database server name.'
39+
end
40+
SOURCE
41+
}
42+
43+
it 'generates a doc string for a parameter that is also a namevar' do
44+
expect(subject.size).to eq(1)
45+
object = subject.first
46+
expect(object.parameters.size).to eq(1)
47+
expect(object.parameters[0].name).to eq('name')
48+
expect(object.parameters[0].docstring).to eq('The database server name.')
49+
expect(object.parameters[0].isnamevar).to eq(true)
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)