Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Run minitest suites after your Chef recipes to check the status of your system.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Vagrantfile
Octocat-spinner-32 minitest-chef-handler.gemspec
README.md

Minitest Chef Handler

Run minitest suites after your Chef recipes to check the status of your system.

Motivation

Working at Engine Yard I have to maintain a quite complicated set of Chef recipes that we use to set up our customers' instances. I need to be sure that everytime someone modifies those recipes, mostly myself, the provisioned services continue working as expected.

There are other solutions that evaluate the configured node after the recipes are loaded without arriving to the converge phase, like ChefSpec or rspec-chef, but I needed something to write integration tests easily. I checked chef-minitest but I'm still amazed by the ugly code that I have to write into the recipes to make it work.

Installation

$ gem install minitest-chef-handler

Usage

  1. Add the report handler to your client.rb or solo.rb file:
require 'minitest-chef-handler'

report_handlers << MiniTest::Chef::Handler.new
  1. 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

You still have access to Chef's run_status, node and run_context from your tests:

class TestNginx < MiniTest::Chef::TestCase
  def test_succeed
    assert run_status.success?
  end
end

Further configuration

These are the options the handler accepts:

  • :path => where your test files are, './test/test_*.rb' by default
  • :filter => filter test names on pattern
  • :seed => set random seed
  • :verbose => show progress processing files.

Example:

handler = MiniTest::Chef::Handler.new({
  :path    => './cookbooks/test/*_test.rb',
  :filter  => 'foo',
  :seed    => srand,
  :verbose => true})

report_handlers << handler

Copyright

Copyright (c) 2012 David Calavera. See LICENSE for details.

Something went wrong with that request. Please try again.