Skip to content

Commit db6cff0

Browse files
bastelfreakekohl
andcommitted
Deprecate symbolized facts
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
1 parent 3ba78cb commit db6cff0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,54 @@ RSpec.configure do |c|
8888
end
8989
```
9090

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+
91139
## Usage
92140

93141
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.

0 commit comments

Comments
 (0)