Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

rspec-puppet - could not parse for environment rp_env:

$
0
0
I'm new to rspec-puppet testing, and I am trying to write some rspec tests for my module. I am using the puppetlabs_spec_helper 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', }) end end 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 contain_file('/tmp/helloworld').with({> Puppet::Error:> Could not parse for environment rp_env: Syntax error at> '{'; expected '}' at line 3 on node>> ... 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 rubygems.org. 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 #simple/manifests/init.pp class simple( $dest, ) { file{"${dest}/hello": 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/) end end I'm now getting the following error > Failures: 1) simple should contain File[/tmp/hello] with content =~ /world/> Failure/Error: should contain_file('/tmp/hello').with_content(/world/)> Puppet::Error:> Must pass dest to Class[Simple] at line 3 on node > ... I'm not sure what minor problem I have with my syntax... do parameters have to be passed in as a hash? #### EDIT AGAIN So, Actually reading the docs at http://rspec-puppet.com/matchers/ describe 'my::type' do context 'with foo => true' do let(:params) { {:foo => true} } it { should compile } end context 'with foo => bar' do let(:params) { {:foo => 'bar'} } it do expect { should compile }.to raise_error(Puppet::Error, /foo must be a boolean/) end end end 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!

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>