Setting custom environments in rspec-puppet tests

Back to Listing

Hanover, MD, 17 April 2015

I recently was attempting, with little success, to set a custom environment for a subset of rspec-puppet tests. After much Googling and perusing the rspec-puppet code base, I finally came up with a method that met my needs nicely.



First, I added a global helper method set_environment and a before(:each) stanza in the RSpec.configure block as shown in the Gist below.


The usage is very straightforward and is done with a let clause as shown in the following code.

Here’s hoping that you find this helpful! We’ll try to get around to actually making a patch to rspec-puppet to get this into the core at some point.

Trevor has worked in a variety of IT fields over the last decade, including systems engineering, operating system automation, security engineering, and various levels of development.

At OP his responsibilities include maintaining overall technical oversight for Onyx Point solutions, providing technical leadership and mentorship to the DevOps teams. He is also responsible for leading OP’s solutions and intellectual property development efforts, setting the technical focus of the company, and managing OP products and related services. In this regard, he oversees product development and delivery as well as developing the strategic roadmap for OP’s product line.

At Onyx Point, our engineers focus on Security, System Administration, Automation, Dataflow, and DevOps consulting for government and commercial clients. We offer professional services for Puppet, RedHat, SIMP, NiFi, GitLab, and the other solutions in place that keep your systems running securely and efficiently. We offer Open Source Software support and Engineering and Consulting services through GSA IT Schedule 70. As Open Source contributors and advocates, we encourage the use of FOSS products in Government as part of an overarching IT Efficiencies plan to reduce ongoing IT expenditures attributed to software licensing. Our support and contributions to Open Source, are just one of our many guiding principles

  • Customer First.
  • Security in All We Do.
  • Pursue Innovation with Integrity.
  • Communicate Openly and Respectfully.
  • Offer Your Talents, and Appreciate the Talents of Others

puppet, ruby, rspec, technical

Share this story

We work with these Technologies + Partners