Ask Your Question

How to write rspec-test for a class that uses 'create_resources' function

asked 2013-08-19 04:57:55 -0600

Can't figure out how to write a puppet-Rspec test for the class, that takes parameters and calls 'create_resources' for defined type, passing resources to that function.

Update: Looks like that I need to test only a httpd::vhost_template, but don't know how.

Here is the class I stuck with:

class httpd::vhosts($vhosts_config) {

  if $vhosts_config[use_templates] {
    notice 'use templates!'

    create_resources(httpd::vhost_template, $vhosts_config[vhosts])

Here is the httpd::vhost_template resource definition

define httpd::vhost_template ($vhost_name, $vhost_url, $vhost_order) {

  $basepath = '/vagrant/httpd2_test'


  $file_name = "${vhost_order}_${vhost_name}.conf"

  file { "${basepath}/conf.d/${file_name}":
    ensure  => file ...
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-08-20 10:23:25 -0600

I found out that 'define' can be tested by it's own (didn't knew that it is possible, when I was asking the question). There's a good example in the beginning of Rspec-puppet tutorial.

edit flag offensive delete link more

answered 2017-01-13 06:50:44 -0600

karthikeayan gravatar image

It has to be tested against each of the value in the $vhosts_config[vhosts]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-08-19 04:57:55 -0600

Seen: 2,756 times

Last updated: Jan 13 '17