Search code examples
rubyrspecchef-infrachefspec

chefspec testing resource with loops


If I have a chef recipe with the following attribute

node.default["cookbook"]["directory"] = %w(/mnt/directory1 /mnt/directory2)

    node["cookbook"]["directory"].each do |dir|
      directory dir do
        owner "user"
        mode 0644"
        action :create
      end
    end

How would I write a chefspec test that handles an array of directories to be created based on the attribute?

Thank you for your help.


Solution

  • expect(chef_run).to create_directory('/mnt/directory1')
    expect(chef_run).to create_directory('/mnt/directory2')