Chefspec filter recipe eval, or stub include_recipe?


#1

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).
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:inblock (2 levels) in from_file’
# ./spec/default_spec.rb:43:in block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:inblock (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?


#2

Eric,

Can you do something like this? Does this work?

-Pete

On Wed, Apr 30, 2014 at 11:24 AM, Eric Wolfe 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).
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:inblock (2 levels) in from_file’
# ./spec/default_spec.rb:43:in block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:inblock (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?


#3

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

On Wed, Apr 30, 2014 at 12:08 PM, Pete Cheslock petecheslock@gmail.comwrote:

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 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).
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:inblock (2 levels) in from_file’
# ./spec/default_spec.rb:43:in block (3 levels) in <top (required)>' # ./spec/default_spec.rb:48:inblock (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?