rspec-puppet-facts 1.9.2 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cc1e0c2d29c71210af4d52cd12eb0cf9be062dedd4a6eb59f931379acb12b57
4
- data.tar.gz: b16313f97d45b158fec32cabf3e69519c28b64739964b9856249c24786f595a3
3
+ metadata.gz: 643de41b550424eb4cf57cdb3b2c7a68ee9391b80df3eedb29f0896d0b88bd70
4
+ data.tar.gz: e9db928178faccb9a8825f27a655d33d2488197985211b22ff78b48bdfd4d8bb
5
5
  SHA512:
6
- metadata.gz: 0b3e3465f50d1a9b2b2043aede40cfdc4345c9bf3c6be392b7c9dd7b898b9f4a6352bfde02c5e74761b737a55cb20af6a60cb781c359d2d0108c959bf18be755
7
- data.tar.gz: f5935b8d432442845fa5cd64490cc480ee46ebd341f6be3041f76e20dadc259395d41a28cbcf382531c1a4e27014d850751800afe4a6824f86d41ea773e03615
6
+ metadata.gz: afe0f40872939558ac3112ac26c1cb2186203174d5a68247d01a8559bb9054b6f8f2f0538359f609149e95b7cac755b21c2823e12e97f86096814846855c6d5d
7
+ data.tar.gz: a5d72718244ef7dd72d667660e21f7e958c2d5025d2da6818f9dde169e7a8841aa6389a281294da28dfbb0f3fe972f7e6de82db81eaa17b2c048d1b3c59f1ecc
data/.travis.yml CHANGED
@@ -1,27 +1,29 @@
1
- ---
2
1
  language: ruby
3
2
  sudo: false
4
3
  cache: bundler
5
4
  script:
6
- - bundle exec rake spec
5
+ - bundle exec rake spec
6
+ - bundle exec rake build
7
7
  rvm:
8
- - 1.8.7
9
- - 1.9.3
10
- - 2.0.0
11
- - 2.1.5
12
- env:
13
- - FACTER_GEM_VERSION="~> 1.6.0"
14
- - FACTER_GEM_VERSION="~> 1.7.0"
15
- - FACTER_GEM_VERSION="~> 2.0.0"
16
- - FACTER_GEM_VERSION="~> 2.1.0"
17
- - FACTER_GEM_VERSION="~> 2.2.0"
18
- - FACTER_GEM_VERSION="~> 2.3.0"
19
- - FACTER_GEM_VERSION="~> 2.4.0"
20
- - FACTER_GEM_VERSION="~> 2.0"
8
+ - 2.1
9
+ - 2.2
10
+ - 2.3
11
+ - 2.4
12
+ - 2.5
21
13
  matrix:
22
14
  fast_finish: true
23
- allow_failures:
24
- - rvm: 1.8.7
25
- - rvm: 1.9.3
15
+ include:
16
+ - rvm: 2.6
17
+ env: COVERAGE=true
26
18
  notifications:
27
19
  email: false
