Hi,

Augeas changes the file during the execution of the catalog on the node, so it cannot have any content in the catalo, and that is what puppet-rspec is testing.

the with_content test will always fail, because a content attribute is not available for the augeas resource

puppet describe -s  augeas

Parameters
----------
    changes, context, force, incl, lens, load_path, name, onlyif, returns,
    root, show_diff, type_check

For rspec unit testing, one must keep in mind that you are testing the content of the catalog.

hth

Grts

Johan


On 25/09/14 12:09, Bill Sirinek wrote:
I have a simple class that sets the timezone on a Solaris system. I'm trying to write tests for it, and failing. It's telling me the file is nil, but there should be content as the file does exist. The file is not generated via a template or as a static puppet file in the module... the module just has an augeas resource to set a shell-style variable inside the file: TZ=<timezone> I have puppetlabs_spec_helper 0.8.1 and rspec-puppet 1.0.1 installed as gems into Puppet Enterprise's ruby (PE 3.2.3)
Here is the error and the offending rspec code:
bsirinek@myhost $ rake spec
/opt/puppet/bin/ruby -I/opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-support-3.1.0/lib:/opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-core-3.1.4/lib /opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-core-3.1.4/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration\}/\*\*/\*_spec.rb --color
...F
Failures:
1) timezone when called with parameters on solaris should contain Augeas[set_timezone] with incl => "/etc/default/init", lens => "Shellvars.lns", changes => "set TZ US/Eastern" and content =~ /^TZ=US\/Eastern$/
     Failure/Error: }).with_content(/^TZ=US\/Eastern$/)
expected that the catalogue would contain Augeas[set_timezone] with content set to /^TZ=US\/Eastern$/ but it is set to nil # ./spec/classes/timezone_spec.rb:47:in `block (3 levels) in <top (required)>'
(...annoying deprecation warnings removed...)
Finished in 0.60314 seconds (files took 1.4 seconds to load)
4 examples, 1 failure
Failed examples:
rspec ./spec/classes/timezone_spec.rb:43 # timezone when called with parameters on solaris should contain Augeas[set_timezone] with incl => "/etc/default/init", lens => "Shellvars.lns", changes => "set TZ US/Eastern" and content =~ /^TZ=US\/Eastern$/ /opt/puppet/bin/ruby -I/opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-support-3.1.0/lib:/opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-core-3.1.4/lib /opt/puppet/lib/ruby/gems/1.9.1/gems/rspec-core-3.1.4/exe/rspec --pattern spec/\{classes,defines,unit,functions,hosts,integration\}/\*\*/\*_spec.rb --color failed
rspec test:
  describe 'when called with parameter on solaris' do
    let(:facts) { { :osfamily => 'Solaris' } }
    let(:params) { { :time_zone => 'US/Eastern' } }
    it {
      should contain_augeas('set_timezone').with({
        :incl    => '/etc/default/init',
        :lens    => 'Shellvars.lns',
        :changes => "set TZ US/Eastern"
      }).with_content(/^TZ=US\/Eastern$/)
    }
  end
The test works fine if I leave off the with_content.
Any ideas?
Thanks
Bill

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com <mailto:puppet-users+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/7007a8e5-df7b-492a-accb-eed09cb12871%40googlegroups.com <https://groups.google.com/d/msgid/puppet-users/7007a8e5-df7b-492a-accb-eed09cb12871%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer              (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
_________________________________________________________
Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________

Next Events:
Puppet Introduction Course | 
http://www.open-future.be/puppet-introduction-course-13th-october
Puppet Practitioner Training | 
http://www.open-future.be/puppet-practitioner-former-puppet-advanced-training-14-till-16th-october
Linux Training | http://www.open-future.be/linux-training-20-till-24th-october
Puppet Introduction Course | 
http://www.open-future.be/puppet-introduction-course-10th-november
Puppet Fundamentals Training | 
http://www.open-future.be/puppet-fundamentals-training-12-till-14th-november
Subscribe to our newsletter | http://eepurl.com/BUG8H

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/5424124E.8000500%40open-future.be.
For more options, visit https://groups.google.com/d/optout.

Reply via email to