Skip to content

Commit 77d98af

Browse files
igalicpetems
authored andcommitted
fix tests: introduce rspec-puppet-facts
to only test supported OSes ;)
1 parent 27d2f03 commit 77d98af

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

Gemfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ source "https://rubygems.org"
22

33
group :test do
44
gem "rake"
5-
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0'
6-
gem "puppet-lint"
5+
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0'
76
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
8-
gem "puppet-syntax"
97
gem "puppetlabs_spec_helper"
8+
gem "metadata-json-lint"
9+
gem "rspec-puppet-facts"
10+
gem "rspec", "< 3.2.0", { "platforms" => ["ruby_18"] }
1011
end
1112

1213
group :development do
1314
gem "travis"
1415
gem "travis-lint"
15-
gem "beaker"
16-
gem "beaker-rspec"
17-
gem "vagrant-wrapper"
1816
gem "puppet-blacksmith"
1917
gem "guard-rake"
2018
end
19+
20+
group :system_tests do
21+
gem "beaker"
22+
gem "beaker-rspec"
23+
end

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ require 'puppetlabs_spec_helper/rake_tasks'
22
require 'puppet-lint/tasks/puppet-lint'
33
require 'puppet-syntax/tasks/puppet-syntax'
44

5-
# These two gems aren't always present, for instance
5+
# These gems aren't always present, for instance
66
# on Travis with --without development
77
begin
88
require 'puppet_blacksmith/rake_tasks'
99
rescue LoadError
1010
end
1111

12+
Rake::Task[:lint].clear
13+
14+
PuppetLint.configuration.relative = true
1215
PuppetLint.configuration.send("disable_80chars")
1316
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
1417
PuppetLint.configuration.fail_on_warnings = true
@@ -20,6 +23,7 @@ PuppetLint.configuration.send('disable_class_parameter_defaults')
2023
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
2124

2225
exclude_paths = [
26+
"bundle/**/*",
2327
"pkg/**/*",
2428
"vendor/**/*",
2529
"spec/**/*",
@@ -32,9 +36,14 @@ RSpec::Core::RakeTask.new(:acceptance) do |t|
3236
t.pattern = 'spec/acceptance'
3337
end
3438

39+
task :metadata do
40+
sh "metadata-json-lint metadata.json"
41+
end
42+
3543
desc "Run syntax, lint, and spec tests."
3644
task :test => [
3745
:syntax,
3846
:lint,
3947
:spec,
48+
:metadata,
4049
]

spec/classes/libvirt_spec.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2013 Brainsware
1+
# Copyright 2015 any number of authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -15,18 +15,30 @@
1515
require 'spec_helper'
1616

1717
describe 'libvirt', :type => :class do
18-
let(:title) { 'libvirt' }
18+
context 'supported operating systems' do
19+
on_supported_os.each do |os, facts|
20+
context "on #{os} #{facts}" do
21+
let(:facts) do
22+
facts
23+
end
1924

20-
it { should contain_class('libvirt') }
21-
it { should contain_file('/etc/libvirt/qemu/networks/autostart/default.xml')
22-
.with_ensure('absent')
23-
}
25+
context 'with default parameters' do
26+
let(:title) { 'libvirt' }
2427

25-
describe 'with default network enabled' do
26-
let(:params) {{ :defaultnetwork => true }}
28+
it { should contain_class('libvirt') }
29+
it { should contain_file('/etc/libvirt/qemu/networks/autostart/default.xml')
30+
.with_ensure('absent')
31+
}
32+
end
2733

28-
it { should contain_class('libvirt') }
29-
it { should contain_exec('virsh-net-autostart-default') }
34+
context 'with default network enabled' do
35+
let(:params) {{ :defaultnetwork => true }}
36+
37+
it { should contain_class('libvirt') }
38+
it { should contain_exec('virsh-net-autostart-default') }
39+
end
40+
end
41+
end
3042
end
3143

3244
end

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
require 'puppetlabs_spec_helper/module_spec_helper'
2+
require 'rspec-puppet-facts'
3+
include RspecPuppetFacts
4+
5+
RSpec.configure do |c|
6+
c.before do
7+
# avoid "Only root can execute commands as other users"
8+
Puppet.features.stubs(:root? => true)
9+
end
10+
end

0 commit comments

Comments
 (0)