Skip to content

Commit f648b4a

Browse files
committed
setup rspec defaults and helpers
1 parent 5a8cabc commit f648b4a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spec/spec_helper_local.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
include RspecPuppetFacts
4+
5+
Dir['./spec/support/unit/**/*.rb'].sort.each { |f| require f }
6+
7+
RSpec.configure do |c|
8+
c.fail_if_no_examples = true
9+
c.silence_filter_announcements = true
10+
11+
c.expect_with :rspec do |expectations|
12+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13+
end
14+
end

spec/support/unit/facts.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Rough conversion of grepping in the puppet source:
2+
# grep defaultfor lib/puppet/provider/service/*.rb
3+
# Source https://github.com/voxpupuli/voxpupuli-test/blob/master/lib/voxpupuli/test/facts.rb
4+
add_custom_fact :service_provider, ->(_os, facts) do
5+
os = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
6+
case os['family'].downcase
7+
when 'archlinux'
8+
'systemd'
9+
when 'darwin'
10+
'launchd'
11+
when 'debian'
12+
'systemd'
13+
when 'freebsd'
14+
'freebsd'
15+
when 'gentoo'
16+
'openrc'
17+
when 'openbsd'
18+
'openbsd'
19+
when 'redhat'
20+
(os['release']['major'].to_i >= 7) ? 'systemd' : 'redhat'
21+
when 'suse'
22+
(os['release']['major'].to_i >= 12) ? 'systemd' : 'redhat'
23+
when 'windows'
24+
'windows'
25+
else
26+
'init'
27+
end
28+
end

0 commit comments

Comments
 (0)