Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

Is it a good idea to create helper ruby modules to be required by rspec-puppet tests?

$
0
0
I intend to do some [changes](https://github.com/puppetlabs/puppetlabs-apache/pull/1667) in a number of templates for **puppetlabs-apache** module, and there will be an identical section repeated in all templates (in fact, included by a helper template, but this is irrelevant here). The **rspec-puppet** test for the classes which use these templates will, then have redundant code to test this content. In order not to repeat code, I thought of creating a helper module with the redundant logic and requiring it in each spec test. It would look kinda like:
# /spec/classes/mod/mod_helper_spec.rb
def repeated_content
  (Whatever redundant stuff)
end
# /spec/classes/mod/*_spec.rb
require './mod_helper_spec.rb'

(specifics for the tested class)

repeated_content(params)

(specifics for the tested class)
My question is: is this a Good Idea? The obvious intent is to DRY (don't repeat yourself) the test code, but I wonder if I'm adding more complexity than spec tests should have. I read [here](https://niallburkley.com/blog/rspecs-shared_examples_for/) and [here](http://itreallymatters.net/post/443831906/using-modules-and-methods-within-specs) about using this techique in plain Ruby **rspec**, but found no reference about this in **rspec-puppet**.

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>