Hi, Change filez from a class to a define ( https://docs.puppetlabs.com/learning/definedtypes.html).
Stephen On 9 January 2015 at 23:08, Chris Galli <[email protected]> wrote: > I've created a simple module to play with rspec-puppet, and I'm having > trouble getting my tests to pass because it appears I can't set the value > of $title -- It's always the name of my module. > > I think perhaps I'm not understanding something about $title in puppet or > let( :title ) in rspec-puppet. > > > Here's what I'm testing and the results I'm getting. > > Create module: > $ puppet module generate --skip-interview poc-filez > > > > Module contents (*poc-filez/manifests/init.pp*): > class filez { > > file { $title: > # have also tried "${title}" > ensure => "present", > } > } > > > > > Spec contents (*poc-filez/spec/classes/init_spec.rb*) > require 'spec_helper' > describe 'filez' do > expected_title = '/home/me/foo' > let(:title) { expected_title } > # have tried variations, e.g. let (:title) { "#{expected_title" } > > > # this fails > it { should contain_file("#{expected_title}") } > > # but when I use the module name, it passes, File[filez] is in the > catalog > # it { should contain_file("filez") } > end > > > > *.fixtures.yml* contents: > fixtures: > > repositories: > # > symlinks: > filez: "#{source_dir}" > > > > > Test results: > $ rake spec > > > Failures: > > > 1) filez should contain File[/home/me/foo] > Failure/Error: it { should contain_file("#{expected_title}") } > expected that the catalogue would contain File[/home/me/foo] > > > > However, if I change the module to use $name, and pass $name as a > parameter in the spec, then my tests pass, e.g. > > *manifests/init.pp* > class filez { > file { $name: > ensure => "present", > > } > } > > > *spec/classes/init_spec.rb* > require 'spec_helper' > describe 'filez' do > expected_title = '/home/me/foo' > let(:params) {{ :name => expected_title }} > > > # this passes > it { should contain_file("#{expected_title}") } > > > # this fails > # it { should contain_file("filez") } > end > > > > I've examined other projects that use rspec-puppet and let( :title ) and > on the surface they seems very similar. But obviously, I'm missing > something or not doing something correctly. Any insight would be greatly > appreciated. I've got several legacy modules that use $title, so I'm > hesitant to simply accept changing them to use name (unless of course > that's the root of my problem). > > Much appreciated, > > Chris > > > ps > I'm using Ruby 2.1.5 on MAC OS X 10.9.5 > > Version Info (from *Gemfile.lock*): > GEM > remote: https://rubygems.org/ > specs: > CFPropertyList (2.2.8) > diff-lcs (1.2.5) > facter (2.3.0) > CFPropertyList (~> 2.2.6) > hiera (1.3.4) > json_pure > json_pure (1.8.1) > metaclass (0.0.4) > mocha (1.1.0) > metaclass (~> 0.0.1) > puppet (3.7.3) > facter (> 1.6, < 3) > hiera (~> 1.0) > json_pure > puppet-lint (1.1.0) > puppet-syntax (1.3.0) > rake > puppetlabs_spec_helper (0.8.2) > mocha > puppet-lint > puppet-syntax > rake > rspec > rspec-puppet > rake (10.4.2) > rspec (3.1.0) > rspec-core (~> 3.1.0) > rspec-expectations (~> 3.1.0) > rspec-mocks (~> 3.1.0) > rspec-core (3.1.7) > rspec-support (~> 3.1.0) > rspec-expectations (3.1.2) > diff-lcs (>= 1.2.0, < 2.0) > rspec-support (~> 3.1.0) > rspec-mocks (3.1.3) > rspec-support (~> 3.1.0) > rspec-puppet (1.0.1) > rspec > rspec-support (3.1.2) > > > PLATFORMS > ruby > > > DEPENDENCIES > facter (>= 1.7.0) > puppet (>= 3.3) > puppet-lint (>= 0.3.2) > puppetlabs_spec_helper (>= 0.1.0) > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/39cf1edd-aa4f-4370-8674-4b041e4cfa86%40googlegroups.com > <https://groups.google.com/d/msgid/puppet-users/39cf1edd-aa4f-4370-8674-4b041e4cfa86%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAN5z%3Dnqa_E9gmwsyVRW%2BOHFZn28uOyuPou5_DVd0gSqgJVSQhA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
