About | FAQ | Help
Ask Your Question

How to generate/test a template file for rspec tests?

asked 2015-04-23 13:22:50 -0500

I've created a file resource that is using a template file as content which is generated from a automatic hiera lookup.

$source_list_template = template($sources['list.template'])

file { 'sources.list':
  ensure  => file,
  content => template($source_list_template),
  notify  => Exec['apt_update'],

I've already figured how to set the :params to make it available to the context:

let(:params) { { 
  :sources => {
    'list.template' => 'puppet:///files/sources.list.erb',
} }

I now need to know how I can create a virtual template file or the content of this file to test how the final file should look like. I've not found this in the documentation on http://rspec-puppet.com and https://github.com/rodjek/rspec-puppet.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-24 04:53:09 -0500

After studying the puppetlabs documentation again I realized that templates are not to be used outside of modules anymore so I switched from $content => template() to $source => 'puppet:///path/to/file'. That can easily be tested within rspec as it is only a string that has to be asked for.


it {
  is_expected.to contain_file('sources.list').with({
    :source  => 'puppet:///path/to/file',
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-04-23 13:22:50 -0500

Seen: 1,168 times

Last updated: Apr 24 '15