Ask Your Question
1

how to use PuppetlabsSpec::Files ?

asked 2013-11-10 15:37:50 -0500

doc75 gravatar image

Hello,

I am trying to test my personal puppet module with the help of "puppetlabsspechelper".

I would like to get the path of a temporary directory that is cleaned after the spec is replayed. I guess that I could be using PuppetlabsSpec::Files module and the tmpdir method inside it. But as the method is not a defined as "self" and this is a module, how should I proceed ?

Do I neeed to just create a testing class that is including this module ?

If yes, in which directory Where should I put this class to be clean in ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-11-11 02:34:45 -0500

doc75 gravatar image

updated 2013-11-11 14:08:08 -0500

Answering my own question as I found out it's just pure Ruby.

in the spec_helper.rb file:

require 'puppetlabs_spec_helper/puppet_spec_helper'

...

class MySpecFiles
    include PuppetlabsSpec::Files
end

In the spec files where it is needed:

before :each do
   my_tmp_dir = MySpecFiles.new.tmpdir('some_string')
end

Remark: "before :each" enable to recreate the directory before each spec, otherwise it is deleted at the end of the first spec run.

Then you can use mytmpdir to store information and it will be deleted at the end of your specs.

edit flag offensive delete link more

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: 2013-11-10 15:37:50 -0500

Seen: 91 times

Last updated: Nov 11 '13