I have created a simple Puppet 4 class and a unit test to go along with it as follows (after executing touch metadata.json; rspec-puppet-init
while in modules/test/
):
# modules/test/manifests/hello_world1.pp
class test::hello_world1 {
file { "/tmp/hello_world1":
content => "Hello, world!\n"
}
}
# modules/test/spec/classes/test__hello_world1_spec.rb
require 'spec_helper'
describe 'test::hello_world1' do
it { is_expected.to compile }
it { is_expected.to contain_file('/tmp/hello_world1')\
.with_content(/^Hello, world!$/) }
end
I can successfully run the unit test by executing rspec spec/classes/test__hello_world1_spec.rb
while in modules/test/
.
I would now like to proceed to a slightly more advanced class that uses code from another module, namely concat
(the module has arleady been installed in modules/concat
):
# modules/test/manifests/hello_world2.pp
class test::hello_world2
{
concat{ "/tmp/hello_world2":
ensure => present,
}
concat::fragment{ "/tmp/hello_world2_01":
target => "/tmp/hello_world2",
content => "Hello, world!\n",
order => '01',
}
}
# modules/test/spec/classes/test__hello_world2_spec.rb
require 'spec_helper'
describe 'test::hello_world2' do
it { is_expected.to compile }
# ...
end
When I attempt running this unit test with rspec spec/classes/test__hello_world2_spec.rb
while in modules/test
I receive an error message that includes:
Failure/Error: it { is_expected.to compile } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Unknown resource type: 'concat'
I suspect the root cause is that rspec
cannot find the other module(s), because it has not been told a "modulepath".
My question is this: How exactly am I supposed to start unit tests, especially ones that require access to other modules?