Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ group :test do
gem 'simplecov-console'
gem 'rspec', '~> 3.1'
gem 'json_spec', '~> 1.1', '>= 1.1.5'
gem 'mdl', '~> 0.8.0' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.4.0')
end

group :acceptance do
Expand Down
42 changes: 42 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,45 @@
YARD::Registry.clear
end
end

def mdl_available
@mdl_available ||= !Gem::Specification.select { |item| item.name.casecmp('mdl').zero? }.empty?
end

def lint_markdown(content)
return [] unless mdl_available
require 'mdl'

ruleset = MarkdownLint::RuleSet.new
ruleset.load_default

# All rules
style = MarkdownLint::Style.load('all', ruleset.rules)

# Create a document
doc = MarkdownLint::Doc.new(content, false)

# Run the rules
violations = []
ruleset.rules.each do |id, rule|
error_lines = rule.check.call(doc)
next if error_lines.nil? or error_lines.empty?
# record the error
error_lines.each do |line|
line += doc.offset # Correct line numbers for any yaml front matter
violations << "#{filename}:#{line}: #{id} #{rule.description}"
end
end
violations
end

RSpec::Matchers.define :have_no_markdown_lint_errors do
match do |actual|
@violations = lint_markdown(actual)
@violations.empty?
end

failure_message do |actual|
"expected that #{actual.length > 80 ? actual.slice(0,80).inspect + '...' : actual.inspect} would have no markdown lint errors but got #{@violations.join("\n")}"
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet-strings/markdown_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ def parse_data_type_content
let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/markdown/#{filename}") }
let(:baseline) { File.read(baseline_path) }

RSpec.shared_examples 'markdown lint checker' do |parameter|
it 'should not generate markdown lint errors from the rendered markdown', if: mdl_available do
pending('Failures are expected')
Tempfile.open('md') do |file|
PuppetStrings::Markdown.render(file.path)

expect(File.read(file.path)).to have_no_markdown_lint_errors
end
end
end

describe 'rendering markdown to a file' do
before(:each) do
parse_shared_content
Expand All @@ -339,6 +350,8 @@ def parse_data_type_content
expect(File.read(file.path)).to eq(baseline)
end
end

include_examples 'markdown lint checker'
end

describe 'with Puppet Plans', :if => TEST_PUPPET_PLANS do
Expand All @@ -354,6 +367,8 @@ def parse_data_type_content
expect(File.read(file.path)).to eq(baseline)
end
end

include_examples 'markdown lint checker'
end

describe 'with Puppet Data Types', :if => TEST_PUPPET_DATATYPES do
Expand All @@ -369,6 +384,8 @@ def parse_data_type_content
expect(File.read(file.path)).to eq(baseline)
end
end

include_examples 'markdown lint checker'
end
end
end