Skip to content

Instantly share code, notes, and snippets.

@acrmp
Created March 19, 2012 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acrmp/2128448 to your computer and use it in GitHub Desktop.
Save acrmp/2128448 to your computer and use it in GitHub Desktop.
minitest-chef-handler
require 'minitest/spec'
module MiniTest::Chef::Resources
include Chef::Mixin::ConvertToClassName
def self.register_resource(resource)
define_method(resource) do |name|
clazz = Chef::Resource.const_get(convert_to_class_name(resource.to_s))
res = clazz.new(name, run_context)
Chef::Platform.provider_for_resource(res).load_current_resource
end
end
[:package, :service].each{|r| register_resource(r)}
end
module MiniTest::Assertions
def assert_package_installed(package)
refute package.version.nil?, "Expected #{package} to be installed"
end
def assert_service_running(service)
assert service.running, "Expected #{service} to be running"
end
# MiniTest::Spec
Chef::Resource::Package.infect_an_assertion :assert_package_installed, :must_be_installed, :only_one_argument
Chef::Resource::Service.infect_an_assertion :assert_service_running, :must_be_running, :only_one_argument
end
class TestMysql < MiniTest::Chef::TestCase
include MiniTest::Chef::Resources
def test_mysql_installed
assert_package_installed package("mysql-server")
end
def test_mysql_running
assert_service_running service("mysql")
end
end
#describe 'mysql::server' do
#
# include MiniTest::Chef::Resources
#
# it "installs mysql" do
# package("mysql-server").must_be_installed
# end
#
# it "starts mysql" do
# service("mysql").must_be_running
# end
#
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment