class Pfm::Command::ValidatorCommands::ServerBuild

def unit_test

def unit_test
  # load chefspec here as it load chef and can take a long time on some systems
  # so we only want to load it when we absolutely need it
  require 'chefspec'
  base_path = 'chef'
  cookbooks_dir = 'cookbooks'
  # Loop through the base directory looking through all of the cookbooks
  # for unit tests
  Dir.entries(base_path).each do |dir|
    next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}"
    next if dir.to_s == 'vendor'
    Dir.entries("#{base_path}/#{dir}/#{cookbooks_dir}").each do |cookbook|
      next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}"
      # skip directories eg. '.' and '..'
      next if cookbook.to_s == '.' || cookbook.to_s == '..'
      # run rspec unit tests
      Dir.chdir("#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") do
        msg("\nRunning unit tests for #{cookbook} cookbook")
        system("rspec -r rspec_junit_formatter --format progress --format RspecJunitFormatter -o #{@reports_dir}/rspec/#{cookbook}_junit.xml") || @failure = true
      end
    end
  end
end