Issue #11191 has been updated by Jeff McCune.
# Work Around 2 # Ken also has a work-around that manually creates a directory and an empty site.pp file for each puppet module that uses rspec-puppet. This doesn't seem ideal at all since everyone would need to copy and paste this functionality into their modules. <https://github.com/puppetlabs/puppetlabs-ntp/commit/2de694927175dcfd0752a1bf1a961e495ed0ffdc> <pre> commit 2de694927175dcfd0752a1bf1a961e495ed0ffdc Author: Ken Barber <[email protected]> Date: Sun Dec 4 01:17:06 2011 +0000 (#11152) Create temporary puppetconf area with empty manifests/site.pp Without a manifests/site.pp file for Puppet to read we get rspec testing errors. This patch creates a temporary directory and creates an empty site.pp to avoid this. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab7e2db..10afd38 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,21 @@ require 'puppet' require 'rspec-puppet' +require 'tmpdir' RSpec.configure do |c| + c.before :each do + # Create a temporary puppet confdir area and temporary site.pp so + # when rspec-puppet runs we don't get a puppet error. + @puppetdir = Dir.mktmpdir("ntp") + manifestdir = File.join(@puppetdir, "manifests") + Dir.mkdir(manifestdir) + FileUtils.touch(File.join(manifestdir, "site.pp")) + Puppet[:confdir] = @puppetdir + end + + c.after :each do + FileUtils.remove_entry_secure(@puppetdir) + end + c.module_path = File.join(File.dirname(__FILE__), '../../') end </pre> ---------------------------------------- Bug #11191: Puppet should provide platform access to compiler functionality without an application site.pp https://projects.puppetlabs.com/issues/11191 Author: Jeff McCune Status: Needs Decision Priority: Normal Assignee: Nigel Kersten Category: API Target version: Affected Puppet version: development Keywords: empathy rspec-puppet rspec testing platform Branch: # Overview # I'm working with [rspec-puppet](https://github.com/rodjek/rspec-puppet) to add spec tests to a module I'm working on. I ran squarely into an issue where Puppet refuses to compile catalogs because I do not have a site.pp file. rspec-puppet does not need a site.pp file because it compiles catalogs in-memory. Simply touching an empty site.pp to create the file allows Puppet to work correctly with rspec-puppet. # Expected Behavior # I expect Puppet to work as a platform providing an API in this situation. It appears to be working as an application instead. I expect rspec-puppet to be able to consume a well defined compiler API and then perform operations on the catalog object produced by this compiler API. # Actual Behavior # The error I get is: <pre> % rspec ./spec/defines/pe_accounts_user_spec.rb -l 15 Run filtered including {:line_number=>15} F Failures: 1) pe_accounts::user expected defaults Failure/Error: it { should contain_user.with_param('shell', '/bin/bash') } Puppet::Error: Could not parse for environment production: No file(s) found for import of '/Users/jeff/.puppet/manifests/site.pp' at line 3 on node maynard.local # /vagrant/src/puppet/lib/puppet/parser/compiler.rb:27:in `compile' # ./spec/defines/../../../puppet/lib/puppet/indirector/catalog/compiler.rb:77:in `compile' # /vagrant/src/puppet/lib/puppet/util.rb:185:in `benchmark' # ./spec/defines/../../../puppet/lib/puppet/indirector/catalog/compiler.rb:75:in `compile' # ./spec/defines/../../../puppet/lib/puppet/indirector/catalog/compiler.rb:35:in `find' # /vagrant/src/puppet/lib/puppet/indirector/indirection.rb:189:in `find' # /vagrant/src/envpuppet/rspec-puppet/lib/rspec-puppet/support.rb:12:in `build_catalog' # /vagrant/src/envpuppet/rspec-puppet/lib/rspec-puppet/example/define_example_group.rb:53:in `catalogue' # /vagrant/src/envpuppet/rspec-puppet/lib/rspec-puppet/example/define_example_group.rb:7:in `subject' # ./spec/defines/pe_accounts_user_spec.rb:15 Finished in 0.00896 seconds 1 example, 1 failure Failed examples: rspec ./spec/defines/pe_accounts_user_spec.rb:15 # pe_accounts::user expected defaults </pre> # Work around # Creating a blank and empty site.pp works around the issue. <pre> % touch ~/.puppet/manifests/site.pp </pre> <pre> % rspec ./spec/defines/pe_accounts_user_spec.rb -l 15 Run filtered including {:line_number=>15} . Finished in 0.23748 seconds 1 example, 0 failures </pre> # References # * Dan's issue reported against upstream rspec-puppet <https://github.com/rodjek/rspec-puppet/issues/15> -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
