Comments (7)
Thanks for reporting this! Could you send us a PR to fix the docs?
from rspec-puppet-facts.
Hah, you assume I've found a solution yet. 🙁 That would be nice, still looking.
from rspec-puppet-facts.
You would need to use os_facts[:osfamily]
instead of facts[:osfamily]
since that's what you've called the facts variable in on_supported_os.each do |os, os_facts|
. Notice that the example actually calls the facts variable facts
, not os_facts
:
on_supported_os.each do |os, facts|
context "on #{os}" do
...
# If you need to specify any operating system specific tests
case facts[:osfamily]
Also note that let
definitions are only available within an example, e.g. it { ... }
and not example groups, e.g. context ...
. So facts[:osfamily]
would work for you within an it
block, but not within a context
block.
I have run into this confusion myself as the Puppet Development Kit spec templates use os_facts
while the examples in this documentation use facts
, e.g. https://github.com/puppetlabs/pdk-templates/blob/2b3320584b8d6ceb9027b441582bb4e16c3d6350/object_templates/class_spec.erb#L4 and https://github.com/puppetlabs/pdk-templates/blob/2b3320584b8d6ceb9027b441582bb4e16c3d6350/object_templates/defined_type_spec.erb#L9. Would it make sense to update this documentation to match the PDK templates?
from rspec-puppet-facts.
Perhaps it would be better to update PDK's templates to use facts
as that makes more sense than their implementation using os_facts
from rspec-puppet-facts.
No, in this case it's the rspec-puppet-facts documentation that is wrong. The facts
local variable is actually a memoised helper expected to be created by let(:facts)
as standard practice in rspec-puppet. The docs for rspec-puppet-facts set up a rather confusing situation where one of the facts
values ends up shadowed, which while it technically works it should not be encouraged.
on_supported_os.each do |os, facts| # <-- facts hash added to scope
let(:facts) do # <-- facts hash now shadowed by the memoised facts helper
facts # <-- Want to guess what this value will be at a specific time of evaluation?
end
from rspec-puppet-facts.
@rodjek you seem to know what's going on with this, could you send a PR to the docs?
from rspec-puppet-facts.
@towo rodjek/rspec-puppet#774 (comment) describes correct syntax.
from rspec-puppet-facts.
Related Issues (20)
- rspec-puppet-facts hangs searching for facter version HOT 3
- More docs changes needed HOT 1
- Overriding structured facts HOT 3
- Memoizing facts HOT 3
- remove json as a dependency HOT 2
- Cut a new release HOT 1
- Reduce calls to FacterDB
- Allow modules to export custom fact values HOT 1
- Push 2.0.1 git tag to Github HOT 1
- Fail tests when no facts are found in facterdb
- "add_custom_fact" creates String-Facts instead of Symbol-Facts HOT 1
- release notes for 3.0.0
- Cut a new release to support windows server 2016 HOT 5
- facterversion filter fails with windows and facter version 3.x HOT 2
- File resource is trying to load Windows provider on a non-Windows computer HOT 2
- AIX hardware model should not be x86_64 HOT 2
- PR #72 breaks Puppet 6 HOT 5
- Specify required_ruby_version
- Commit 21442e7 looks to introduce hard to debug behavior HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspec-puppet-facts.