Ask Your Question
0

"No examples found" error in rspec-puppet

asked 2015-08-06 06:56:28 -0500

Chutki gravatar image

Hi,

Below is my manifests for multipath

class multi {

  if $::is_virtual == 'true' {

  $onoff = hiera('MULTI')

  case $onoff {
    'off'  : {
      service { 'service name' :
        ensure => stopped,
        enable => false,
      }
    }
    'on'  : {
      service { 'service name' :
        ensure   => running,
        enable   => true,
      }
    }
    default: {}
  } 

include multi

I have written rspec

let(:facts) {{ :is_virtual => 'isvirtual' }}

  if ( 'isvirtual' == 'true')

    let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
    hiera = Hiera.new({ :config => 'spec/fixtures/hiera/hiera.yaml' })

    tempa = hiera.lookup('MULTI',nil,nil)

    let(:hiera_data) {{
      :MULTI => tempa
    }}

    if ( tempa == 'off')

      context "validating content with puppet #{tempa}" do
        it { should contain_sercive('service name').with(
          :ensure => 'stopped',
          :enable => 'false'
        )}
      end
    end

    if (tempa == 'on')

      context "validating content with puppet #{tempa}" do
        it { should contain_sercive('service name').with(
          :ensure => 'running',
          :enable => 'true'
        )}

spec/fixtures/hiera/multi.yaml

MULTI: 'off'

but I am getting below o/p, none of my test cases executed

No examples found.


Finished in 0.00007 seconds
0 examples, 0 failures
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-06 20:36:25 -0500

GregLarkin gravatar image

Doesn't the if statement below always evaluate to false, thus causing all of your tests to be skipped?

let(:facts) {{ :is_virtual => 'isvirtual' }}

  if ( 'isvirtual' == 'true')

i.e. 'isvirtual' != 'true' (both evaluated as strings)

edit flag offensive delete link more

Comments

Thanks for the update. I have changed the if condition to "if ('isvirtual' != true)" , now its working. But I don't understand how its working,. Because in my manifests the is statement "$::is_virtual == true, but in rspec how it worked when its other way round.

Chutki gravatar imageChutki ( 2015-08-21 13:27:32 -0500 )edit

Your if statement is comparing two strings, not the value of the variable $::is_virtual. The string 'isvirtual' does not equal the string 'true', so your if expression evaluates to 'true'. Therefore, your test cases are executing, but you're not actually checking the value of $::is_virtual.

GregLarkin gravatar imageGregLarkin ( 2015-08-24 10:58:41 -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

Stats

Asked: 2015-08-06 06:56:28 -0500

Seen: 240 times

Last updated: Aug 06 '15