Proper way to use hiera with puppetlabs-spec-helper?
Posted
by
Lee Lowder
on Server Fault
See other posts from Server Fault
or by Lee Lowder
Published on 2012-07-19T15:57:42Z
Indexed on
2012/08/29
9:40 UTC
Read the original article
Hit count: 325
puppet
I am trying to write some rspec tests for my modules. Most of them now use hiera.
I have a .fixures.yml:
fixtures:
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git
hiera-puppet: https://github.com/puppetlabs/hiera-puppet.git
symlinks:
mongodb: "#{source_dir}"
and a spec/classes/mongodb_spec.rb:
require 'spec_helper'
describe 'mongodb', :type => 'class' do
context "On an Ubuntu install, admin and single user" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemrelease => '12.04'
}
end
it {
should contain_user('XXXX').with( { 'uid' => '***' } )
should contain_group('XXXX').with( { 'gid' => '***' } )
should contain_package('mongodb').with( { 'name' => 'mongodb' } )
should contain_service('mongodb').with( { 'name' => 'mongodb' } )
}
end
end
but when I run the spec test, I get:
# rake spec
/usr/bin/ruby1.8 -S rspec spec/classes/mongodb_spec.rb --color
F
Failures:
1) mongodb On an Ubuntu install, admin and single user
Failure/Error: should contain_user('XXXX').with( { 'uid' => '***' } )
LoadError:
no such file to load -- hiera_puppet
# ./spec/fixtures/modules/hiera-puppet/lib/puppet/parser/functions/hiera.rb:3:in `function_hiera'
# ./spec/classes/mongodb_spec.rb:15
Finished in 0.05415 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/classes/mongodb_spec.rb:14 # mongodb On an Ubuntu install, admin and single user
rake aborted!
/usr/bin/ruby1.8 -S rspec spec/classes/mongodb_spec.rb --color failed
Tasks: TOP => spec_standalone
(See full trace by running task with --trace)
Module spec testing is relatively new, as is hiera. So far I have been unable to find any suitable solutions. (the back and forth on puppet-dev was interesting, but not helpful).
What changes do I need to make to get this to work? Installing puppet from a gem and hacking on rubylib isn't a viable solution due to corporate policy.
I am using Ubuntu 12.04 LTS + Puppet 2.7.17 + hiera 0.3.0.
© Server Fault or respective owner