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.
# 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
Am I missing something obvious (I'm new to Chef and Ruby)?
Thanks, Richard.