[chef] Running ChefSpec without Berkshelf or Librarian


Chronological Thread 
  • From: Richard Murray < >
  • To:
  • Subject: [chef] Running ChefSpec without Berkshelf or Librarian
  • Date: Fri, 14 Feb 2014 11:58:27 +0000

Hi I'm trying to write a unit tests using ChefSpec (and Chef Solo) but I can't get even the simplest test to work.  I've tried following several examples but always get a Chef::Exceptions::CookbookNotFound error on the cookbook I'm attempting to test.

For example if I add the following to the 'java' cookbook (http://community.opscode.com/cookbooks/java

# coobooks/java/spec/default_spec.rb
require 'chefspec'

describe 'java::default' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }  
  it 'should include the openjdk recipe by default' do
    chef_run.should include_recipe 'java::openjdk'
  end
end

When I run rspec I get the following error:

Failures:

  1) java::default should include the openjdk recipe by default
     Failure/Error: let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
     Chef::Exceptions::CookbookNotFound:
       Cookbook java not found. If you're loading java from another cookbook, make sure you configure the dependency in your metadata
     # ./cookbooks/java/spec/default_spec.rb:4:in `block (2 levels) in <top (required)>'
     # ./cookbooks/java/spec/default_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.035 seconds
1 example, 1 failure

Failed examples:

rspec ./cookbooks/java/spec/default_spec.rb:5 # java::default should include the openjdk recipe by default


I've tried running the following commands but they both result in this error:

rspec cookbooks\java
rspec cookbooks\java\spec\default_spec.rb


I've tried adding a .chef/knife.rb as detailed here https://wiki.opscode.com/display/chef/Troubleshooting+and+Technical+FAQ) but that didn't help.

The ChefSpec readme (https://github.com/sethvargo/chefspec) mentions BerkShelf and Librarian.  I don't currently use either of those tools, do I need them to run ChefSpec?

Am I missing something obvious (I'm new to Chef and Ruby)?

Thanks, Richard.



Archive powered by MHonArc 2.6.16.

§