rspec testing; how to test a subclass that requires another class

355 views
Skip to first unread message

Trey Ormsbee

unread,
May 1, 2015, 5:47:26 PM5/1/15
to puppet...@googlegroups.com
I have a puppet module that I am not sure hot to write a test for:  Example below:

class appsuite (
  $param1,
  $param2,
  $param3,
  $param4,
) {

  include appsuite::params
  include appsuite::repo
  include appsuite::preconfig

}

#nothing in params, repo or preconfig really matter,  other then preconfig lays down a shared settings file: /etc/appsuite/settings 
# /etc/appsuite/settings is required to be in place during the install of any component of appsuite as it is sued to do its own setup.

So then I have a seperate class

class appsuite::component1 (
  $component_param1,
  $component_param2,
) {

  ...
  package { 'component1': ensure => installed }
  ...
}


Now, class appsuite::component1 requires appsuite to be defined and all those classes to be ran before it starts all it's magic.  How do I test that?

I got this

describe 'appsuite' do
  context "test appsuite" do
    let :params do {
      param1 = 'blah1',
      param2 = 'blah2',
      param3 = 'blah3',
      param4 = 'blah4',
    }
    end
    it { is_expected.to contain_file('/etc/appsuite/settings').with({'mode' => '0644'}) }
  end
end

Now the above works fine,  but I do not understand how to then call appsuite::component1 from that test with those parameters,   I tried nesting in the descibe,  but it then says i need to pass params to appsuite.  Seems like this would be a pretty common thing to do so I hope I am just missing something.

Any ideas?


Thanks
Trey

Gavin Williams

unread,
May 2, 2015, 4:39:38 AM5/2/15
to puppet...@googlegroups.com
Trey

You can use "let(:pre_condition)" to include any dependencies when testing...

E.g. https://github.com/fatmcgav/fatmcgav-glassfish/blob/develop/spec/classes/install_spec.rb#L14

Gav

Trey Ormsbee

unread,
May 2, 2015, 10:10:30 PM5/2/15
to puppet...@googlegroups.com
Thank you,  That is exactly what I was looking for.  It's hard to actually google that info :\  
Reply all
Reply to author
Forward
0 new messages