rspec - Running unit tests for Puppet modules -


i add rspec unit tests puppet 4 modules. started , confirm basic functioning, first run unit tests come standard puppet modules such puppetlabs/apt.

if try running specific unit test so

cd modules/apt rspec spec/classes/apt_spec.rb 

i failures, , of diagnostic output seems indicate part of puppet runtime environment (such module stdlib, defines function merge) not picked correctly:

failures:    1) apt defaults should contain file[sources.list] notifies class[apt::update]      failure/error:        { is_expected.to contain_file('sources.list').that_notifies('class[apt::update]').only_with({          :ensure  => 'file',          :path    => '/etc/apt/sources.list',          :owner   => 'root',          :group   => 'root',          :mode    => '0644',          :notify  => 'class[apt::update]',        })}       puppet::preformattederror:        evaluation error: unknown function: 'merge'. @ /home/my_user/modules/apt/spec/fixtures/modules/apt/manifests/init.pp:50:14 on node my_host 

if try running unit tests so

rake spec 

i error message:

rake aborted! nameerror: uninitialized constant bundler /home/my_user/modules/apt/rakefile:3:in `<top (required)>' (see full trace running task --trace) 

prior these attempts have taken steps prepare runtime environment (on debian host):

 mkdir modules  cd modules  puppet module --modulepath=. install puppetlabs-apt # installs stdlib  sudo gem install rspec-puppet  sudo gem install puppet  sudo gem install puppetlabs_spec_helper  sudo apt-get install rake 

my question this: how can correctly prepare runtime environment , run unit tests come puppet module puppet forge such puppetlabs/apt?

to need firstly ensure have ruby gems installed. ensure have installed bundler, means typing:

$ gem install bundler 

next, assume cloned apt module, cd directory cloned in , install bundle:

$ bundle install 

now, there's problem specific module you've chosen. when try run bundle install get:

could not find gem 'puppet-module-posix-default-r2.0' in of gem sources listed in gemfile or available on machine. 

i not sure means @ moment, , needs raise bug.

i expected able work around using:

$ bundle install --without development system_tests 

even not working commented-out groups.

next, run tests using:

$ bundle exec rake spec 

that run tests. however, think puppet has broken rspec tests people outside company.

i going follow , come , update answer have figured out has happened.

i'll leave answer here since it's still documenting correct procedure.

see blog post on subject, although possibly little dated now. let me know if there's need update.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -