Skip to content

Instantly share code, notes, and snippets.

@acrmp
acrmp / 00_README.md
Created November 10, 2012 00:05
Mocking out a library in Chef

Example of mocking out a library in Chef so you can test the provider in isolation.

If you want to test the library itself you can do more normal Ruby things.

class Chef
class Recipe
def skip_unsupported_platform
unless supported_platform?
Chef::Log.info("Unsupported platform #{node[:platform]} in #{cookbook_name}::#{recipe_name}, skipping recipe")
Chef::Log.debug("You said to skip unsupported platforms in #{cookbook_name}::#{recipe_name}")
Chef::Log.debug("and #{node['platform']} is unsupported by cookbook #{cookbook_name}. Update the cookbook's metadata")
Chef::Log.debug("if this is a supported platform, or remove #{cookbook_name}::#{recipe_name} from the node.")
end
end