Puppet[:certname] Puppet[:code] Puppet[:config] Puppet[:libdir] Puppet[:manifest] Puppet[:manifestdir] Puppet[:modulepath] Puppet[:templatedir]
RSpec.configure do |c| c.add_setting :module_path, :default => ‘/etc/puppet/modules’ c.add_setting :manifest_dir, :default => nil c.add_setting :manifest, :default => nil c.add_setting :template_dir, :default => nil c.add_setting :config, :default => nil end
from rspec-puppet?
node_obj = Puppet::Node.new(nodename) # default to Puppet[:certname]? node_obj.merge(facts_val) # but what is this?
should contain_file('foo').with_content(/bar/).with_content(/baz/)
would not check /bar/
, only /baz/
, for example
- [X] gem install or gemfile line
See the fizzgig branch of puppet for an example
Can we isolate the compiler from the settings?
Answer seems to be yes – use puppetlabs_spec_helper or directly Puppet::Test::TestHelper to tear down Puppet.settings after each test.
- in govuk/puppet, we had trouble having multiple directories on the module path, so we ended up doing this:
RSpec.configure do |c|
c.module_path = File.join(HERE, 'modules')
# ...
end
# note monkey-patch here because the modulepath isn't working
module RSpec::Puppet
module Support
alias_method :real_build_catalog, :build_catalog
def build_catalog (nodename, fact_val, code)
Puppet[:modulepath] = File.join(HERE, 'modules') + ':' + File.join(HERE, 'vendor', 'modules')
real_build_catalog(nodename,fact_val,code)
end
end
end
That’s not so cool :(
See govuk_nodes_spec_optional for examples of this. the rspec-puppet equivalent is :type => :host
maybe testing functions more generally?
@dcarley’s trick of using a precondition with a collector might be helpful here