how to add template file in rspec-puppet -


i have below manifests sudo user, loading template file

class sudo {   if $::operatingsystemmajrelease < 7 {     $variable = $::operatingsystemmajrelease ? {       '6' => $::fqdn,      }     file { '/etc/sudoers' :       ensure  => present,       owner   => 'root',       group   => 'root',       mode    => '0440',       content => template('sudo/sudoers.erb'),     }   } } 

below rspec file

vim test_spec.rb require 'spec_helper' describe 'sudo'   { should contain_class('sudo')}   let(:facts) {{:operatingsystemmajrelease => 6}}    if (6 < 7)     context "testing sudo template rspec"     let(:params) {{:content => template('sudo/sudoers.erb')}}     {should contain_file('/etc/sudoers').with(       'ensure' => 'present',       'owner'   => 'root',       'group'   => 'root',       'mode'    => '0440',       'content' => template('sudo/sudoers.erb'))}   end   end end 

getting below error when run "rake spec"

.f failures:   1) sudo testing sudo template rspec      failure/error: 'content' => template('sudo/sudoers.erb'))}      nomethoderror:        undefined method `template' #<rspec::core::examplegroup::nested_1::nested_1:0x7f5802e70bd8>      # ./spec/classes/test_spec.rb:17 finished in 0.16067 seconds 2 examples, 1 failure failed examples: rspec ./spec/classes/test_spec.rb:12 # sudo testing sudo template rspec rake aborted! ruby -s rspec spec/classes/test_spec.rb failed 

can 1 guide me how test template rspec-puppet. surfed net breaking head more 2 days none helped.

template function of puppet parser , such not available unit tests.

if really want use existing template fixture, have have manually evaluate erb code.

the better unit testing approach hard-code test data right in test code.

if (6 < 7)   context "testing sudo template rspec"   let(:params) {{:content => 'spec-content'}}   {should contain_file('/etc/sudoers').with(     'ensure' => 'present',     'owner'   => 'root',     'group'   => 'root',     'mode'    => '0440',     'content' => 'spec-content'}   end end 

using actual valid templates more interesting in realms of acceptance or perhaps integration testing.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -