2

I have created a custom cookbook resource within the resources directory of the cookbook. Can anybody advice how to write unit tests for this? I am using rspec. Below is an example of my custom resource.

resource_name :sample
property :target_path, kind_of: String, name_property: true

action :create do
  remote_file "#{target_path}" do
  end
end
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Basil Paul
  • 92
  • 7

2 Answers2

2

The main-line option would be to make a test cookbook with a bunch of test recipes. This is unfortunately a bit ungainly. Keep an eye on https://github.com/poise/poise-spec to improve this. It should work today if you want to dive in and read the code, or check out the resource unit tests in any of my other cookbooks.

coderanger
  • 52,400
  • 4
  • 52
  • 75
0

One option is chefspec, which is based on rspec. A spec for a custom LWRP (precursor to modern day resources) is documented in How can I test my LWRP with ChefSpec?

jedifans
  • 2,287
  • 1
  • 13
  • 9