Skip to content

Commit b79522c

Browse files
committed
(MAINT) Add spec helpers
This commit adds two spec helpers that enable litmus and provide additional functionality. For example: * A custom runner has been created to execute puppet-lint via it's entrypoint. The function will also ensure that the resulting command is executed in a safe manor. * Two new rspec matchers have been added that help verify the messages that puppet-lint returns. They are very similar to the custom matchers that exist for the spec test, just much simpler.
1 parent 9571e24 commit b79522c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

spec/spec_helper_acceptance.rb

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

0 commit comments

Comments
 (0)