- From: Malte Swart <
>
- To:
- Subject: [chef] Re: ChefSpec for LWRPs without recipes...
- Date: Wed, 08 May 2013 23:08:44 +0200
- Organization: Devtation Software Systems
Hey,
I had to solve the same problem for a cookbook of my own.
My approach is similar to your second alternative. A created another (test)
cookbook which uses and depends on the main cookbook (LWRP, definitions ...).
I put this cookbook under spec/support/cookbooks and adjusted the ChefSpec
cookbook_path to use also spec/support/cookbook to search for cookbooks. [1]
It is undocumented but chefspec supports like the chef client also a list of
directories as cookbook_path.
In my case Chef::ChefRunner.new cookbook_path: [ '..',
'spec/support/cookbooks' ] works great. There might be a more robust way to
set the cookbook path like [2] - but if chefspec is started from the cookbook
directory, there should no problem.
I hope this late answer helps you, too.
Malte.
[1]:
https://github.com/acrmp/chefspec#varying-the-cookbook-path
[2]:
https://github.com/acrmp/chefspec/blob/master/lib/chefspec/chef_runner.rb#L161
On Wednesday, 01 May 2013 07:53:21 Bryan Stenson wrote:
>
Ohai!
>
>
Following the cookbook pattern described in the "Berkshelf Way", I'm trying
>
to create a library cookbook which contains some custom LWRPs. This
>
library cookbook will not have any meaningful recipe on its own...it will
>
only supply providers and resources to be consumed by application cookbooks.
>
>
I'd like to test the library cookbook separately, and I think ChefSpec is
>
the correct approach for unit testing. I see that ChefSpec takes a recipe
>
list when "converging", but, since my library cookbook won't have recipes,
>
I don't have one to give to ChefRunner.
>
>
I suppose I'd like some suggestions/experiences on how to do this. From my
>
perspective, I can see at least two ways to solve it (with a STRONG
>
preference on the latter):
>
>
1. Create a "lwrp_testing.rb" recipe which will specifically call out to
>
each LWRP the library cookbook provides. I don't like this cause then I've
>
got a testing recipe floating around which COULD be applied to a node in
>
production - and that's just silly. I could prefix this recipe with a "_"
>
(as in, "_lwrp_testing.rb"), but again, it feels like a hack.
>
>
2. Create a recipe fixture for testing the LWRP for use only during
>
ChefSpec runs. The recipe would only exist in the context of a ChefSpec
>
run, and allow for valid exercise of the underlying LWRPs during
>
testing...at the same time, the recipe would not exist "for reals" in the
>
cookbook, and couldn't be assigned to a run_list. This seems like an
>
elegant approach (design wise), but my Ruby skills are not to the level
>
they should be to easily implement this. Anybody else try this?
>
>
Or, perhaps there's another solution I'm overlooking?
>
>
Thanks for your thoughts.
>
>
Bryan
>
>
PS - Thanks to everybody for another great ChefConf!
Archive powered by MHonArc 2.6.16.