So I have a simple class, for now, where I am trying to write RSPEC tests to check the following:
1. Smart Parameter $current_version is in catalogue.
2. If $current_version = $installed_version (custom fact that will be stubbed as a :fact), that 'class foo' exits without doing anything.
3. if $current_version != $installed_version a class foo::cleanup is called.
I have looked all over to try to work this out and keep hitting posts about "can't check variables" but when I do a p catalogue.resources I see:
foo
[Stage[main]{:name=>"main"}, Class[Settings]{:name=>"Settings"}, Class[main]{:name=>"main"}, Class[Foo]{:name=>"Foo", :mypath=>"/opt/mypath", :current_ver=>"0.1.2"}]
In foo.pp:
class foo ( $mypath="/usr/local/mypath", $current_version="0.1.2" ) {
if $installed_version == $current_version { # Goodie. Nothing to do }
else { include foo::cleanup }
}
In the spec file .spec/classes/init_spec.rb:
require 'spec_helper'
describe 'foo' do
context 'foo current version' do
let :params do {
:mypath => '/opt/mypath',
# :current_version => '1.2.3',
}
end
it {p catalogue.resources}
it do
is expected_to contain_class('foo').with(:current_version => "0.1.2" )
end
end
While this is very basic, and I have tried multiple ways, it error out with:
Failure/Error: should contain_class('epops_hyperic').with_current_version("0.1.2")
expected that the catalogue would contain Class[epops_hyperic] with current_version set to "0.1.2" but it is set to nil
Yet the p catalogue.resources function shows the shows it correctly as noted in the Stage[main] above.
If I uncomment the parameter :current_version => '1.2.3' the catalogue print has :current_version => "1.2.3" as expected (since it is overridden) and the test fails with the expected message :current_ver set to "0.1.2" but it is set to "1.2.3". This I know how to deal with, but that then causes the problems with 2 and 3 above.
What I want to test in the spec is if current_ver == expected version, the module doesn't need to do anything and exits. If not it will call class foo::cleanup. I read a lot on this today and have seen various generalized suggestions about 3, but nothing about 2.
How do I test if the class exits after finding nothing is needed to be done or it included the class to do a cleanup accordingly?
All of the tutorials give basics, but I can't find anything digging more specific that seems to work.
Can anyone point me to the right places to look to research this? So far the spec files seem really good for TDD, but without a good reference to these sorts of non file, package, service checks it is confusing.
Thanks!