how to write puppet-rspec for dependent define?

I have a define like below,

define module::define1 (
$path = undef,$someparam = undef,
...
) {

unless defined(Define2[$someparam]) { fail("Please create define2[$someparam] first")
}

file { $path: ensure => directory, } }  When I try to test the existence of file[$path] I am getting error "Please create define2[$someparam] first". But define2 is in another file. How can I include define2 inside my define1's rspec scope? edit retag close merge delete Comments Can you post what you have tried in rspec-puppet ( 2015-12-28 05:11:17 -0500 )edit context 'when invoked' do let(:pre_condition) do 'Module::Define2 <| |>' end it { should contain_file('file_title') } end I tried this but not working! ( 2015-12-28 07:22:21 -0500 )edit 1 Answer Sort by » oldest newest most voted It's not clear what you are trying to do. You could mean this: define module::define1 ($path      = undef,
$someparam = undef, ) { unless defined("module::define2") { fail("You have not defined a type 'module::define2'") } file {$path:
ensure => directory,
}
}


That is to say, perhaps you want a failure inside module::define1 if the programmer has forgotten to provide a definition for another type define2.

Or you could mean this:

define module::define1 (
$path = undef,$someparam = undef,
) {
unless defined(Module::Define2[$someparam]) { fail("You have not declared a Module::Define2[$someparam]")
}

file { $path: ensure => directory, } }  And then in spec/defines/define1_spec.rb: require 'spec_helper' describe 'module::define1', :type => :define do let :pre_condition do 'module::define2 { "someval": }' end let(:title) { 'spec_m' } let(:params) {{ :path => '/tmp/somepath', :someparam => 'someval', }} it do is_expected.to contain_file('/tmp/somepath') end end  That is to say, you want a failure inside module::define1 if the catalog doesn't already contain a resource Module::Define2[$someparam].

In either case, though, this seems like very confusing code, and there's undoubtedly a better way of doing whatever it is you're trying to do.

more

yeah, now I understood, when we say, let(:title) actually it will add 'spec_m' to the catalog

( 2016-01-11 08:00:56 -0500 )edit