Comments (4)
Got it working doing this. Thanks!
describe "profiles class without any parameters" do
case facts[:operatingsystemmajrelease]
when '6'
codename = 'Santiago'
when '7'
codename = 'Maipo'
end
let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
let(:params) {{ }}
let(:facts) do
facts.merge({
:lsbdistcodename => codename,
:concat_basedir => '/tmp',
})
end
from rspec-puppet-facts.
I'm seeing the same behavior when using facts.merge({ :my_custom_fact => 'value' })
. That fact is being ignored. But... If I put the facts.merge({ :my_custom_fact => 'value' })
inside a it
block it works fine.
I'm not sure what I'm doing wrong or if this is expected behavior. Here is an example.
describe 'profiles::base' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context 'with defaults for all parameters' do
let(:facts) do
facts.merge({
:my_custom_fact => "value",
})
end
it do
expect(facts[:my_custom_fact]).to eq 'value'
end
end
end
end
end
Here's the failure
1) profiles::base on centos-6-x86_64 with defaults for all parameters should eq "value"
Failure/Error: expect(facts[:my_custom_fact]).to eq 'value'
expected: "value"
got: nil
(compared using ==)
# ./spec/classes/base_spec.rb:20:in `block (5 levels) in <top (required)>
But if I do this instead, the test passes. Notice that I had to use facts.merge!
instead of facts.merge
.
describe 'profiles::base' do
on_supported_os.each do |os, facts|
context "on #{os}" do
context 'with defaults for all parameters' do
it do
facts.merge!({
:my_custom_fact => "value",
})
expect(facts[:my_custom_fact]).to eq 'value'
end
end
end
end
end
My ruby is not great, so I'm not sure I can identify the culprit or if I'm just mis-understanding something about rspec-puppet-facts
. On a side note, removing the on_supported_os.each do |os, facts|
block and going back to the old method, this works.
describe 'profiles::base' do context 'with defaults for all parameters' do let(:facts) do { :my_custom_fact => 'value' } end it do expect(facts[:my_custom_fact]).to eq 'value' end end end
from rspec-puppet-facts.
After thinking about this for a moment, I think I understand what is happening. When we define the block on_supported_os.each do |os, facts|
this essentially overrides the let(:facts)
when defined further down in a describe or context block. I ended up re-naming the facts
loop variable to default_facts
and I can indeed, merge custom facts in another describe or context block.
Here's a working example:
describe 'profiles::base' do
on_supported_os.each do |os, default_facts|
context "on #{os}" do
context 'with defaults for all parameters' do
let(:facts) do
default_facts.merge({
:my_custom_fact => 'value'
})
end
it do
expect(facts[:my_custom_fact]).to eq 'value'
end
it do
expect(facts[:osfamily]).to eq 'RedHat'
end
end
end
end
end
from rspec-puppet-facts.
@phathocker lsb facts are not availble on RedHat untill you install the redhat-lsb-code package, which is not installed by default, so they are not included in the facts database (facterdb). However you can appends the missing facts to the facts hash using this https://github.com/mcanevet/rspec-puppet-facts/blob/master/README.md#append-some-facts.
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
- facts cannot be cased as described HOT 7
- 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.