rspec-puppet-facts 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e501268fb551da91bff54951aee4dc884f117a4b
4
- data.tar.gz: cabe7a413415661d69ab685a614e7c6bfbe50729
3
+ metadata.gz: 785242ffa008d8289d585447477c09447bda5d8b
4
+ data.tar.gz: 0f112311ebf40c1b3272e6276d1341eb1aa51eec
5
5
  SHA512:
6
- metadata.gz: 3cca12e796f02836127490f652cf3ca9a461878e7ea1d18ac94e84986ec3575bb1b60ae4d02144eeaa824ab3300251d31e1f4ff00dfd177d8d2c5d709e0bf71c
7
- data.tar.gz: e7ae8569cc4d2715effe03add802b420fe52c3f76b7c94bdbb72d8c83e4d1160ab559d7ce99dac4c39d933a8b9478047a07155cf86e907904205cd9e17cb95f2
6
+ metadata.gz: 017a8282b68844be3988ec6b514bff9311c0fe953474ba8db434a5f83481f6adcf981c1a15b2a87f9bb2855655de9f0eaed03f5cac839dd10808c990682bd644
7
+ data.tar.gz: e4f609545cfefa58d7b8779c1741f4db8ce8294a08bff965fc0a767895fa715d57f09b61ccb664bd5b78e2697aadc126772350b79a70202e3ac6ed1ab42a72eb
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ coverage/
7
7
  .idea
8
8
  doc
9
9
  .yardoc
10
+ vendor/
@@ -1,3 +1,6 @@
1
+ ##2017-06-23 - Release 1.8.0
2
+ - Support specifying facter version
3
+
1
4
  ##2017-01-04 - Release 1.7.1
2
5
  - Ignore case when choosing H/W models
3
6
 
