Here are the steps I used to install puppet-rspec on CentOS 6.
I’ll be using RVM to install a recent version of Ruby to ease the process. At one point you could get rpec to work with the Ruby 1.8.7, the version that ships with CentOS 6, but recent attempts have failed for me because the required GEMs all require newer Ruby versions.
1) Install RVM. We’ll be using the multi-user install, but the single user install works also.
sudo yum install gnupg2
sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | sudo bash -s stable
RVM installs a file in
/etc/profile.d that allows it to take over ruby duties when anyone logs in. If you prefer to selectively enable RVM, move the
/etc/profile.d/rvm.sh file to another location and run the command
“source /path/to/rvm.sh” to enable it.
2) Add your user account to the rvm group to give yourself the ability to use rvm to manage ruby. (You cannot use root or sudo to manage rvm.)
sudo usermod -a -G rvm myuser
Restart your session to pick up the change.
3) Install a newer Ruby.
rvm install 2.1
ruby --version to make sure you’re using the installed version. You should see something similar to:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
4) Install the puppet-rspec gem along with some other requirements.
You’ll notice I have puppet in the list of gems to install. Now that we are using RVM, the Puppet gem installed at the system level is no longer visible, so we need to reinstall it. Make sure to specify the version if you don’t want to run the latest release. Here I install version 3.8.1, the latest version 3 at this time.
gem update --system
gem install puppet -v 3.8.1
gem install -V rspec
gem install -V rspec-puppet
gem install -V puppet-lint
gem install -V puppet-syntax
# No need to install these two, they get pulled in by rspec.
#gem install -V rspec-core
#gem install -V rspec-expectations
5) Build and install the puppetlabs-rspec-helper gem. We’ll use puppetlabs-rspec-helper in the next step to setup our directories.
git clone git://github.com/puppetlabs/puppetlabs_spec_helper.git
gem install -V pkg/puppetlabs_spec_helper-*.gem
Configuring the module
6) Run puppetlabs-rspec-helper to initialize the module’s spec directory layout.
7) Add the following line to your module’s spec/spec_helper.rb file.
8) Add the following line to your module’s Rakefile:
9) Create a puppetlabs_spec_helper .fixtures.yml file in your module’s directory. Here is an example file:
If you don’t create the .fixtures.yml you will receive trace backs. In my case rake complained about missing constants.
So that that’s it. Hopefully you found this useful and it got you up and running.
https://github.com/puppetlabs/puppetlabs_spec_helper (explains .fixures.yml)