Ask Your Question
0

rspec-puppet test run for each lamba value

asked 2016-05-19 07:00:31 -0500

Chutki gravatar image

updated 2016-05-23 01:35:36 -0500

Hi,

I have written below rspec test case

 context 'with defaults for all parameters' do
    [5,6,7].each do|osversion|
      if osversion >= 7

        context 'test case for osversion 5 or 6' do
          let(:facts) {{ :operatingsystemmajrelease => '6', :osfamily => 'RedHat' }}

          it { should contain_class('module') }

          it { should contain_file('/etc/module.conf').with(
            'ensure' => 'present',
            'owner'  => 'root',
            'group'  => 'root',
            'mode'   => '0644',
            'source' => "puppet:///modules/module/module.conf",
          )}
        end
      end
   end
end

My test execute for 4 time

....

Finished in 0.6915 seconds (files took 0.91355 seconds to load)

4 examples, 0 failures

but ideally it should pass only two test cases, why the test case runs separately for osversion 5 and 6

what should I do if a test case should run only once. ( I meant only two test case pass for either 5 or 6 option)

================================================================================================

Below code worked

describe "module_name" do
        osversion = '6'
          if osversion >= 7

            context 'test case for osversion 5 or 6' do
              let(:facts) {{ :operatingsystemmajrelease => osversion , :osfamily => 'RedHat' }}

              it { should contain_class('module') }

              it { should contain_file('/etc/module.conf').with(
                'ensure' => 'present',
                'owner'  => 'root',
                'group'  => 'root',
                'mode'   => '0644',
                'source' => "puppet:///modules/module/module.conf",
              )}
            end
          end
       end
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-05-21 01:45:43 -0500

updated 2016-05-21 01:46:29 -0500

You have only shown us a snippet of your code, i.e. one context block. It's not possible that this context block is causing 4 examples to run, so you have code elsewhere that accounts for some or all of the passing tests. Note that you can switch to documentation formatted output by adding the following line to your .rspec file:

--format documentation

This will help you to understand what is really happening.

edit flag offensive delete link more

Comments

Thanks for the update I ran the test case with "--format rspec.txt" option. It ran for each value which I mentioned in the lamda. So I made little changes in the test case, updated below on jy original post and it worked as per my expectation.

Chutki gravatar imageChutki ( 2016-05-23 01:32:34 -0500 )edit

Can you please mark this as resolved then. Thanks...

Alex Harvey gravatar imageAlex Harvey ( 2016-05-23 02:26:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-19 07:00:31 -0500

Seen: 83 times

Last updated: May 23 '16