rodjek / rspec-puppet

RSpec tests for your Puppet manifests
http://rspec-puppet.com
MIT License
362 stars 202 forks source link

case statement is not evaluated properly #746

Closed blackknight36 closed 3 years ago

blackknight36 commented 5 years ago

I have a spec file which is used to test a class on multiple OSes however my case statement only appears to be getting evaluated when the first loop runs. For example, here is the code I'm using.

on_supported_os.each do |os, facts|
  let(:facts) do
    facts
  end

  context "on #{os}" do
    case facts[:operatingsystem]
      when 'CentOS'
        bacula_base = 'base-centos7'
        bacula_ssl_dir = '/var/lib/bacula/ssl'
        puppet_ssl_dir = '/etc/puppetlabs/puppet/ssl'
      when 'Fedora'
        bacula_base = nil
        bacula_ssl_dir = '/var/lib/bacula/ssl'
        puppet_ssl_dir = '/etc/puppet/ssl'
      when 'windows'
        bacula_base = nil
        bacula_ssl_dir = 'c:/ProgramData/Bacula/ssl'
        puppet_ssl_dir = 'c:/ProgramData/PuppetLabs/puppet/etc/ssl'
    end

    it do
      is_expected.to contain_file(bacula_ssl_dir)
          .with({
            :ensure => 'directory',
          })
  end
end

This spec file fails when the Windows and CentOS tests run due to the paths not being updated properly. Is there another way to ensure that my variables are getting set properly for each OS?

evidex commented 3 years ago

I was able to resolve this issue by 1) having my case statement in a context (as you do) and 2) including a let(:facts) { facts } at the start of that context.

blackknight36 commented 3 years ago

I was able to resolve this issue by 1) having my case statement in a context (as you do) and 2) including a let(:facts) { facts } at the start of that context.

Thanks. It's been a few years since I looked at this but I will give that a shot.