|
| 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 | + |
| 53 | + describe 'parsing source with ensurable' do |
| 54 | + let(:source) { <<~SOURCE |
| 55 | + Puppet::Type.newtype(:database) do |
| 56 | + desc 'database' |
| 57 | + end |
| 58 | + Puppet::Type.type(:database).ensurable do |
| 59 | + desc 'What state the database should be in.' |
| 60 | + end |
| 61 | + SOURCE |
| 62 | + } |
| 63 | + |
| 64 | + it 'generates a doc string for an ensurable' do |
| 65 | + expect(subject.size).to eq(1) |
| 66 | + object = subject.first |
| 67 | + expect(object.properties.size).to eq(1) |
| 68 | + expect(object.properties[0].name).to eq('ensure') |
| 69 | + expect(object.properties[0].docstring).to eq('What state the database should be in.') |
| 70 | + end |
| 71 | + end |
| 72 | +end |
0 commit comments