rspec-puppet - could not parse for environment rp_env:

asked 2016-03-04 10:47:43 -0500

DarylW gravatar image

updated 2016-03-04 11:42:25 -0500

I'm new to rspec-puppet testing, and I am trying to write some rspec tests for my module.

I am using the puppetlabsspechelper and I ran rspec-puppet-init from my module directory.

I have a really simple test that tests that my class has created a file

# spec/defines/classes/simple_spec.rb
require 'puppetlabs_spec_helper/module_spec_helper'

describe 'Simple test' do
  let(:title) { 'test'}
  it do
    should contain_file('/tmp/helloworld').with({
      'ensure' => 'present',

When I run 'rake' from my modules top level directory, I see the following error

Failures: 1) Simple test should contain File[/tmp/helloworld] with ensure => "present" Failure/Error: should containfile('/tmp/helloworld').with({ Puppet::Error: Could not parse for environment rpenv: Syntax error at '{'; expected '}' at line 3 on node <my hostname=""> ...

From a bit of searching around, it looks like 'rb_env' is the default env that rspec-puppet assigns if one isn't specified, but I'm still to new with rspec/rspec-puppet testing to know where that file gets generated, what it's contents is, how I would set it for a different environment, etc..

Of note, I'm testing on an ec2 instance that is not the puppet master, and I'm in an environment where I don't just have ready connectivy to

Thanks in advance for your help!

### Edit

I renamed my 'describe' to the name of the class under test, and that resolved the rb_env issue, failing forward to the next problem!

I have my class now as follows

class simple(
) {
    ensure => 'present',
    content => 'world'

and I have my test updated to be

# spec/defines/classes/simple_spec.rb
require 'puppetlabs_spec_helper/module_spec_helper'

describe 'simple' do
  let(:title) { 'test'}
  let(:dest) { '/tmp' }
  it do
    should contain_file('/tmp/hello').with_content(/world/)

I'm now getting the following error

Failures: 1) simple should contain File[/tmp/hello] with content =~ /world/ Failure/Error: should containfile('/tmp/hello').withcontent(/world/) Puppet::Error: Must pass dest to Class[Simple] at line 3 on node <my hostname=""> ...

I'm not sure what minor problem I have with my syntax... do parameters have to be passed in as a hash?


So, Actually reading the docs at

describe 'my::type' do
  context 'with foo => true' do
    let(:params) { {:foo => true} }

    it { should compile }

  context 'with foo => bar' do
    let(:params) { {:foo => 'bar'} }

    it do
      expect {
        should compile
      }.to raise_error(Puppet::Error, /foo must be a boolean/)

I needed to let(:params) { {:dest => '/tmp'} } for my test to pass. I hope the existence of this post can help someone in the future googling for the same terms, I know that I didn't find any useful results for the 'rb_env' error!

edit retag flag offensive close merge delete


I changed my test describe to match the actual class name under test, and I'm seeing expected output now, based on reading

DarylW gravatar imageDarylW ( 2016-03-04 11:18:20 -0500 )edit

Great, well done.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-04 21:07:55 -0500 )edit