Thanks for the info Gareth. I have managed to get it working as you suggested. Lots of other good stuff in that docker module as well.
I still feel that for true spec testing I should be able to test each class standalone but maybe I am trying to break things down too much. Thanks john On Wednesday, 1 April 2015 16:22:51 UTC+1, garethr wrote: > > On 1 April 2015 at 15:37, choffee <[email protected] <javascript:>> wrote: > > Hi, > > > > I am having some trouble testing some classes using rspec. > > > > I have three classes. init, service and config. > > > > service contains just the service settings with a class setting for > service > > name eg. > > > > class tc::service ( > > $service_name => tc::service_name > > ) { > > > > service {'tc': > > service_name => $service_name > > } > > } > > > > init has a param for setting the service name > > > > class tc ( > > $service_name => tc::params::service_name > > ) inherits tc::params { > > > > class {'tc::service': > > service_name => $service_name > > } > > include tc::config > > } > > > > The config class has something that notifies the service > > > > class tc::config { > > file {'/foo/bar': > > notify => Service['tc'], > > } > > } > > > > I am trying to test the service and config modules using rspec and get > all > > sorts of errors about variable blank or classes not being loaded. > > > > Is there some way to better set this up from a puppet point of view? > > I think a common pattern that does this would be: > > > https://github.com/garethr/garethr-docker/blob/master/manifests/init.pp#L190-L195 > > > Here we're saying: > > Install requires config, which notifies service. > > > Should I just test the init class? ( Seems to go against the unit tests > a > > bit ) > > I would say test the public interface not the implementation. If you > intend your individual classes to be public, test them directly. If > you don't then test them via the public interface (often init.pp). > Their are a bunch of bits in > https://speakerdeck.com/garethr/test-driven-development-for-puppet > which might be useful. > > The above linked Docker module also has a somewhat large (300+ tests) > rspec-puppet test suite which might be worth looking at, at least to > see how I approached the problem. > > Gareth > > > Is there a way in rspec to shim a class so that things like > Service['tc'] > > appear to be available to the config class? > > > > Thanks > > > > john > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "Puppet Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to [email protected] <javascript:>. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/puppet-users/eb3d3791-d2e3-483c-9005-0b61626df7e7%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > > > > -- > Gareth Rushgrove > @garethr > > devopsweekly.com > morethanseven.net > garethrushgrove.com > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/de2d1b06-f1f5-4a3a-8510-1be77980ad60%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
