rspec-puppet is a framework for testing Puppet code with the rspec BDD framework
Questions tagged [rspec-puppet]
49 questions
3
votes
1 answer
Correct way to start RSpec-puppet unit tests
I have created a simple Puppet 4 class and a unit test to go along with it as follows (after executing touch metadata.json; rspec-puppet-init while in modules/test/):
# modules/test/manifests/hello_world1.pp
class test::hello_world1 {
file {…

rookie09
- 736
- 1
- 6
- 18
3
votes
1 answer
How to rspec test a Puppet class when a parameter needs a resource reference
This may be a simple matter of mocking a resource, but...
class myclass (
String stringParam,
Integer intParam,
File fileParam
) {
# do some things
$path = fileParam['title']
$mode = fileParam['mode']
# do some more things
}
Now I want…

Chris Owens
- 1,107
- 1
- 10
- 15
3
votes
1 answer
Puppet Code coverage testing using rspec
My Module structure is this.
install_logging
├── files
│ └── install_logging.sh
├── Gemfile
├── Gemfile.lock
├── manifests
│ ├── \
│ ├── empty.rb
│ └── init.pp
├── Modulefile
├── Rakefile
├── README
├── spec
│ ├── chkcls_sec.rb
│ ├──…

Vivek
- 31
- 4
3
votes
2 answers
How can I mock facts to test a Puppet template that does decimal multiplication on a fact?
Context:
I have a puppet template that addresses the count sub-component of the processors fact when it is rendered. That fact exists on all of my clients.
The use case for the fact is in a template line that performs decimal math on it, e.g.:…

Zac B
- 3,796
- 3
- 35
- 52
3
votes
2 answers
can you override paramterized class variables in rspec-puppet?
I am retrofitting unit tests to an existing module (not authored by myself). I can't seem to override the params class undef value to a hash value.
the params class has the following (excerpt only):
class myclass::params {
splunk = undef,
…

kaizenCoder
- 2,211
- 6
- 33
- 64
3
votes
2 answers
Puppet: rake spec could not find class ::splunk
I'm trying to tests my puppet modules, but I get an error message that it can't find class.
I've written a couple of internally used Puppet modules; now that I have my head around puppet, I want to write tests. Since I ran into issues, I decided to…

W3t Tr3y
- 402
- 3
- 12
2
votes
1 answer
How to mock puppet validate_cmd in puppet using rspec?
I have a puppet cookbook rspec sample test like below
it {
is_expected.to contain_file('/etc/resolv.conf')
.with(
'ensure' => 'file',
'owner' => 'root',
'group' => 'root',
'mode' => '0444',
'validate_cmd' =>…

melvil james
- 592
- 7
- 18
2
votes
1 answer
rspec-puppet unit test for define type using resource
I have written a user define type which downloads a file using wget and stores in /root. I have used exec type to accomplish this. the code is working well with puppet apply, now when I am trying to write rspec test for the same, i am facing issues…

shailesh
- 23
- 2
2
votes
2 answers
Rspec: Could not parse for environment rp_env
I am new to rspec-puppet, and i am beginning with test writing:
I wrote this code:
describe 'rcjenkins' do
let(:facts) do
{
:osfamily => 'RedHat'
}
end
let(:pre_condition) do
"$facts = #{facts}"
end
let(:params) do
…

Techmago
- 380
- 4
- 18
2
votes
2 answers
How to check if an array parameter to a Puppet resource contains a value
I am writting a custom puppet module which includes an ::apache::vhost resource, and would like to verify in my rspec tests that the directories parameter contains a certain value, without reproducing the entire directories configuration which is…

TaninDirect
- 458
- 1
- 7
- 15
2
votes
1 answer
Why do I get puppet-rspec 'class does not exist' when it does?
I setup a new puppet demo module with the following Gemfile and it worked as expected when I ran a simple puppet-rspec test.
Gemfile
source 'https://rubygems.org'
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require…

kaizenCoder
- 2,211
- 6
- 33
- 64
2
votes
1 answer
How do I override hiera_data in rspec-puppet?
Lets say I have the following tests:
context 'test' do
let(:hiera_data) { { :number => '2' } }
it { should have_module__define_resource_count(2) }
end
context 'test2' do
let(:hiera_data) { { :number => '10' } }
it { should…

030
- 10,842
- 12
- 78
- 123
1
vote
1 answer
puppet-rspec - How to pass parameters to nested profile classes during unit test?
I am trying to build two Puppet profiles for the Hashicorp Consul DCS. Consul can run as a client or server agent, the server mode being a superset of the client mode. This is directly mirrored in the configuration:
Consul server agents typically…

Alexander
- 11
- 1
1
vote
1 answer
How do I fix psych module not being found or being the right version Ruby
I get the following error when trying to do anything with Ruby, specifically ruby gems:
/usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/2.4.0/yaml.rb:5:in `':
It seems your ruby installation is missing psych (for YAML output).
To eliminate…

AndreasKralj
- 463
- 4
- 23
1
vote
1 answer
Puppet: variable value in test file
I'm writing some tests for puppet and in my init_spec.rb file I want to use a variable that is declared in the default_facts.yml file. How could I import the value of that variable without having to declare it in the init_spec.rb file.
Thanks in…

DOM
- 35
- 5