data/README.md CHANGED
@@ -7,14 +7,79 @@ rspec-puppet-facts
7
7
  [![Gem Downloads](https://img.shields.io/gem/dt/rspec-puppet-facts.svg)](https://rubygems.org/gems/rspec-puppet-facts)
8
8
  [![Coverage Status](https://img.shields.io/coveralls/mcanevet/rspec-puppet-facts.svg)](https://coveralls.io/r/mcanevet/rspec-puppet-facts?branch=master)
9
9
 
10
- Based on an original idea from [apenney](https://github.com/apenney/puppet_facts/).
10
+ Based on an original idea from [apenney](https://github.com/apenney/puppet_facts/), this gem provides a method of running your [rspec-puppet](https://github.com/rodjek/rspec-puppet) tests against the facts for all your supported operating systems (provided by [facterdb](https://github.com/camptocamp/facterdb). This simplifies unit testing because you don't need to specify the facts yourself.
11
11
 
12
- Simplify your unit tests by looping on every supported Operating System and populating facts.
12
+ ## Installation
13
13
 
14
- Testing a class or define
15
- -------------------------
14
+ If you're using Bundler to manage gems in your module repository, install `rspec-puppet-facts` by adding it to the Gemfile.
16
15
 
17
- ### Before
16
+ 1. Add the following line to your `Gemfile`:
17
+
18
+ ```ruby
19
+ gem 'rspec-puppet-facts', '~> 1.7', :require => false
20
+ ```
21
+
22
+ 2. Run `bundle install`.
23
+
24
+ If you're not using Bundler, install the `rspec-puppet-facts` manually.
25
+
26
+ 1. On the command line, run:
27
+
28
+ ```bash
29
+ $ gem install rspec-puppet-facts
30
+ ```
31
+
32
+ After the gem is installed (using either method), make the gem available to rspec by adding the following lines in your `spec/spec_helper.rb` file. Place the lines after `require 'rspec-puppet'` and before the `RSpec.configure` block, if one exists.
33
+
34
+ ```ruby
35
+ require 'rspec-puppet-facts'
36
+ include RspecPuppetFacts
37
+ ```
38
+
39
+ ## Specifying the supported operating systems
40
+
41
+ To determine which facts to run your tests against, `rspec-puppet-facts` checks your module's `metadata.json` to find out what operating systems your module supports. The `metadata.json` file is located in the root of your module. To learn more about this file, see Puppet's [metatdata](https://docs.puppet.com/puppet/latest/modules_metadata.html) documentation.
42
+
43
+ By default, `rspec-puppet-facts` provides the facts only for `x86_64` architecture. However, you can override this default and the supported operating system list by passing a hash to `on_supported_os` in your tests. This hash must contain either or both of the following keys:
44
+
45
+ * `:hardwaremodels` - An array of hardware architecture names, as strings.
46
+ * `:supported_os` - An array of hashes representing the operating systems.
47
+ **Note: the keys of these hashes must be strings**
48
+ * `'operatingsystem'` - The name of the operating system, as a string.
49
+ * `'operatingsystemrelease'` - An array of version numbers, as strings.
50
+
51
+ This is particularly useful if your module is split into operating system subclasses. For example, if you had a class called `myclass::debian` that you wanted to test against Debian 6 and Debian 7 on both `x86_64` _and_ `i386` architectures, you could write the following test:
52
+
53
+ ```ruby
54
+ require 'spec_helper'
55
+
56
+ describe 'myclass::debian' do
57
+ test_on = {
58
+ :hardwaremodels => ['x86_64', 'i386'],
59
+ :supported_os => [
60
+ {
61
+ 'operatingsystem' => 'Debian',
62
+ 'operatingsystemrelease' => ['6', '7'],
63
+ },
64
+ ],
65
+ }
66
+
67
+ on_supported_os(test_on).each do |os, facts|
68
+ it { is_expected.to compile.with_all_deps }
69
+ end
70
+ end
71
+ ```
72
+
73
+ ## Usage
74
+
75
+ 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.
76
+
77
+ Each iteration of `on_supported_os` provides two variables to your tests. (In the code examples below, these variables are specified by the values between the pipe (`|`) characters.)
78
+
79
+ * The first value is the name of the fact set. This is made from the values of the operatingsystem, operatingsystemmajrelease, and architecture facts separated by dashes (for example, 'debian-7-x86_64').
80
+ * The second value is the facts for that combination of operating system, release, and architecture.
81
+
82
+ For example, previously, you might have written a test that specified Debian 7 and Red Hat 6 as the supported modules:
18
83
 
19
84
  ```ruby
20
85
  require 'spec_helper'
@@ -29,10 +94,10 @@ describe 'myclass' do
29
94
  :operatingsystemmajrelease => '7',
30
95
  ...
31
96
  }
32
-
33
- it { is_expected.to compile.with_all_deps }
34
- ...
35
97
  end
98
+
99
+ it { is_expected.to compile.with_all_deps }
100
+ ...
36
101
  end
37
102
 
38
103
  context "on redhat-6-x86_64" do
@@ -43,17 +108,17 @@ describe 'myclass' do
43
108
  :operatingsystemmajrelease => '6',
44
109
  ...
45
110
  }
46
-
47
- it { is_expected.to compile.with_all_deps }
48
- ...
49
111
  end
112
+
113
+ it { is_expected.to compile.with_all_deps }
114
+ ...
50
115
  end
51
116
 
52
117
  ...
53
118
  end
54
119
  ```
55
120
 
56
- ### After
121
+ With `on_supported_os` iteration, you can rewrite this test to loop over each of the supported operating systems without explicitly specifying them:
57
122
 
58
123
  ```ruby
59
124
  require 'spec_helper'
@@ -68,6 +133,8 @@ describe 'myclass' do
68
133
 
69
134
  it { is_expected.to compile.with_all_deps }
70
135
  ...
136
+
137
+ # If you need any to specify any operating system specific tests
71
138
  case facts[:osfamily]
72
139
  when 'Debian'
73
140
  ...
@@ -79,55 +146,63 @@ describe 'myclass' do
79
146
  end
80
147
  ```
81
148
 
82
- Testing a type or provider
83
- --------------------------
149
+ ### Testing a type or provider
84
150
 
85
- ### Before
151
+ Use `on_supported_os` in the same way for your type and provider unit tests.
152
+
153
+ **Specifying each operating system**:
86
154
 
87
155
  ```ruby
88
156
  require 'spec_helper'
89
157
 
90
- describe Puppet::Type.type(:mytype) do
158
+ describe 'mytype' do
91
159
 
92
160
  context "on debian-7-x86_64" do
93
- before :each do
94
- Facter.clear
95
- Facter.stubs(:fact).with(:osfamily).returns Facter.add(:osfamily) { setcode { 'Debian' } }
96
- Facter.stubs(:fact).with(:operatingsystem).returns Facter.add(:operatingsystem) { setcode { 'Debian' } }
97
- Facter.stubs(:fact).with(:operatingsystemmajrelease).returns Facter.add(:operatingsystemmajrelease) { setcode { '7' } }
161
+ let(:facts) do
162
+ {
163
+ :osfamily => 'Debian',
164
+ :operatingsystem => 'Debian',
165
+ :operatingsystemmajrelease => '7',
166
+ }
98
167
  end
168
+
169
+ it { should be_valid_type }
99
170
  ...
100
171
  end
101
172
 
102
173
  context "on redhat-7-x86_64" do
103
- before :each do
104
- Facter.clear
105
- Facter.stubs(:fact).with(:osfamily).returns Facter.add(:osfamily) { setcode { 'RedHat' } }
106
- Facter.stubs(:fact).with(:operatingsystem).returns Facter.add(:operatingsystem) { setcode { 'RedHat' } }
107
- Facter.stubs(:fact).with(:operatingsystemmajrelease).returns Facter.add(:operatingsystemmajrelease) { setcode { '7' } }
174
+ let(:facts) do
175
+ {
176
+ :osfamily => 'RedHat',
177
+ :operatingsystem => 'RedHat',
178
+ :operatingsystemmajrelease => '7',
179
+ }
108
180
  end
181
+
182
+ it { should be_valid_type }
109
183
  ...
110
184
  end
111
185
  end
112
186
 
113
187
  ```
114
188
 
115
- ### After
189
+ **Looping with `on_supported_os` iterator**:
116
190
 
117
191
  ```ruby
118
192
  require 'spec_helper'
119
193
 
120
- describe Puppet::Type.type(:mytype) do
194
+ describe 'mytype' do
121
195
 
122
196
  on_supported_os.each do |os, facts|
123
197
  context "on #{os}" do
124
- before :each do
125
- Facter.clear
126
- facts.each do |k, v|
127
- Facter.stubs(:fact).with(k).returns Facter.add(k) { setcode { v } }
128
- end
198
+ let(:facts) do
199
+ facts
129
200
  end
201
+
202
+ it { should be_valid_type }
130
203
  ...
204
+
205
+ # If you need to specify any operating system specific tests
131
206
  case facts[:osfamily]
132
207
  when 'Debian'
133
208
  ...
@@ -141,115 +216,87 @@ end
141
216
 
142
217
  ```
143
218
 
144
- Testing a function
145
- ------------------
219
+ ### Testing a function
146
220
 
147
- ### Before
221
+ As with testing manifests, types, or providers, `on_supported_os` iteration simplifies your function unit tests.
222
+
223
+ **Specifying each operating system**:
148
224
 
149
225
  ```ruby
150
226
  require 'spec_helper'
151
227
 
152
- describe Puppet::Parser::Functions.function(:myfunction) do
153
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
154
-
228
+ describe 'myfunction' do
155
229
  context "on debian-7-x86_64" do
156
- before :each do
157
- scope.stubs(:lookupvar).with('::osfamily').returns('Debian')
158
- scope.stubs(:lookupvar).with('osfamily').returns('Debian')
159
- scope.stubs(:lookupvar).with('::operatingsystem').returns('Debian')
160
- scope.stubs(:lookupvar).with('operatingsystem').returns('Debian')
161
- ...
230
+ let(:facts) do
231
+ {
232
+ :osfamily => 'Debian',
233
+ :operatingsystem => 'Debian',
234
+ ...
235
+ }
162
236
  end
163
- ...
164
- end
165
237
 
166
- context "on redhat-7-x86_64" do
167
- before :each do
168
- scope.stubs(:lookupvar).with('::osfamily').returns('RedHat')
169
- scope.stubs(:lookupvar).with('osfamily').returns('RedHat')
170
- scope.stubs(:lookupvar).with('::operatingsystem').returns('RedHat')
171
- scope.stubs(:lookupvar).with('operatingsystem').returns('RedHat')
172
- ...
173
- end
238
+ it { should run.with_params('something').and_return('a value') }
174
239
  ...
175
240
  end
176
- end
177
- ```
178
-
179
- ### After
180
-
181
- ```ruby
182
- require 'spec_helper'
183
241
 
184
- describe Puppet::Parser::Functions.function(:myfunction) do
185
- let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
186
-
187
- on_supported_os.each do |os, facts|
188
- context "on #{os}" do
189
- before :each do
190
- facts.each do |k, v|
191
- scope.stubs(:lookupvar).with("::#{k}").returns(v)
192
- scope.stubs(:lookupvar).with(k).returns(v)
193
- end
194
- end
242
+ context "on redhat-7-x86_64" do
243
+ let(:facts) do
244
+ {
245
+ :osfamily => 'RedHat',
246
+ :operatingsystem => 'RedHat',
247
+ ...
248
+ }
195
249
  end
196
250
 
251
+ it { should run.with_params('something').and_return('a value') }
197
252
  ...
198
-
199
253
  end
200
254
  end
201
255
  ```
202
256
 
203
- By default rspec-puppet-facts looks at your `metadata.json` to find supported operating systems and tests only with `x86_64`, but you can specify for each context which ones you want to use:
257
+ **Looping with `on_supported_os` iterator**:
204
258
 
205
259
  ```ruby
206
260
  require 'spec_helper'
207
261
 
208
- describe 'myclass' do
262
+ describe 'myfunction' do
209
263
 
210
- on_supported_os({
211
- :hardwaremodels => ['i386', 'x86_64'],
212
- :supported_os => [
213
- {
214
- "operatingsystem" => "Debian",
215
- "operatingsystemrelease" => [
216
- "6",
217
- "7"
218
- ]
219
- },
220
- {
221
- "operatingsystem" => "RedHat",
222
- "operatingsystemrelease" => [
223
- "5",
224
- "6"
225
- ]
226
- }
227
- ],
228
- }).each do |os, facts|
264
+ on_supported_os.each do |os, facts|
229
265
  context "on #{os}" do
230
266
  let(:facts) do
231
267
  facts
232
268
  end
233
269
 
234
- it { is_expected.to compile.with_all_deps }
270
+ it { should run.with_params('something').and_return('a value') }
235
271
  ...
236
272
  end
237
273
  end
238
274
  end
239
275
  ```
240
276
 
241
- Append some facts:
242
- ------------------
277
+ ### Adding custom fact values
278
+
279
+ By adding custom fact values, you can:
280
+
281
+ * Override fact values
282
+ * Include additional facts in your tests.
283
+ * Add global custom facts for all of your unit tests
284
+ * Add custom facts to only certain operating systems
285
+ * Add custom facts to all operating systems _except_ specific operating systems
286
+ * Create dynamic values for custom facts by setting a lambda as the value.
243
287
 
244
- You can locally override facts in your spec:
288
+ #### Override and add facts
289
+
290
+ To override fact values and include additional facts in your tests, merge values with the facts hash provided by each iteration of `on_supported_os`.
245
291
 
246
292
  ```ruby
247
293
  require 'spec_helper'
248
294
 
249
295
  describe 'myclass' do
250
-
251
296
  on_supported_os.each do |os, facts|
252
297
  context "on #{os}" do
298
+
299
+ # Add the 'foo' fact with the value 'bar' to the tests
253
300
  let(:facts) do
254
301
  facts.merge({
255
302
  :foo => 'bar',
@@ -263,78 +310,57 @@ describe 'myclass' do
263
310
  end
264
311
  ```
265
312
 
266
- You can also globally set facts in `spec/spec_helper.rb`
313
+ #### Set global custom facts
267
314
 
268
- * Simple:
315
+ Set global custom fact values in your `spec/spec_helper.rb` file so that they are automatically available to all of your unit tests using `on_supported_os`.
269
316
 
270
- ```ruby
271
- add_custom_fact :concat_basedir, '/doesnotexist'
272
- ```
317
+ Pass the fact name and value to the `add_custom_fact` function:
273
318
 
274
- * Confine to an OS:
319
+ ```ruby
320
+ require 'rspec-puppet'
321
+ require 'rspec-puppet-facts'
322
+ include RspecPuppetFacts
275
323
 
276
- ```ruby
277
- add_custom_fact :root_home, '/root', :confine => 'redhat-7-x86_64'
278
- ```
324
+ # Add the 'concat_basedir' fact to all tests
325
+ add_custom_fact :concat_basedir, '/doesnotexist'
279
326
 
280
- * Exclude an OS:
327
+ RSpec.configure do |config|
328
+ # normal rspec-puppet configuration
329
+ ...
330
+ end
331
+ ```
281
332
 
282
- ```ruby
283
- add_custom_fact :root_home, '/root', :exclude => 'redhat-7-x86_64'
284
- ```
285
- * Call a proc to get a value:
333
+ #### Confine custom facts
286
334
 
287
- ```ruby
288
- add_custom_fact :root_home, ->(_os,facts) { "/tmp/#{facts['hostname']}" }
289
- ```
335
+ To add custom facts for only certain operating systems, set `confine` with the operating system as a string value:
290
336
 
291
- Usage
292
- -----
337
+ ```ruby
338
+ add_custom_fact :root_home, '/root', :confine => 'redhat-7-x86_64'
339
+ ```
293
340
 
294
- Add this in your Gemfile:
341
+ To add custom facts for all operating systems _except_ specific ones, set `exclude` with the operating system as a string value:
295
342
 
296
343
  ```ruby
297
- gem 'rspec-puppet-facts', :require => false
344
+ add_custom_fact :root_home, '/root', :exclude => 'redhat-7-x86_64'
298
345
  ```
299
346
 
300
- Add this is your `spec/spec_helper.rb`:
347
+ #### Create dynamic facts
348
+
349
+ In addition to the static fact values shown in the previous examples, you can create dynamic values.
350
+
351
+ To do this, pass a lambda as the value for the custom fact. The lambda is passed the same values for operating system name and fact values that your tests are provided by `on_supported_os`.
301
352
 
302
353
  ```ruby
303
- require 'rspec-puppet-facts'
304
- include RspecPuppetFacts
354
+ add_custom_fact :root_home, lambda { |os,facts| "/tmp/#{facts['hostname']" }
305
355
  ```
306
356
 
307
- Run the tests:
357
+ Running your tests
358
+ ------------------
308
359
 
309
- ```bash
310
- rake spec
311
- ```
360
+ For most cases, there is no change to how you run your tests. Running `rake spec` will run all the tests against the facts for all the supported operating systems.
312
361
 
313
- Run the tests only on some of the facts sets:
362
+ If you want to run the tests against the facts for specific operating systems, you can provide a filter in the `SPEC_FACTS_OS` environment variable and only the supported operating systems whose name starts with the specified filter will be used.
314
363
 
315
364
  ```bash
316
365
  SPEC_FACTS_OS='ubuntu-14' rake spec
317
366
  ```
318
-
319
- Finaly, Add some `facter` version to test in your .travis.yml
320
-
321
- ```yaml
322
- ...
323
- matrix:
324
- fast_finish: true
325
- include:
326
- - rvm: 1.8.7
327
- env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
328
- - rvm: 1.8.7
329
- env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
330
- - rvm: 1.9.3
331
- env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.1.0"
332
- - rvm: 1.9.3
333
- env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.2.0"
334
- - rvm: 2.0.0
335
- env: PUPPET_GEM_VERSION="~> 3.0"
336
- allow_failures:
337
- - rvm: 1.8.7
338
- env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
339
- ...
340
- ```
@@ -23,12 +23,22 @@ module RspecPuppetFacts
23
23
  # @param [Hash] opts
24
24
  # @option opts [String,Array<String>] :hardwaremodels The OS architecture names, i.e. x86_64
25
25
  # @option opts [Array<Hash>] :supported_os If this options is provided the data
26
+ # @option opts [String] :facterversion the facter version of which to
27
+ # select facts from, e.g.: '3.6'
26
28
  # will be used instead of the "operatingsystem_support" section if the metadata file
27
29
  # even if the file is missing.
28
30
  def on_supported_os(opts = {})
29
31
  opts[:hardwaremodels] ||= ['x86_64']
30
32
  opts[:hardwaremodels] = [opts[:hardwaremodels]] unless opts[:hardwaremodels].is_a? Array
31
33
  opts[:supported_os] ||= RspecPuppetFacts.meta_supported_os
34
+ opts[:facterversion] ||= Facter.version
35
+
36
+ unless (facterversion = opts[:facterversion]) =~ /\A\d+\.\d+(?:\.\d+)*\z/
37
+ raise ArgumentError, ":facterversion must be in the format 'n.n' or " \
38
+ "'n.n.n' (n is numeric), not '#{facterversion}'"
39
+ end
40
+
41
+ facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
32
42
 
33
43
  filter = []
34
44
  opts[:supported_os].map do |os_sup|
@@ -45,7 +55,7 @@ module RspecPuppetFacts
45
55
  end
46
56
 
47
57
  filter << {
48
- :facterversion => "/^#{Facter.version[0..2]}/",
58
+ :facterversion => facter_version_filter,
49
59
  :operatingsystem => os_sup['operatingsystem'],
50
60
  :operatingsystemrelease => "/^#{operatingsystemmajrelease.split(' ')[0]}/",
51
61
  :hardwaremodel => hardwaremodel,
@@ -55,7 +65,7 @@ module RspecPuppetFacts
55
65
  else
56
66
  opts[:hardwaremodels].each do |hardwaremodel|
57
67
  filter << {
58
- :facterversion => "/^#{Facter.version[0..2]}/",
68
+ :facterversion => facter_version_filter,
59
69
  :operatingsystem => os_sup['operatingsystem'],
60
70
  :hardwaremodel => hardwaremodel,
61
71
  }
@@ -220,4 +230,12 @@ module RspecPuppetFacts
220
230
  @metadata = nil
221
231
  end
222
232
 
233
+ # Generates a JGrep statement expression for a specific facter version
234
+ # @return [String] JGrep statement expression
235
+ # @param version [String] the Facter version
236
+ # @api private
237
+ def self.facter_version_to_filter(version)
238
+ major, minor = version.split('.')
239
+ "/\\A#{major}\\.#{minor}\\./"
240
+ end
223
241
  end
@@ -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.7.1'
5
+ STRING = '1.8.0'
6
6
  end
7
7
  end
@@ -370,6 +370,109 @@ describe RspecPuppetFacts do
370
370
  )
371
371
  end
372
372
  end
373
+
374
+ context 'Without a custom facterversion in the options hash' do
375
+ subject do
376
+ on_supported_os(
377
+ supported_os: [
378
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
379
+ ]
380
+ )
381
+ end
382
+
383
+ it 'returns facts from the loaded facter version' do
384
+ major, minor = Facter.version.split('.')
385
+ is_expected.to match(
386
+ 'centos-7-x86_64' => include(
387
+ facterversion: /\A#{major}\.#{minor}\./
388
+ )
389
+ )
390
+ end
391
+ end
392
+
393
+ context 'With a custom facterversion (3.1) in the options hash' do
394
+ subject do
395
+ on_supported_os(
396
+ supported_os: [
397
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
398
+ ],
399
+ facterversion: '3.1'
400
+ )
401
+ end
402
+
403
+ it 'returns facts from a facter version matching 3.1' do
404
+ is_expected.to match(
405
+ 'centos-7-x86_64' => include(facterversion: '3.1.6')
406
+ )
407
+ end
408
+ end
409
+
410
+ context 'With a custom facterversion (3.1.2) in the options hash' do
411
+ subject do
412
+ on_supported_os(
413
+ supported_os: [
414
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
415
+ ],
416
+ facterversion: '3.1.2'
417
+ )
418
+ end
419
+
420
+ it 'returns facts from a facter version matching 3.1' do
421
+ is_expected.to match(
422
+ 'centos-7-x86_64' => include(facterversion: '3.1.6')
423
+ )
424
+ end
425
+ end
426
+
427
+ context 'With a custom facterversion (3.3) in the options hash' do
428
+ subject do
429
+ on_supported_os(
430
+ supported_os: [
431
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
432
+ ],
433
+ facterversion: '3.3'
434
+ )
435
+ end
436
+
437
+ it 'returns facts from a facter version matching 3.3' do
438
+ is_expected.to match(
439
+ 'centos-7-x86_64' => include(facterversion: '3.3.0')
440
+ )
441
+ end
442
+ end
443
+
444
+ context 'With a custom facterversion (3.3.2) in the options hash' do
445
+ subject do
446
+ on_supported_os(
447
+ supported_os: [
448
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
449
+ ],
450
+ facterversion: '3.3.2'
451
+ )
452
+ end
453
+
454
+ it 'returns facts from a facter version matching 3.3' do
455
+ is_expected.to match(
456
+ 'centos-7-x86_64' => include(facterversion: '3.3.0')
457
+ )
458
+ end
459
+ end
460
+
461
+ context 'With an invalid facterversion in the options hash' do
462
+ let(:method_call) do
463
+ on_supported_os(
464
+ supported_os: [
465
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
466
+ ],
467
+ facterversion: '3'
468
+ )
469
+ end
470
+
471
+ it 'raises an error' do
472
+ expect { method_call }.to raise_error(ArgumentError,
473
+ /:facterversion must be in the /)
474
+ end
475
+ end
373
476
  end
374
477
 
375
478
  context '#add_custom_fact' do
@@ -451,4 +554,69 @@ describe RspecPuppetFacts do
451
554
  end
452
555
  end
453
556
 
557
+ describe '.facter_version_to_filter' do
558
+ context 'when passed a version that is major.minor (1)' do
559
+ subject { RspecPuppetFacts.facter_version_to_filter('1.2') }
560
+
561
+ it 'returns the correct JGrep statement expression' do
562
+ is_expected.to eq('/\A1\.2\./')
563
+ end
564
+ end
565
+
566
+ context 'when passed a version that is major.minor (2)' do
567
+ subject { RspecPuppetFacts.facter_version_to_filter('10.2') }
568
+
569
+ it 'returns the correct JGrep statement expression' do
570
+ is_expected.to eq('/\A10\.2\./')
571
+ end
572
+ end
573
+
574
+ context 'when passed a version that is major.minor (3)' do
575
+ subject { RspecPuppetFacts.facter_version_to_filter('1.20') }
576
+
577
+ it 'returns the correct JGrep statement expression' do
578
+ is_expected.to eq('/\A1\.20\./')
579
+ end
580
+ end
581
+
582
+ context 'when passed a version that is major.minor (4)' do
583
+ subject { RspecPuppetFacts.facter_version_to_filter('10.20') }
584
+
585
+ it 'returns the correct JGrep statement expression' do
586
+ is_expected.to eq('/\A10\.20\./')
587
+ end
588
+ end
589
+
590
+ context 'when passed a version that is major.minor.patch (1)' do
591
+ subject { RspecPuppetFacts.facter_version_to_filter('1.2.3') }
592
+
593
+ it 'returns the correct JGrep statement expression' do
594
+ is_expected.to eq('/\A1\.2\./')
595
+ end
596
+ end
597
+
598
+ context 'when passed a version that is major.minor.patch (2)' do
599
+ subject { RspecPuppetFacts.facter_version_to_filter('10.2.3') }
600
+
601
+ it 'returns the correct JGrep statement expression' do
602
+ is_expected.to eq('/\A10\.2\./')
603
+ end
604
+ end
605
+
606
+ context 'when passed a version that is major.minor.patch (3)' do
607
+ subject { RspecPuppetFacts.facter_version_to_filter('1.20.3') }
608
+
609
+ it 'returns the correct JGrep statement expression' do
610
+ is_expected.to eq('/\A1\.20\./')
611
+ end
612
+ end
613
+
614
+ context 'when passed a version that is major.minor.patch (4)' do
615
+ subject { RspecPuppetFacts.facter_version_to_filter('10.20.3') }
616
+
617
+ it 'returns the correct JGrep statement expression' do
618
+ is_expected.to eq('/\A10\.20\./')
619
+ end
620
+ end
621
+ end
454
622
  end
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.7.1
4
+ version: 1.8.0
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: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types