You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-29Lines changed: 56 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ If you're using Bundler to manage gems in your module repository, install `rspec
22
22
1. Add the following line to your `Gemfile`:
23
23
24
24
```ruby
25
-
gem 'rspec-puppet-facts', :require =>false
25
+
gem 'rspec-puppet-facts', require:false
26
26
```
27
27
28
28
2. Run `bundle install`.
@@ -54,38 +54,18 @@ By default, `rspec-puppet-facts` provides the facts only for `x86_64` architectu
54
54
*`'operatingsystem'` - The name of the operating system, as a string.
55
55
*`'operatingsystemrelease'` - An array of version numbers, as strings.
56
56
57
-
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:
57
+
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 12 and Debian 11 on both `x86_64`_and_`i386` architectures, you could write the following test:
58
58
59
59
```ruby
60
60
require'spec_helper'
61
61
62
-
describe 'myclass::debian'do
63
-
test_on = {
64
-
:hardwaremodels => ['x86_64', 'i386'],
65
-
:supported_os => [
66
-
{
67
-
'operatingsystem' => 'Debian',
68
-
'operatingsystemrelease' => ['6', '7'],
69
-
},
70
-
],
71
-
}
72
-
73
-
on_supported_os(test_on).each do |os, os_facts|
74
-
let (:facts) { os_facts }
75
-
it { is_expected.to compile.with_all_deps }
76
-
end
77
-
end
78
-
```
79
-
Ruby 1.9 and later:
80
-
```ruby
81
-
require'spec_helper'
82
-
83
62
describe 'myclass::raspbian'do
84
63
test_on = {
64
+
hardwaremodels: ['x86_64', 'i386'],
85
65
supported_os: [
86
66
{
87
67
'operatingsystem' => 'Debian',
88
-
'operatingsystemrelease' => ['10', '9', '8'],
68
+
'operatingsystemrelease' => ['12', '11'],
89
69
},
90
70
],
91
71
}
@@ -98,17 +78,64 @@ end
98
78
99
79
## Specifying a default Facter version
100
80
101
-
By default, `on_supported_os` will return the facts for the version of Facter
102
-
that it has loaded (usually this is Facter 2.5.1). This behaviour can be
103
-
overridden by setting the `default_facter_version` RSpec setting in your
104
-
`spec/spec_helper.rb` file.
81
+
By default, `on_supported_os` will return the facts for the version of Facter that it has loaded. It will check for the loaded Puppet version and maps that to the Facter version that Perforce released in the matching AIO.
82
+
The mapping is stored in `ext/puppet_agent_components.json` (check the [maintenance](#maintenance) section for details) and computated in the `facter_version_for_puppet_version` method.
83
+
This behaviour can be overridden by setting the `default_facter_version` RSpec setting in your `spec/spec_helper.rb` file.
105
84
106
85
```ruby
107
86
RSpec.configure do |c|
108
87
c.default_facter_version ='3.14.0'
109
88
end
110
89
```
111
90
91
+
## Symbolized vs stringified facts
92
+
93
+
For a long long time, the first level of keys in a factsets were symbols.
94
+
This was fine before there were structured facts, but structured facts ended up as nested hashes that always had strings.
95
+
This doesn't make sense and easy to get wrong.
96
+
The original data contains only strings so conversion actually costs performance.
97
+
98
+
The option to switch between symbolized vs stringified facts was introduced in [25634f4481f20f2fc7444e867928ca607234e33e](https://github.com/voxpupuli/rspec-puppet-facts/commit/25634f4481f20f2fc7444e867928ca607234e33e) (Release [1.9.5](https://github.com/voxpupuli/rspec-puppet-facts/blob/master/CHANGELOG.md#2019-07-29---release-195)), but version 5.0.0 has resolved various implementation bugs.
99
+
100
+
This can be configured like this:
101
+
102
+
```ruby
103
+
RSpec.configure do |c|
104
+
c.facterdb_string_keys =false
105
+
end
106
+
```
107
+
108
+
In the 5.x release series of rspec-puppet-facts the default `false` is deprecated.
109
+
With the 6.0.0 release we will flip it to `true` (https://github.com/voxpupuli/rspec-puppet-facts/pull/189).
110
+
111
+
You may have the following rspec-puppet test using deprecated symbolized facts:
112
+
113
+
```ruby
114
+
on_supported_os.each do |os, os_facts|
115
+
case os_facts[:os]['name']
116
+
when'Archlinux'
117
+
context 'on Archlinux'do
118
+
it { is_expected.to contain_package('borg') }
119
+
end
120
+
when'Ubuntu'
121
+
end
122
+
end
123
+
```
124
+
125
+
With the string facts, the same test looks like:
126
+
127
+
```ruby
128
+
on_supported_os.each do |os, os_facts|
129
+
case os_facts['os']['name']
130
+
when'Archlinux'
131
+
context 'on Archlinux'do
132
+
it { is_expected.to contain_package('borg') }
133
+
end
134
+
when'Ubuntu'
135
+
end
136
+
end
137
+
```
138
+
112
139
## Usage
113
140
114
141
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.
@@ -475,7 +502,7 @@ fact sets that only make sense in your environment or might contain sensitive in
475
502
To supply external facts to facterdb just set the `FACTERDB_SEARCH_PATHS` environment variable with one or more
476
503
paths to your facts.
477
504
478
-
When separating paths please use the default path separator character supported by your OS.
505
+
When separating paths please use the default path separator character supported by your OS.
0 commit comments