How to make puppetlabs_spec_helper ignore modules inside fixtures

245 views
Skip to first unread message

Sebastian Otaegui

unread,
Aug 12, 2014, 2:47:37 PM8/12/14
to puppet...@googlegroups.com
Hello all, 

I have created this module: 

https://github.com/Spantree/puppet-thrift and everything worked fine all specs ran fine.

Now I using the puppetlabs/apt module and when I run the 'rake spec' it is trying to run the 'apt' tests, and it is failing (I think) because I am not providing the appropriate facts.

Is there a way to ignore the rspecs inside the fixtures/modules/ directory?

I tried to do this: 

require 'rake'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
  t.pattern = 'spec/*/*_spec.rb'
end


But it didn't work.

Can anybody point me in the right direction here?

Thanks in advance,
Seb

Jason Antman

unread,
Aug 13, 2014, 8:42:56 AM8/13/14
to puppet...@googlegroups.com
Seb,

You really shouldn't be running specs for dependent modules.

(1) If I were you, I'd really use the spec helper, and garethr's module skeleton - https://github.com/garethr/puppet-module-skeleton
(2) looking at your code, you should just be able to
t.pattern = 'spec/(classes|defines)/*_spec.rb'

-Jason


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1d7b8768-0e72-40c3-97f7-623d08f028ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Antman

unread,
Aug 13, 2014, 9:57:17 AM8/13/14
to puppet...@googlegroups.com
Seb,

I actually *just* came by a very similar issue myself. The examples at http://murphyslaw.github.io/blog/2012/04/06/run-specs-excluding-integration-specs/ should help you.

-Jason

Wil Cooley

unread,
Aug 13, 2014, 9:08:40 PM8/13/14
to puppet-users group


On Aug 12, 2014 11:57 AM, "Sebastian Otaegui" <fen...@gmail.com> wrote:
>
> Hello all, 
>
> I have created this module: 
>
> https://github.com/Spantree/puppet-thrift and everything worked fine all specs ran fine.
>
> Now I using the puppetlabs/apt module and when I run the 'rake spec' it is trying to run the 'apt' tests, and it is failing (I think) because I am not providing the appropriate facts.
>
> Is there a way to ignore the rspecs inside the fixtures/modules/ directory?
>
> I tried to do this: 
>
> require 'rake'
> require 'rspec/core/rake_task'
>
> RSpec::Core::RakeTask.new(:spec) do |t|
>   t.pattern = 'spec/*/*_spec.rb'
> end
>
> But it didn't work.
>

How about just:

require 'puppetlabs_spec_helper/rake_tasks'

Garrett Honeycutt

unread,
Aug 13, 2014, 11:30:20 PM8/13/14
to puppet...@googlegroups.com
On 8/13/14 9:08 PM, Wil Cooley wrote:
>
> On Aug 12, 2014 11:57 AM, "Sebastian Otaegui" <fen...@gmail.com
Hi,

+1 to Will Cooley.

When you generate a module with `puppet module generate` it will use
that single line.

https://github.com/puppetlabs/puppet/blob/master/lib/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Sebastian Otaegui

unread,
Aug 14, 2014, 3:57:03 PM8/14/14
to puppet...@googlegroups.com
I created a small POC module using puppet from master and `puppet module generate`

I still have rspec-puppet go inside the apt module in fixtures and execute the tests:

Failures:

  1) poc with defaults for all parameters should contain Class[poc]
     Failure/Error: it { should contain_class('poc') }
     Puppet::Error:
       This module only works on Debian or derivatives like Ubuntu at /Users/otaeguis/projects/src/test-poc/spec/fixtures/modules/apt/manifests/init.pp:43 on node feniixhq.10.208.50.91
     # ./spec/classes/init_spec.rb:5:in `block (3 levels) in <top (required)>'

Here is a link to the puppet module with the POC https://github.com/feniix/puppet-module-rspec-issue

Appreciate some guidance on how to solve this.



--
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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Those who do not understand Unix are condemned to reinvent it, poorly.
Any sufficiently recent Microsoft OS contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Unix.

Garrett Honeycutt

unread,
Aug 14, 2014, 4:27:31 PM8/14/14
to puppet...@googlegroups.com
On 8/14/14 3:56 PM, Sebastian Otaegui wrote:
> I created a small POC module using puppet from master and `puppet module
> generate`
>
> I still have rspec-puppet go inside the apt module in fixtures and
> execute the tests:
>
> Failures:
>
> 1) poc with defaults for all parameters should contain Class[poc]
> Failure/Error: it { should contain_class('poc') }
> Puppet::Error:
> This module only works on Debian or derivatives like Ubuntu at
> /Users/otaeguis/projects/src/test-poc/spec/fixtures/modules/apt/manifests/init.pp:43
> on node feniixhq.10.208.50.91
> # ./spec/classes/init_spec.rb:5:in `block (3 levels) in <top
> (required)>'
>
> Here is a link to the puppet module with the
> POC https://github.com/feniix/puppet-module-rspec-issue
>
> Appreciate some guidance on how to solve this.
>
>
>
> On Wed, Aug 13, 2014 at 10:30 PM, Garrett Honeycutt
> <g...@garretthoneycutt.com <mailto:g...@garretthoneycutt.com>> wrote:
>
> On 8/13/14 9:08 PM, Wil Cooley wrote:
> >
> > On Aug 12, 2014 11:57 AM, "Sebastian Otaegui" <fen...@gmail.com
> <mailto:fen...@gmail.com>
> Mobile: +1.206.414.8658 <tel:%2B1.206.414.8658>
>

Hi Sebastian,

Your issue is because the module in question is failing if certain facts
are not set. In puppetlabs/apt the module fails[1] if $osfamily is not
'Debian'. For your spec tests to succeed you need to set the osfamily
fact to Debian.

[1] -
https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/init.pp#L43-45

Sebastian Otaegui

unread,
Aug 14, 2014, 4:58:52 PM8/14/14
to puppet...@googlegroups.com
Hi Garrett,

thanks, just to clarify and make sure I understood, so it is not running the spec.rb files in apt/spec/* but it is just evaluating the facts within the puppet runtime in the apt/manifest/*.pp, right?

Thanks

--
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...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Garrett Honeycutt

unread,
Aug 14, 2014, 5:35:25 PM8/14/14
to puppet...@googlegroups.com
> <mailto:g...@garretthoneycutt.com <mailto:g...@garretthoneycutt.com>>>
> Mobile: +1.206.414.8658 <tel:%2B1.206.414.8658>
>

Sebastian,

Yes. Your manifests include 'apt'. That code needs the osfamily fact and
since it is not set to to Debian, the code fails and returns the error
to your spec tests. You are not evaluating spec tests under apt. You can
see this by changing the output of rspec. Try this before running your
spec tests.

export SPEC_OPTS="--format documentation"
Reply all
Reply to author
Forward
0 new messages