Ask Your Question

rspec-puppet custom stages

asked 2017-03-20 02:53:23 -0500

Jack Straw gravatar image

We use custom stages in our puppet setup.

stage { ['custom1', 'custom2']: }
Stage['custom1'] -> Stage['main'] -> Stage['custom2']

This works fine in our daily operation

class { 'test1::test2': stage => custom2 }

When i use rspec-puppet to test the code I get the following message

could not find stage custom2 specified by Class[test1::test2]

Does anybody know where I can specify the stage?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-20 15:40:54 -0500

DarylW gravatar image

Where are your stages declared? Are they in the code that you are executing in your test case? I was able to properly use custom stages in a rough test (though I didn't verify ordering)

class foo {
  stage { ['custom1', 'custom2']: }
  Stage['custom1'] -> Stage['main'] -> Stage['custom2']

  class { 'foo::custom':
    stage => 'custom2',

class foo::custom {
  notify { 'custom notify': }

describe 'foo' do
  let(:params) {{ }}
  it { should compile.with_all_deps }
  it { should contain_notify('custom notify') }

If your stages aren't declared in the code that you are testing, you could declare them in a pre_condition block?

let (:pre_condition) {
' stage { ['custom1', 'custom2']: }
Stage['custom1'] -> Stage['main'] -> Stage['custom2']'

or include the appropriate class where the stages are declared?

edit flag offensive delete link more


Thanks, that did the trick. Both the pre_condition and include solution work. The stages are declared in a different class. Using fixtures now with a let(:pre_condition) { 'include stageclass' }

Jack Straw gravatar imageJack Straw ( 2017-03-21 01:53:37 -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


Asked: 2017-03-20 02:53:23 -0500

Seen: 17 times

Last updated: 2 days ago