我有以下 sudo 用户的清单,正在加载模板文件
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'),
}
}
}
下面是我的 rspec 文件
vim test_spec.rb
require 'spec_helper'
describe 'sudo' do
it { should contain_class('sudo')}
let(:facts) {{:operatingsystemmajrelease => 6}}
if (6 < 7)
context "testing sudo template with rspec" do
let(:params) {{:content => template('sudo/sudoers.erb')}}
it {should contain_file('/etc/sudoers').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0440',
'content' => template('sudo/sudoers.erb'))}
end
end
end
运行“rake spec”时出现以下错误
.F
Failures:
1) sudo testing sudo template with rspec
Failure/Error: 'content' => template('sudo/sudoers.erb'))}
NoMethodError:
undefined method `template' for #<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 with rspec
rake aborted!
ruby -S rspec spec/classes/test_spec.rb failed
谁能指导我如何使用 rspec-puppet 测试模板。我上网也打破了我的头两天多没有帮助。