spec/unit/puppet-strings/markdown_spec.rb in puppet-strings-2.2.0 vs spec/unit/puppet-strings/markdown_spec.rb in puppet-strings-2.3.0
- old
+ new
@@ -2,11 +2,11 @@
require 'puppet-strings/markdown'
require 'puppet-strings/markdown/table_of_contents'
require 'tempfile'
describe PuppetStrings::Markdown do
- before :each do
+ def parse_shared_content
# Populate the YARD registry with both Puppet and Ruby source
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
# An overview for a simple class.
# @summary A simple class.
# @todo Do a thing
@@ -63,19 +63,11 @@
$param2,
String $param3 = 'hi',
Boolean $param4 = true
) {
}
-SOURCE
- YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_PLANS
-# A simple plan.
-# @param param1 First param.
-# @param param2 Second param.
-# @param param3 Third param.
-plan plann(String $param1, $param2, Integer $param3 = 1) {
-}
-SOURCE
+ SOURCE
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :json)
{
"description": "Allows you to backup your database to local file.",
"input_method": "stdin",
@@ -96,11 +88,11 @@
"description": "Path to file you want backup to",
"type": "String[1]"
}
}
}
-SOURCE
+ SOURCE
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
# A simple Puppet function.
# @param param1 First param.
# @param param2 Second param.
@@ -110,11 +102,11 @@
# @return [Undef] Returns nothing.
# @example Test
# $result = func(1, 2)
function func(Integer $param1, $param2, String $param3 = hi) {
}
-SOURCE
+ SOURCE
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
# An example 4.x function.
#
# @example Calling the function
@@ -270,27 +262,96 @@
autorequires: {
file: '$source', # will evaluate to the value of the `source` attribute
package: 'apt',
},
)
-SOURCE
+ SOURCE
end
- let(:filename) do
- if TEST_PUPPET_PLANS
- 'output_with_plan.md'
- else
- 'output.md'
- end
+ def parse_plan_content
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
+# A simple plan.
+# @param param1 First param.
+# @param param2 Second param.
+# @param param3 Third param.
+plan plann(String $param1, $param2, Integer $param3 = 1) {
+}
+ SOURCE
end
+
+ def parse_data_type_content
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
+# An example Puppet Data Type in Ruby.
+#
+# @param param1 A variant parameter.
+# @param param2 Optional String parameter.
+Puppet::DataTypes.create_type('UnitDataType') do
+ interface <<-PUPPET
+ attributes => {
+ param1 => Variant[Numeric, String[1,2]],
+ param2 => { type => Optional[String[1]], value => "param2" }
+ }
+ PUPPET
+end
+ SOURCE
+
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
+# Documentation for Amodule::SimpleAlias
+type Amodule::SimpleAlias = Variant[Numeric,String[1,20]]
+
+# Documentation for Amodule::ComplexAlias
+type Amodule::ComplexAlias = Struct[{
+ value_type => Optional[ValueType],
+ merge => Optional[MergeType]
+}]
+ SOURCE
+ end
let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/markdown/#{filename}") }
let(:baseline) { File.read(baseline_path) }
describe 'rendering markdown to a file' do
- it 'should output the expected markdown content' do
- Tempfile.open('md') do |file|
- PuppetStrings::Markdown.render(file.path)
- expect(File.read(file.path)).to eq(baseline)
+ before(:each) do
+ parse_shared_content
+ end
+
+ context 'with common Puppet and ruby content' do
+ let(:filename) { 'output.md' }
+
+ it 'should output the expected markdown content' do
+ Tempfile.open('md') do |file|
+ PuppetStrings::Markdown.render(file.path)
+ expect(File.read(file.path)).to eq(baseline)
+ end
+ end
+ end
+
+ describe 'with Puppet Plans', :if => TEST_PUPPET_PLANS do
+ let(:filename) { 'output_with_plan.md' }
+
+ before(:each) do
+ parse_plan_content
+ end
+
+ it 'should output the expected markdown content' do
+ Tempfile.open('md') do |file|
+ PuppetStrings::Markdown.render(file.path)
+ expect(File.read(file.path)).to eq(baseline)
+ end
+ end
+ end
+
+ describe 'with Puppet Data Types', :if => TEST_PUPPET_DATATYPES do
+ let(:filename) { 'output_with_data_types.md' }
+
+ before(:each) do
+ parse_data_type_content
+ end
+
+ it 'should output the expected markdown content' do
+ Tempfile.open('md') do |file|
+ PuppetStrings::Markdown.render(file.path)
+ expect(File.read(file.path)).to eq(baseline)
+ end
end
end
end
end