template erb file in rspec-puppet

asked 2015-09-03 07:38:37 -0500

Chutki gravatar image

Hi,

Below is my manifests for limit configuration

file { "/etc/limits.d/nofile.conf" :
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    content => template('limits/nofile.conf.erb'),
  }

and this is template file nofile.conf

soft    nofile     <%= scope.function_hiera(['limit::nofile']) %>

I wrote rspec-puppet test case for erb file spec/templates/nofile_spec.rb

require 'spec_helper'

describe 'nofile.conf.erb' do

  let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
  before(:each) do
    scope.stubs(:function_hiera).with('limit::nofile').returns('limit::nofile')
  end

  let(:template) { TemplateHarness.new('spec/fixtures/modules/limits/templates/nofile.conf.erb') }

  it 'should create credentials when supplied' do
    template.set '@limit::nofile', scope
    result = template.run
    expect(result).to match
  end
end

I am getting below error

nofile.conf.erb should create credentials when supplied
     Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
     NameError:
       uninitialized constant PuppetlabsSpec
     # ./spec/templates/nofile_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./spec/templates/nofile_spec.rb:7:in `block (2 levels) in <top (required)>'

I referred below url https://github.com/Accuity/rspec-pupp...

edit retag flag offensive close merge delete