# Chefspec filter recipe eval, or stub include\_recipe?

**URL:** <https://discourse.chef.io/t/chefspec-filter-recipe-eval-or-stub-include-recipe/5265>\
**Category:** Chef Infra (archive)\
**Created:** [April 30, 2014, 3:24pm UTC](https://discourse.chef.io/t/chefspec-filter-recipe-eval-or-stub-include-recipe/5265 "2014-04-30T15:24:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_G\_Wolfe1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_g_wolfe1/32/90_2.png) [@Eric\_G\_Wolfe1](https://discourse.chef.io/u/Eric_G_Wolfe1)\
**Post date:** [April 30, 2014, 3:24pm UTC](https://discourse.chef.io/t/chefspec-filter-recipe-eval-or-stub-include-recipe/5265/1 "2014-04-30T15:24:36Z")

</div>

So I am trying to Chefspec some branching logic in a baseline cookbook.  
The recipe chef-client::delete\_validation is throwing up an exception on  
line 28 where it checks for the existence of Chef::Config[:client\_key] (  
[chef-client/recipes/delete\_validation.rb at main · chef-boneyard/chef-client · GitHub](https://github.com/opscode-cookbooks/chef-client/blob/master/recipes/delete_validation.rb#L28)).  
I get several errors like so:

1. mu-baseline::default On Centos 6.4 as a VMWare guest does include

> recipe mu-baseline::zenoss\_register  
> Failure/Error: end.converge(described\_recipe)  
> TypeError:  
> no implicit conversion of nil into String  
> #  
> /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete\_validation.rb:28:in  
> `exists?' # /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete_validation.rb:28:in `block (2 levels) in from\_file'  
> # ./spec/default\_spec.rb:43:in `block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:in `block (4 levels) in \<top (required)\>'

If I just remove `include_recipe 'chef-client::delete_validation'` those  
test(s) pass. Is there a way I can filter that recipe's evaluation, or  
something I can stub, to get past this exception?

---

<div class="post-metadata">

**Author:** ![Pete\_Cheslock](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/pete_cheslock/32/326_2.png) [@Pete\_Cheslock](https://discourse.chef.io/u/Pete_Cheslock)\
**Post date:** [April 30, 2014, 4:08pm UTC](https://discourse.chef.io/t/chefspec-filter-recipe-eval-or-stub-include-recipe/5265/2 "2014-04-30T16:08:58Z")

</div>

Eric,

Can you do something like this? Does this work?

> <https://gist.github.com/petecheslock/0f54506406b5e9b42ab2#file-gistfile1-txt-L7>

-Pete

On Wed, Apr 30, 2014 at 11:24 AM, Eric Wolfe [eric.wolfe@gmail.com](mailto:eric.wolfe@gmail.com) wrote:

> So I am trying to Chefspec some branching logic in a baseline cookbook.  
> The recipe chef-client::delete\_validation is throwing up an exception on  
> line 28 where it checks for the existence of Chef::Config[:client\_key] (  
> [https://github.com/opscode-cookbooks/chef-client/blob/master/recipes/delete\_validation.rb#L28](https://github.com/opscode-cookbooks/chef-client/blob/master/recipes/delete_validation.rb#L28)).  
> I get several errors like so:
> 
> 1. mu-baseline::default On Centos 6.4 as a VMWare guest does include
> 
> > recipe mu-baseline::zenoss\_register  
> > Failure/Error: end.converge(described\_recipe)  
> > TypeError:  
> > no implicit conversion of nil into String  
> > #  
> > /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete\_validation.rb:28:in  
> > `exists?' # /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete_validation.rb:28:in `block (2 levels) in from\_file'  
> > # ./spec/default\_spec.rb:43:in `block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:in `block (4 levels) in \<top (required)\>'
> 
> If I just remove `include_recipe 'chef-client::delete_validation'` those  
> test(s) pass. Is there a way I can filter that recipe's evaluation, or  
> something I can stub, to get past this exception?

---

<div class="post-metadata">

**Author:** ![Eric\_G\_Wolfe1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_g_wolfe1/32/90_2.png) [@Eric\_G\_Wolfe1](https://discourse.chef.io/u/Eric_G_Wolfe1)\
**Post date:** [April 30, 2014, 6:12pm UTC](https://discourse.chef.io/t/chefspec-filter-recipe-eval-or-stub-include-recipe/5265/3 "2014-04-30T18:12:39Z")

</div>

Yes Pete that does work. Thanks, Pete and Zack!

On Wed, Apr 30, 2014 at 12:08 PM, Pete Cheslock [petecheslock@gmail.com](mailto:petecheslock@gmail.com)wrote:

> Eric,
> 
> Can you do something like this? Does this work?
> 
> [gist:0f54506406b5e9b42ab2 · GitHub](https://gist.github.com/petecheslock/0f54506406b5e9b42ab2#file-gistfile1-txt-L7)
> 
> -Pete
> 
> On Wed, Apr 30, 2014 at 11:24 AM, Eric Wolfe [eric.wolfe@gmail.com](mailto:eric.wolfe@gmail.com) wrote:
> 
> > So I am trying to Chefspec some branching logic in a baseline cookbook.  
> > The recipe chef-client::delete\_validation is throwing up an exception on  
> > line 28 where it checks for the existence of Chef::Config[:client\_key] (  
> > [https://github.com/opscode-cookbooks/chef-client/blob/master/recipes/delete\_validation.rb#L28](https://github.com/opscode-cookbooks/chef-client/blob/master/recipes/delete_validation.rb#L28)).  
> > I get several errors like so:
> > 
> > 1. mu-baseline::default On Centos 6.4 as a VMWare guest does include
> > 
> > > recipe mu-baseline::zenoss\_register  
> > > Failure/Error: end.converge(described\_recipe)  
> > > TypeError:  
> > > no implicit conversion of nil into String  
> > > #  
> > > /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete\_validation.rb:28:in  
> > > `exists?' # /tmp/d20140430-13074-1bq5osr/cookbooks/chef-client/recipes/delete_validation.rb:28:in `block (2 levels) in from\_file'  
> > > # ./spec/default\_spec.rb:43:in `block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:in `block (4 levels) in \<top  
> > > (required)\>'
> > 
> > If I just remove `include_recipe 'chef-client::delete_validation'` those  
> > test(s) pass. Is there a way I can filter that recipe's evaluation, or  
> > something I can stub, to get past this exception?
