Skip to content

Commit 763eaee

Browse files
committed
(PDOC-226) Refactor Markdown testing
Previously the markdown unit testing used an a simple if statement to switch between common and Puppet Plans. However with the introduction of Puppet Types we need another combination. This commit refactors the Markdown testing use an additive style to figure out test fixtures which makes adding conditional tests easier in the future.
1 parent 42a643e commit 763eaee

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

spec/unit/puppet-strings/markdown_spec.rb

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'tempfile'
55

66
describe PuppetStrings::Markdown do
7-
before :each do
7+
def parse_shared_content
88
# Populate the YARD registry with both Puppet and Ruby source
99
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
1010
# An overview for a simple class.
@@ -64,14 +64,6 @@ class noparams () {}
6464
String $param3 = 'hi',
6565
Boolean $param4 = true
6666
) {
67-
}
68-
SOURCE
69-
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_PLANS
70-
# A simple plan.
71-
# @param param1 First param.
72-
# @param param2 Second param.
73-
# @param param3 Third param.
74-
plan plann(String $param1, $param2, Integer $param3 = 1) {
7567
}
7668
SOURCE
7769

@@ -275,21 +267,48 @@ class noparams () {}
275267
SOURCE
276268
end
277269

278-
let(:filename) do
279-
if TEST_PUPPET_PLANS
280-
'output_with_plan.md'
281-
else
282-
'output.md'
283-
end
270+
def parse_plan_content
271+
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
272+
# A simple plan.
273+
# @param param1 First param.
274+
# @param param2 Second param.
275+
# @param param3 Third param.
276+
plan plann(String $param1, $param2, Integer $param3 = 1) {
277+
}
278+
SOURCE
284279
end
280+
285281
let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/markdown/#{filename}") }
286282
let(:baseline) { File.read(baseline_path) }
287283

288284
describe 'rendering markdown to a file' do
289-
it 'should output the expected markdown content' do
290-
Tempfile.open('md') do |file|
291-
PuppetStrings::Markdown.render(file.path)
292-
expect(File.read(file.path)).to eq(baseline)
285+
before(:each) do
286+
parse_shared_content
287+
end
288+
289+
context 'with common Puppet and ruby content' do
290+
let(:filename) { 'output.md' }
291+
292+
it 'should output the expected markdown content' do
293+
Tempfile.open('md') do |file|
294+
PuppetStrings::Markdown.render(file.path)
295+
expect(File.read(file.path)).to eq(baseline)
296+
end
297+
end
298+
end
299+
300+
describe 'with Puppet Plans', :if => TEST_PUPPET_PLANS do
301+
let(:filename) { 'output_with_plan.md' }
302+
303+
before(:each) do
304+
parse_plan_content
305+
end
306+
307+
it 'should output the expected markdown content' do
308+
Tempfile.open('md') do |file|
309+
PuppetStrings::Markdown.render(file.path)
310+
expect(File.read(file.path)).to eq(baseline)
311+
end
293312
end
294313
end
295314
end

0 commit comments

Comments
 (0)