Hi Brian,

I've found having my spec test print out a catalog is a good way to build out a 
suite of tests


context 'when the do_stuff param has the value of hell_yeah' do
  let (:facts) {{'osfamily' => 'RainbowOS }}
  let (:params) {{'do_stuff' => 'hell_yeah'}}
  It 'print a catalog for spec building' do
   p subject.resources
  end
end
context 'when the do_stuff param has the value of nope' do
  let (:facts) {{'osfamily' => 'RainbowOS }}
  let (:params) {{'do_stuff' => 'nope'}}
  It 'print a catalog for spec building' do
   p subject.resources
  end
end

Then I do some simple formatting on the subsequently generated catalogs in 
sublime text and review all the resources. With just a few tweaks it's pretty 
easy to grab the resources you actually care about from the catalog as rspec 
sees it.


HTH
-W
Sent from my iPad

> On Jun 4, 2014, at 1:30 PM, Brian Wilkins <bwilk...@gmail.com> wrote:
> 
> I am trying to write unit tests of my puppet modules. In my 
> profiles::logstash::install, I disambiguate the call to 
> /etc/puppet/modules/logstash by using ::logstash in my class definition like 
> so:
> 
> class profiles::logstash::install() {
>   $ensure = $profiles::logstash::enable ? {true => present, default => absent}
>   $status = $profiles::logstash::start ? {true => enabled, default => 
> disabled}
> 
>   class { '::logstash':
>     ensure  => $ensure,
>     status  => $status,
>     version => $profiles::logstash::version
>   }
> }
> 
> However, when I run my spec file:
> 
> require 'spec_helper'
> 
> describe "profiles::logstash" do
>   it { should contain_class("::logstash") }
>   it { should contain_class("profiles::logstash::install") }
>   it { should contain_class("profiles::logstash::config") }
> end
> 
> I get the errors:
> 
> 1) profiles::logstash
>      Failure/Error: it { should contain_class("::logstash") }
>      Puppet::Error:
>        Puppet::Parser::AST::Resource failed with error ArgumentError: Could 
> not find declared class ::logstash at 
> /etc/puppet/modules/profiles/spec/fixtures/modules/profiles/manifests/logstash/install.pp:10
>  on node els4167.els.dev
>      # ./spec/classes/logstash_spec.rb:4
> 
>   2) profiles::logstash
>      Failure/Error: it { should contain_class("profiles::logstash::install") }
>      Puppet::Error:
>        Puppet::Parser::AST::Resource failed with error ArgumentError: Could 
> not find declared class ::logstash at 
> /etc/puppet/modules/profiles/spec/fixtures/modules/profiles/manifests/logstash/install.pp:10
>  on node els4167.els.dev
>      # ./spec/classes/logstash_spec.rb:5
> 
>   3) profiles::logstash
>      Failure/Error: it { should contain_class("profiles::logstash::config") }
>      Puppet::Error:
>        Puppet::Parser::AST::Resource failed with error ArgumentError: Could 
> not find declared class ::logstash at 
> /etc/puppet/modules/profiles/spec/fixtures/modules/profiles/manifests/logstash/install.pp:10
>  on node els4167.els.dev
>      # ./spec/classes/logstash_spec.rb:6
> 
> How do I get rspec to find my class /etc/puppet/modules/logstash and get it 
> to reference ::logstash as a disambiguation?
> -- 
> 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 puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/a47b6fdb-519a-453c-92ec-40787c7d2470%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/BAD12348-3208-4763-B20D-70FD1C721B8B%40wolfspyre.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to