
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
minitest-chef-handler
Advanced tools
Run minitest suites after your Chef recipes to check the status of your system.
gem install minitest-chef-handler
Option 1: Add the report handler to your client.rb or solo.rb file:
require 'minitest-chef-handler'
report_handlers << MiniTest::Chef::Handler.new
Options 2: Using minitest-handler
# Vagrantfile
chef.run_list = [
"your-recipes",
"minitest-handler"
]
Write your tests as normal MiniTest cases extending from MiniTest::Chef::TestCase:
class TestNginx < MiniTest::Chef::TestCase
def test_config_file_exist
assert File.exist?('/etc/nginx.conf')
end
end
Inside your tests cases, you still have access to Chef's run_status
, node
and run_context
:
class TestNginx < MiniTest::Chef::TestCase
def test_succeed
assert run_status.success?
end
end
Wrap your descriptions with a class extending from MiniTest::Chef::Spec:
class NginxSpec < MiniTest::Chef::Spec
describe 'configuration' do
it 'creates nginx.conf'
end
end
Use the prefix recipe::
in your descriptions:
describe "recipe::nginx::configuration" do
it 'creates nginx.conf'
end
Or use describe_recipe
to define your specs:
describe_recipe "nginx::configuration" do
it 'creates nginx.conf'
end
Inside your specs, you still have access to Chef's run_status
, node
and run_context
:
describe_recipe 'nginx:configuration' do
it 'installs version 1.0.15' do
node[:nginx][:version].should == '1.0.15'
end
end
By including MiniTest::Chef::Resources
and MiniTest::Chef::Assertions
you
can also make assertions like these:
file("/etc/fstab").must_have(:mode, "644")
package("less").must_be_installed
service("chef-client").must_be_running
assert_directory "/etc", "root", "root", "755"
assert_file "/etc/fstab", "root", "root", "644"
assert_sh "ls /etc"
assert_logrotate "/etc/logrotate.d/mysql"
and many more
The resources supported are: cron
, directory
, file
, group
, ifconfig
,
link
, mount
, package
, service
and user
.
For example usage see the tests under the examples/spec_examples
directory.
These are the options the handler accepts:
Example:
handler = MiniTest::Chef::Handler.new({
:path => './cookbooks/test/*_test.rb',
:filter => 'foo',
:seed => srand,
:verbose => true})
report_handlers << handler
MiniTest-chef-hander collects test paths based in the recipes ran. It loads the tests based on the name of the cookbook and the name of the recipe. The tests must be under the cookbooks directory.
Examples:
If the seen recipes includes the recipe "foo" we try to load tests from:
cookbooks/foo/tests/default_test.rb
cookbooks/foo/tests/default/*_test.rb
cookbooks/foo/specs/default_spec.rb
cookbooks/foo/specs/default/*_spec.rb
If the seen recipes includes the recipe "foo::install" we try to load tests from:
cookbooks/foo/tests/install_test.rb
cookbooks/foo/tests/install/*_test.rb
cookbooks/foo/specs/install_spec.rb
cookbooks/foo/specs/install/*_spec.rb
If the tests detect any failure, the handler raises an error to abort the Chef execution. This error can be captured by any other exception handler and be treated like any other error in the Chef execution.
The instructions above have described how to use it in a Chef solo installation. If you want to distribute the handler to your Chef server check either the chef_handler cookbooks in the examples or minitest-handler-cookbook.
bundle
bundle exec rake # unit tests
bundle exec vagrant up # integration tests (install virtualbox first and vagrant destroy -f afterwards to clean up)
Copyright (c) 2012 David Calavera. See LICENSE for details.
FAQs
Unknown package
We found that minitest-chef-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.