Ask Your Question

How to write better rspec ruby code for directory exist

asked 2014-01-10 10:43:17 -0500

mac gravatar image


How to write rspec ruby code whether directory (opt) exist in redhat or ubuntu ?


edit retag flag offensive close merge delete


Do you want to test with rspec-puppet, or is it someting else ?

doc75 gravatar imagedoc75 ( 2014-01-10 13:57:02 -0500 )edit

yes I want to write a ruby code using rspec-puppet

mac gravatar imagemac ( 2014-01-11 05:06:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-11 11:30:05 -0500

doc75 gravatar image

updated 2014-01-11 11:36:59 -0500

If you want to test your code from your other question ( ), I would do like this (not sure it is typo free):

shared_examples_for 'test /opt existence' do
    it do
        should contain_file('/opt').with(
            :ensure => 'directory',
            :mode   => '0755',
            :owner  => 'root',
            :group  => 'root',
            :before => "Notify[The 'opt' directory exist for Ubuntu & Centos servers.]" )
    it { should contain_notify("The 'opt' directory exist for Ubuntu & Centos servers.") }

context 'ubuntu' do
    let(:facts) {{ :operatingsystem => 'Ubuntu' }}
    it_should_behave_like 'test /opt existence'

context 'redhat' do
    let(:facts) {{ :operatingsystem => 'RedHat' }}
    it_should_behave_like 'test /opt existence'

context 'other' do
     let(:facts ...
edit flag offensive delete link more


Thanks a lot for your response on this..

mac gravatar imagemac ( 2014-01-12 10:30:56 -0500 )edit

After testing, it gives no result, you can view the code in Also, what needs to be defined in spec/classes. Thanks

mac gravatar imagemac ( 2014-01-13 06:29:07 -0500 )edit

Actually the test of any manifest has to go inside spec/classes. the spec/defines is for defined type test. If you need more help, please post the content of ...(more)

doc75 gravatar imagedoc75 ( 2014-01-14 04:05:20 -0500 )edit

/modules/filecheck/spec/classes ---> /filecheck/manifests/init.pp --> also, spec/define is empty in my case. Thanks

mac gravatar imagemac ( 2014-01-15 02:02:48 -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: 2014-01-10 10:43:17 -0500

Seen: 752 times

Last updated: Jan 11 '14