|
4 | 4 | require 'tempfile'
|
5 | 5 |
|
6 | 6 | describe PuppetStrings::Markdown do
|
7 |
| - before :each do |
| 7 | + def parse_shared_content |
8 | 8 | # Populate the YARD registry with both Puppet and Ruby source
|
9 | 9 | YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
|
10 | 10 | # An overview for a simple class.
|
@@ -64,14 +64,6 @@ class noparams () {}
|
64 | 64 | String $param3 = 'hi',
|
65 | 65 | Boolean $param4 = true
|
66 | 66 | ) {
|
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) { |
75 | 67 | }
|
76 | 68 | SOURCE
|
77 | 69 |
|
@@ -275,21 +267,48 @@ class noparams () {}
|
275 | 267 | SOURCE
|
276 | 268 | end
|
277 | 269 |
|
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 |
284 | 279 | end
|
| 280 | + |
285 | 281 | let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/markdown/#{filename}") }
|
286 | 282 | let(:baseline) { File.read(baseline_path) }
|
287 | 283 |
|
288 | 284 | 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 |
293 | 312 | end
|
294 | 313 | end
|
295 | 314 | end
|
|
0 commit comments