ChefSpec converge in Automate Unit phases failing

Sean Horn -

I have a cookbook I'm testing named VMwareTomcatProvision.

It's in a directory like this, and has a .delivery directory with a build_cookbook so that it is ready to run through Automate. "cookbooks/VMwareTomcatProvision /spec/unit/recipes/default_spec.rb"

Problem

Every time we tried to send this cookbook through Automate for a build, it would fail in the verify:unit phase like this


* execute[unit_rspec_VMwareTomcatProvision] action run

================================================================================
Error executing action `run` on resource 'execute[unit_rspec_VMwareTomcatProvision]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of rspec --format documentation --color ----
STDOUT: tomcat::default
When all attributes are default, on an unspecified platform
converges successfully (FAILED - 1)

Failures:

1) tomcat::default When all attributes are default, on an unspecified platform converges successfully
Failure/Error: expect { chef_run }.to_not raise_error

expected no Exception, got # with backtrace:
# ./spec/unit/recipes/default_spec.rb:13:in `block (3 levels) in '
# ./spec/unit/recipes/default_spec.rb:17:in `block (4 levels) in '
# ./spec/unit/recipes/default_spec.rb:17:in `block (3 levels) in '
# ./spec/unit/recipes/default_spec.rb:17:in `block (3 levels) in '

Finished in 1.32 seconds (files took 2.33 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/unit/recipes/default_spec.rb:16 # tomcat::default When all attributes are default, on an unspecified platform converges successfully
STDERR: WARNING: you must specify a platform and platform_version to your ChefSpec Runner and/or Fauxhai constructor, in the future omitting these will become a hard error
---- End output of rspec --format documentation --color ----
Ran rspec --format documentation --color returned 1

Solution

The important part to notice in all that output above is

default::tomcat

Wait, what, why? Because the name of the cookbook is `VMwareTomcatProvision`, but we are "describing" a totally different cookbook in the ChefSpec `describe` line of spec/unit/recipes/default_spec.rb as follows


.....unimportant stuff....

describe 'tomcat::default' do
  context 'When all attributes are default, on an unspecified platform' do

.....unimportant stuff....

So, ChefSpec cannot figure out that we are trying to test the cookbook we are running the ChefSpec test in, because we did not name it properly. In a real Chef Server "412 Precondition Failed" almost always means that the Chef Server does not contain the named cookbook at all, or it doesn't contain the cookbook + version we have a constraint on. So, this error does make sense with that knowledge. In other words the fake ChefSpec server is saying "I don't have the cookbook/recipe you asked me to test".

To fix, we need to call out the name of the cookbook where the ChefSpec test lives instead, like this


.....unimportant stuff....

describe 'VMwareTomcatProvision::default' do
  context 'When all attributes are default, on an unspecified platform' do

.....unimportant stuff....
Have more questions? Submit a request

Comments

Powered by Zendesk