1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# frozen_string_literal: true
require 'shellwords'
require 'open3'
require 'rspec/expectations'
def puppet_lint(args = [])
raise "Parameter 'args' should an Array but it was of type #{args.class}." unless args.is_a?(Array) || args.empty?
bin_path = File.join(File.dirname(__FILE__), '..', 'bin', 'puppet-lint')
command = [bin_path]
command.concat(args) unless args.empty?
stdout, stderr, status = Open3.capture3(*command)
{
stdout: stdout.chomp,
stderr: stderr.chomp,
exit_code: status.exitstatus
}
end
RSpec::Matchers.define :have_errors do |expected|
match do |actual|
actual.split("\n").count { |line| line.include?('ERROR') } == expected
end
diffable
end
RSpec::Matchers.define :have_warnings do |expected|
match do |actual|
actual.split("\n").count { |line| line.include?('WARNING') } == expected
end
diffable
end
|