cpspec
Cpspec is a framework which allows behaviour driven development for chef cookbooks/Puppet Manifests. It enables testing of the cookbooks on the local box. The same test then can be executed on Target machine. It is a vagrant extension. Use vagrant to apply cookbook on the local environment and then run test to assert if desired changes are applied.
Installation
-
Install vagrant. Installation instructions can be found here.(vagrantup.com/docs/getting-started/index.html)
gem install cpsec
Usage
-
Write test for the cook books
require 'test/unit'
class TestJavaCookbook
def test_java_installed_in_correct_path
assert_true File.exists?("/usr/bin/java")
end
end
-
Specify the test directory path (Absolute or relative)
Vagrant::Config.run do |config|
config.test.directory = "env-test"
config.vm.define :dev do |conf|
conf.vm.box = "lucid32"
conf.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "chef-repo/cookbooks"
chef.add_recipe "java"
end
end
end
-
Run tests
vagrant run_test
Copyright
Copyright © 2011 Shishir Das. See LICENSE.txt for further details.