20
+ deploy:
21
+ provider: rubygems
22
+ api_key:
23
+ secure: EGvtHfBYUSjhZjLPGZHHH7Exsu9xyYSNlbI/F9SNRDmY568tBZs1Pw05Pr9dhUXajs3xXPkHQwMEBgNs2Rg2SPc6+dCyvabbNM2U58yj5R5D7+ZdUWC1APgjiDvBhm0N5hihmAnoBKPlmPKMh91OQwKI/8/GOhWAQaIZRnNBzMQ+gwHQ8xIkqt3unxJ/LtRybFDzTF5aMtIHrfE8kV08BLaKUzJptzj7Wt5Ms1zE/2UV1S7DhSvZnxWaWtNZwaQPo9NFhjHr5k3nLIoWi6Ge3khVSukZcAki9cR37Tjeyms5B10hp6jW5c6EgCDQp5VNcD/1LgtTs8fWI6mvTsa3YCyaQdVy2SvhUD88/CohFvLXbGcdkFFzwhPa57aCKazq14fh5epScRzAfGpJojkPcxdc5/fiuZiaPg+jmT/OMFqNjQW1C6m2S+VltlXVCyjT83Ri9J9/AEu708akErhz7XjcspxJL8//KVvS/3o4hjtoef1OXxRN+oh3VGwbEZSiqOmjxr6/AigaYsrWOTdz+OZa4fGYbUb9hMHnq314cjgGUMyzZ9tQN8v4mMZb1ZKZPuqrP6um1Y7WbHQJvwl3sXEUuDN68eyWp103M1nyma6hON4+F+r58kTuoWRmy06ZsaEjz57bFxdnDjB8It8V7pI0bcmfs/q5tMIPw6Gh14w=
24
+ gem: rspec-puppet-facts
25
+ on:
26
+ tags: true
27
+ repo: mcanevet/rspec-puppet-facts
28
+ all_branches: true
29
+ rvm: 2.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 2019-07-29 - Release 1.9.5
2
+ - The default version of Facter to search for is now configurable with
3
+ `RSpec.configuration.default_facter_version`.
4
+ - When passing a `:supported_os` hash to `on_supported_os()`, single
5
+ `operatingsystemrelease` values can now be specified as a String rather than
6
+ an Array with a single String.
7
+ - Dependency on the `mcollective-client` gem removed. The `mco_version` fact
8
+ will now optionally be set if the gem is installed.
9
+ - The fact names can now be provided to tests as Strings instead of Symbols by
10
+ setting `RSpec.configuration.facterdb_string_keys` to `true`.
11
+ - Dropped support for Ruby < 2.1.0
12
+
13
+ ## 2019-03-22 - Release 1.9.4
14
+ - Take two on getting rubygems autodeploy going. So much for docs,
15
+ looking at other projects for this one.
16
+ ## 2019-03-22 - Release 1.9.3
17
+ - Various CI updates - [Garrett Honeycutt](https://github.com/ghoneycutt/)
18
+ - Symbolize hash keys in `register_custom_fact`
19
+ [https://github.com/mcanevet/rspec-puppet-facts/pull/77](https://github.com/mcanevet/rspec-puppet-facts/pull/77)
20
+
1
21
  ## 2018-10-24 - Release 1.9.2
2
22
  - Catch the right `LoadError` on missing augeas gem. Thanks to [baurmatt](https://github.com/baurmatt) for the quick fix, and [rodjek](https://github.com/rodjek) for dealing with the testing
3
23
 
data/Gemfile CHANGED
@@ -7,9 +7,3 @@ if facterversion = ENV['FACTER_GEM_VERSION']
7
7
  else
8
8
  gem 'facter', :require => false
9
9
  end
10
-
11
- platforms :ruby_18, :ruby_19 do
12
- gem 'json', '~> 1.0'
13
- gem 'json_pure', '~> 1.0'
14
- gem 'tins', '~> 1.6.0'
15
- end
data/README.md CHANGED
@@ -16,7 +16,7 @@ If you're using Bundler to manage gems in your module repository, install `rspec
16
16
  1. Add the following line to your `Gemfile`:
17
17
 
18
18
  ```ruby
19
- gem 'rspec-puppet-facts', '~> 1.7', :require => false
19
+ gem 'rspec-puppet-facts', :require => false
20
20
  ```
21
21
 
22
22
  2. Run `bundle install`.
@@ -71,6 +71,19 @@ describe 'myclass::debian' do
71
71
  end
72
72
  ```
73
73
 
74
+ ## Specifying a default Facter version
75
+
76
+ By default, `os_supported_os` will return the facts for the version of Facter
77
+ that it has loaded (usually this is Facter 2.5.1). This behaviour can be
78
+ overridden by setting the `default_facter_version` RSpec setting in your
79
+ `spec/spec_helper.rb` file.
80
+
81
+ ```ruby
82
+ RSpec.configure do |c|
83
+ c.default_facter_version = '3.14.0'
84
+ end
85
+ ```
86
+
74
87
  ## Usage
75
88
 
76
89
  Use the `on_supported_os` iterator to loop through all of your module's supported operating systems. This allows you to simplify your tests and remove a lot of duplicate code.
@@ -2,7 +2,11 @@ require 'puppet'
2
2
  require 'facter'
3
3
  require 'facterdb'
4
4
  require 'json'
5
- require 'mcollective'
5
+
6
+ RSpec.configure do |c|
7
+ c.add_setting :default_facter_version, :default => Facter.version
8
+ c.add_setting :facterdb_string_keys, :default => false
9
+ end
6
10
 
7
11
  # The purpose of this module is to simplify the Puppet
8
12
  # module's RSpec tests by looping through all supported
@@ -31,7 +35,7 @@ module RspecPuppetFacts
31
35
  opts[:hardwaremodels] ||= ['x86_64']
32
36
  opts[:hardwaremodels] = [opts[:hardwaremodels]] unless opts[:hardwaremodels].is_a? Array
33
37
  opts[:supported_os] ||= RspecPuppetFacts.meta_supported_os
34
- opts[:facterversion] ||= Facter.version
38
+ opts[:facterversion] ||= RSpec.configuration.default_facter_version
35
39
 
36
40
  unless (facterversion = opts[:facterversion]) =~ /\A\d+\.\d+(?:\.\d+)*\z/
37
41
  raise ArgumentError, ":facterversion must be in the format 'n.n' or " \
@@ -52,7 +56,7 @@ module RspecPuppetFacts
52
56
  filter = []
53
57
  opts[:supported_os].map do |os_sup|
54
58
  if os_sup['operatingsystemrelease']
55
- os_sup['operatingsystemrelease'].map do |operatingsystemmajrelease|
59
+ Array(os_sup['operatingsystemrelease']).map do |operatingsystemmajrelease|
56
60
  opts[:hardwaremodels].each do |hardwaremodel|
57
61
 
58
62
  os_release_filter = "/^#{operatingsystemmajrelease.split(' ')[0]}/"
@@ -81,7 +85,6 @@ module RspecPuppetFacts
81
85
  end
82
86
 
83
87
  filter << {
84
- :facterversion => facter_version_filter,
85
88
  :operatingsystem => os_sup['operatingsystem'],
86
89
  :operatingsystemrelease => os_release_filter,
87
90
  :hardwaremodel => hardwaremodel,
@@ -91,7 +94,6 @@ module RspecPuppetFacts
91
94
  else
92
95
  opts[:hardwaremodels].each do |hardwaremodel|
93
96
  filter << {
94
- :facterversion => facter_version_filter,
95
97
  :operatingsystem => os_sup['operatingsystem'],
96
98
  :hardwaremodel => hardwaremodel,
97
99
  }
@@ -99,20 +101,39 @@ module RspecPuppetFacts
99
101
  end
100
102
  end
101
103
 
104
+ # FacterDB may have newer versions of facter data for which it contains a subset of all possible
105
+ # facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to
106
+ # cycle through and downgrade Facter versions per platform type until we find matching Facter data.
107
+ filter.each do |filter_spec|
108
+ facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
109
+ db = FacterDB.get_facts(filter_spec.merge({ :facterversion => facter_version_filter }))
110
+
111
+ version = facterversion
112
+ while db.empty? && version !~ /\d+\.0($|\.\d+)/
113
+ version = RspecPuppetFacts.down_facter_version(version)
114
+ facter_version_filter = RspecPuppetFacts.facter_version_to_filter(version)
115
+ db = FacterDB.get_facts(filter_spec.merge({ :facterversion => facter_version_filter }))
116
+ end
117
+
118
+ next if db.empty?
119
+
120
+ unless version == facterversion
121
+ if RspecPuppetFacts.spec_facts_strict?
122
+ raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion}, aborting"
123
+ else
124
+ RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion}, using v#{version} instead"
125
+ end
126
+ end
127
+
128
+ filter_spec[:facterversion] = facter_version_filter
129
+ end
130
+
102
131
  received_facts = FacterDB::get_facts(filter)
103
132
  unless received_facts.any?
104
133
  RspecPuppetFacts.warning "No facts were found in the FacterDB for: #{filter.inspect}"
105
134
  return {}
106
135
  end
107
136
 
108
- unless version == facterversion
109
- if RspecPuppetFacts.spec_facts_strict?
110
- raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion}, aborting"
111
- else
112
- RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion}, using v#{version} instead"
113
- end
114
- end
115
-
116
137
  os_facts_hash = {}
117
138
  received_facts.map do |facts|
118
139
  # Fix facter bug
@@ -134,9 +155,16 @@ module RspecPuppetFacts
134
155
  facts.merge! RspecPuppetFacts.common_facts
135
156
  os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
136
157
  end
158
+
159
+ return stringify_keys(os_facts_hash) if RSpec.configuration.facterdb_string_keys
160
+
137
161
  os_facts_hash
138
162
  end
139
163
 
164
+ def stringify_keys(hash)
165
+ Hash[hash.collect { |k,v| [k.to_s, v.is_a?(Hash) ? stringify_keys(v) : v] }]
166
+ end
167
+
140
168
  # Register a custom fact that will be included in the facts hash.
141
169
  # If it should be limited to a particular OS, pass a :confine option
142
170
  # that contains the operating system(s) to confine to. If it should
@@ -211,12 +239,13 @@ module RspecPuppetFacts
211
239
  def self.common_facts
212
240
  return @common_facts if @common_facts
213
241
  @common_facts = {
214
- :mco_version => MCollective::VERSION,
215
- :puppetversion => Puppet.version,
216
- :rubysitedir => RbConfig::CONFIG['sitelibdir'],
217
- :rubyversion => RUBY_VERSION,
242
+ :puppetversion => Puppet.version,
243
+ :rubysitedir => RbConfig::CONFIG['sitelibdir'],
244
+ :rubyversion => RUBY_VERSION,
218
245
  }
219
246
 
247
+ @common_facts[:mco_version] = MCollective::VERSION if mcollective?
248
+
220
249
  if augeas?
221
250
  @common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version')
222
251
  end
@@ -227,6 +256,7 @@ module RspecPuppetFacts
227
256
  # Determine if the Augeas gem is available.
228
257
  # @api private
229
258
  # @return [Boolean] true if the augeas gem could be loaded.
259
+ # :nocov:
230
260
  def self.augeas?
231
261
  require 'augeas'
232
262
  true
@@ -234,6 +264,19 @@ module RspecPuppetFacts
234
264
  RspecPuppetFacts.warning "Failed to retrieve Augeas version: #{e}"
235
265
  false
236
266
  end
267
+ # :nocov:
268
+
269
+ # Determine if the mcollective gem is available
270
+ # @api private
271
+ # @return [Boolean] true if the mcollective gem could be loaded.
272
+ # :nocov:
273
+ def self.mcollective?
274
+ require 'mcollective'
275
+ true
276
+ rescue LoadError
277
+ false
278
+ end
279
+ # :nocov:
237
280
 
238
281
  # Get the "operatingsystem_support" structure from
239
282
  # the parsed metadata.json file
@@ -2,6 +2,6 @@ module RspecPuppetFacts
2
2
  # This module contains the current version constant
3
3
  module Version
4
4
  # The current version of this gem
5
- STRING = '1.9.2'
5
+ STRING = '1.9.5'
6
6
  end
7
7
  end
@@ -1,26 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
- require "rspec-puppet-facts/version"
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require 'rspec-puppet-facts/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "rspec-puppet-facts"
7
+ s.name = 'rspec-puppet-facts'
7
8
  s.version = RspecPuppetFacts::Version::STRING
8
- s.authors = ["Mickaël Canévet"]
9
- s.email = ["mickael.canevet@camptocamp.com"]
10
- s.homepage = "http://github.com/mcanevet/rspec-puppet-facts"
11
- s.summary = "Standard facts fixtures for Puppet"
12
- s.description = "Contains facts from many Facter version on many Operating Systems"
9
+ s.authors = ['Mickaël Canévet']
10
+ s.email = ['mickael.canevet@camptocamp.com']
11
+ s.homepage = 'http://github.com/mcanevet/rspec-puppet-facts'
12
+ s.summary = 'Standard facts fixtures for Puppet'
13
+ s.description = 'Contains facts from many Facter version on many Operating Systems'
13
14
  s.licenses = 'Apache-2.0'
14
15
 
16
+ # see .travis.yml for the supported ruby versions
17
+ s.required_ruby_version = '>= 2.1.0'
18
+
15
19
  s.files = `git ls-files`.split("\n")
16
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
22
 
19
- if RUBY_VERSION =~ /^1\./
20
- s.add_development_dependency 'mime-types', '< 3.0'
21
- else
22
- s.add_development_dependency 'mime-types'
23
- end
23
+ s.add_development_dependency 'mime-types'
24
24
  s.add_development_dependency 'coveralls'
25
25
  s.add_development_dependency 'rake'
26
26
  s.add_development_dependency 'rspec'
@@ -29,5 +29,4 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency 'json'
30
30
  s.add_runtime_dependency 'facter'
31
31
  s.add_runtime_dependency 'facterdb', '>= 0.5.0'
32
- s.add_runtime_dependency 'mcollective-client'
33
32
  end
@@ -7,6 +7,48 @@ describe RspecPuppetFacts do
7
7
  end
8
8
 
9
9
  describe '#on_supported_os' do
10
+ context 'With RSpec.configuration.facterdb_string_keys' do
11
+ subject(:result) do
12
+ on_supported_os(
13
+ {
14
+ :supported_os => [
15
+ {
16
+ "operatingsystem" => "Debian",
17
+ "operatingsystemrelease" => ['7'],
18
+ },
19
+ ],
20
+ }
21
+ )
22
+ end
23
+
24
+ let(:get_keys) do
25
+ proc { |r| r.keys + r.select { |_,v| v.is_a?(Hash) }.map { |_,v| get_keys.call(v) }.flatten }
26
+ end
27
+
28
+ context 'set to true' do
29
+ before(:each) do
30
+ RSpec.configuration.facterdb_string_keys = true
31
+ end
32
+
33
+ after(:each) do
34
+ RSpec.configuration.facterdb_string_keys = false
35
+ end
36
+
37
+ it 'returns a fact set with all the keys as Strings' do
38
+ expect(get_keys.call(result['debian-7-x86_64'])).to all(be_a(String))
39
+ end
40
+ end
41
+
42
+ context 'set to false' do
43
+ before(:each) do
44
+ RSpec.configuration.facterdb_string_keys = false
45
+ end
46
+
47
+ it 'returns a fact set with all the keys as Symbols or Strings' do
48
+ expect(get_keys.call(result['debian-7-x86_64'])).to all(be_a(Symbol).or(be_a(String)))
49
+ end
50
+ end
51
+ end
10
52
 
11
53
  context 'Without specifying supported_os' do
12
54
  subject { on_supported_os }
@@ -142,6 +184,30 @@ describe RspecPuppetFacts do
142
184
  end
143
185
  end
144
186
 
187
+ context 'When specifying a supported_os with a single release as a String' do
188
+ subject(:factsets) do
189
+ on_supported_os(
190
+ {
191
+ :supported_os => [
192
+ { 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => '7' },
193
+ ]
194
+ }
195
+ )
196
+ end
197
+
198
+ it 'returns a Hash' do
199
+ expect(factsets).to be_a(Hash)
200
+ end
201
+
202
+ it 'returns a single fact set' do
203
+ expect(factsets.size).to eq(1)
204
+ end
205
+
206
+ it 'returns a fact set for the specified release' do
207
+ expect(factsets).to include('redhat-7-x86_64' => include(:operatingsystemmajrelease => '7'))
208
+ end
209
+ end
210
+
145
211
  context 'When testing Ubuntu' do
146
212
  subject {
147
213
  on_supported_os(
@@ -161,17 +227,13 @@ describe RspecPuppetFacts do
161
227
  }
162
228
 
163
229
  let(:expected_fact_sets) do
164
- if Facter.version.to_f < 1.7
165
- ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64']
166
- else
167
- ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
168
- end
230
+ ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
169
231
  end
170
232
 
171
233
  it 'should return a hash' do
172
234
  expect(subject.class).to eq Hash
173
235
  end
174
- it 'should have 4 elements' do
236
+ it 'should have 3 elements' do
175
237
  expect(subject.size).to eq(expected_fact_sets.size)
176
238
  end
177
239
  it 'should return supported OS' do
@@ -420,17 +482,38 @@ describe RspecPuppetFacts do
420
482
  expect(subject.size).to eq 2
421
483
  end
422
484
  it 'should return supported OS' do
423
- expect(subject.keys.sort).to eq %w(
424
- archlinux-3-x86_64
425
- debian-8-x86_64
426
- )
485
+ expect(subject.keys.sort).to include(a_string_matching(/\Aarchlinux-\d+-x86_64/), 'debian-8-x86_64')
427
486
  end
428
487
  end
429
488
 
430
489
  context 'Without a custom facterversion in the options hash' do
490
+ subject do
491
+ on_supported_os(
492
+ supported_os: [
493
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
494
+ ]
495
+ )
496
+ end
497
+
498
+ it 'returns facts from the loaded facter version' do
499
+ facter_version = Facter.version.split('.')
500
+ is_expected.to match(
501
+ 'centos-7-x86_64' => include(
502
+ :facterversion => /\A#{facter_version[0]}\.#{facter_version[1]}\./
503
+ )
504
+ )
505
+ end
506
+ end
507
+
508
+ context 'With a default Facter version specified in the RSpec configuration' do
431
509
  before(:each) do
432
- allow(Facter).to receive(:version).and_return('2.4.5')
510
+ RSpec.configuration.default_facter_version = '3.1.0'
511
+ end
512
+
513
+ after(:each) do
514
+ RSpec.configuration.default_facter_version = Facter.version
433
515
  end
516
+
434
517
  subject do
435
518
  on_supported_os(
436
519
  supported_os: [
@@ -439,10 +522,10 @@ describe RspecPuppetFacts do
439
522
  )
440
523
  end
441
524
 
442
- it 'returns facts from the loaded facter version' do
525
+ it 'returns facts from the specified default Facter version' do
443
526
  is_expected.to match(
444
527
  'centos-7-x86_64' => include(
445
- facterversion: /\A2\.4\./
528
+ :facterversion => /\A3\.1\./
446
529
  )
447
530
  )
448
531
  end
@@ -466,7 +549,7 @@ describe RspecPuppetFacts do
466
549
  major, minor = Facter.version.split('.')
467
550
  is_expected.to match(
468
551
  'centos-7-x86_64' => include(
469
- facterversion: /\A#{major}\.[#{minor}#{minor.to_i + 1}]\./
552
+ :facterversion => /\A#{major}\.[#{minor}#{minor.to_i + 1}]\./
470
553
  )
471
554
  )
472
555
  end
@@ -493,7 +576,7 @@ describe RspecPuppetFacts do
493
576
 
494
577
  it 'returns facts from a facter version matching 3.1' do
495
578
  is_expected.to match(
496
- 'centos-7-x86_64' => include(facterversion: '3.1.6')
579
+ 'centos-7-x86_64' => include(:facterversion => '3.1.6')
497
580
  )
498
581
  end
499
582
  end
@@ -510,7 +593,7 @@ describe RspecPuppetFacts do
510
593
 
511
594
  it 'returns facts from a facter version matching 3.1' do
512
595
  is_expected.to match(
513
- 'centos-7-x86_64' => include(facterversion: '3.1.6')
596
+ 'centos-7-x86_64' => include(:facterversion => '3.1.6')
514
597
  )
515
598
  end
516
599
  end
@@ -527,7 +610,7 @@ describe RspecPuppetFacts do
527
610
 
528
611
  it 'returns facts from a facter version matching 3.3' do
529
612
  is_expected.to match(
530
- 'centos-7-x86_64' => include(facterversion: '3.3.0')
613
+ 'centos-7-x86_64' => include(:facterversion => '3.3.0')
531
614
  )
532
615
  end
533
616
  end
@@ -544,7 +627,7 @@ describe RspecPuppetFacts do
544
627
 
545
628
  it 'returns facts from a facter version matching 3.3' do
546
629
  is_expected.to match(
547
- 'centos-7-x86_64' => include(facterversion: '3.3.0')
630
+ 'centos-7-x86_64' => include(:facterversion => '3.3.0')
548
631
  )
549
632
  end
550
633
  end
@@ -564,6 +647,36 @@ describe RspecPuppetFacts do
564
647
  /:facterversion must be in the /)
565
648
  end
566
649
  end
650
+
651
+ context 'Downgrades to a facter version with facts per OS' do
652
+ subject do
653
+ on_supported_os(
654
+ supported_os: [
655
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
656
+ { 'operatingsystem' => 'OpenSuSE', 'operatingsystemrelease' => %w[42] }
657
+ ],
658
+ facterversion: '3.9.5'
659
+ )
660
+ end
661
+
662
+ before(:each) do
663
+ allow(FacterDB).to receive(:get_facts).and_call_original
664
+ allow(FacterDB).to receive(:get_facts).with(
665
+ a_hash_including(facterversion: "/\\A3\\.9\\./", operatingsystem: 'CentOS')
666
+ ).and_return([])
667
+ end
668
+
669
+ it 'returns CentOS facts from a facter version matching 3.8' do
670
+ is_expected.to include(
671
+ 'centos-7-x86_64' => include(:facterversion => '3.8.0')
672
+ )
673
+ end
674
+ it 'returns OpenSuSE facts from a facter version matching 3.9' do
675
+ is_expected.to include(
676
+ 'opensuse-42-x86_64' => include(:facterversion => '3.9.2')
677
+ )
678
+ end
679
+ end
567
680
  end
568
681
 
569
682
  context '#add_custom_fact' do
@@ -620,7 +733,7 @@ describe RspecPuppetFacts do
620
733
  it 'should not add "augeasversion" if Augeas is supported' do
621
734
  allow(described_class).to receive(:augeas?).and_return(false)
622
735
  RspecPuppetFacts.reset
623
- expect(subject.common_facts).not_to include :augeasversion
736
+ expect(subject.common_facts).not_to include(:augeasversion)
624
737
  end
625
738
 
626
739
  it 'should determine the Augeas version if Augeas is supported' do
@@ -643,6 +756,33 @@ describe RspecPuppetFacts do
643
756
  it 'can output a warning message' do
644
757
  expect { RspecPuppetFacts.warning('test') }.to output(/test/).to_stderr_from_any_process
645
758
  end
759
+
760
+ context 'when mcollective is available' do
761
+ module MCollective_stub
762
+ VERSION = 'my_version'
763
+ end
764
+
765
+ before(:each) do
766
+ allow(described_class).to receive(:mcollective?).and_return(true)
767
+ stub_const('MCollective', MCollective_stub)
768
+ described_class.reset
769
+ end
770
+
771
+ it 'includes an "mco_version" fact' do
772
+ expect(subject.common_facts).to include(:mco_version => 'my_version')
773
+ end
774
+ end
775
+
776
+ context 'when mcollective is not available' do
777
+ before(:each) do
778
+ allow(described_class).to receive(:mcollective?).and_return(false)
779
+ described_class.reset
780
+ end
781
+
782
+ it 'does not include an "mco_version" fact' do
783
+ expect(subject.common_facts).not_to include(:mco_version)
784
+ end
785
+ end
646
786
  end
647
787
 
648
788
  describe '.facter_version_to_filter' do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ if ENV['COVERAGE']
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
3
5
 
4
6
  require 'rspec'
5
7
  require 'rspec-puppet-facts'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet-facts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickaël Canévet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2019-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.5.0
139
- - !ruby/object:Gem::Dependency
140
- name: mcollective-client
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  description: Contains facts from many Facter version on many Operating Systems
154
140
  email:
155
141
  - mickael.canevet@camptocamp.com
@@ -184,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
170
  requirements:
185
171
  - - ">="
186
172
  - !ruby/object:Gem::Version
187
- version: '0'
173
+ version: 2.1.0
188
174
  required_rubygems_version: !ruby/object:Gem::Requirement
189
175
  requirements:
190
176
  - - ">="
@@ -192,8 +178,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
178
  version: '0'
193
179
  requirements: []
194
180
  rubyforge_project:
195
- rubygems_version: 2.7.6
181
+ rubygems_version: 2.7.6.2
196
182
  signing_key:
197
183
  specification_version: 4
198
184
  summary: Standard facts fixtures for Puppet
199
- test_files: []
185
+ test_files:
186
+ - spec/fixtures/metadata.json
187
+ - spec/fixtures/metadata.json_with_missing_operatingsystem_support
188
+ - spec/rspec_puppet_facts_spec.rb
189
+ - spec/spec_helper.rb