Ask Your Question
0

How to write better rspec ruby code for directory exist

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

mac gravatar image

Hi,

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

Thanks

edit retag flag offensive close merge delete

Comments

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
1

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 ( https://ask.puppetlabs.com/question/4692/how-to-check-whether-file-exist/ ), 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.]" )
    end
    it { should contain_notify("The 'opt' directory exist for Ubuntu & Centos servers.") }
end

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

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

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

Comments

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 http://pastebin.com/Lr4esbC0 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 ---> http://pastebin.com/xSz0FN7r /filecheck/manifests/init.pp --> http://pastebin.com/VfL0jkf1 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

Stats

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

Seen: 821 times

Last updated: Jan 11 '14