#!/usr/bin/env rake
# encoding: utf-8

require 'rake/testtask'
require 'rubocop/rake_task'

# Rubocop
desc 'Run Rubocop lint checks'
task :rubocop do
  RuboCop::RakeTask.new
end

# lint the project
desc 'Run robocop linter'
task lint: [:rubocop]

# run tests
task default: [:lint, 'test:check']

namespace :test do
  # run inspec check to verify that all profiles are properly configured
  task :check do
    path = File.join(File.dirname(__FILE__))
    Dir.glob(['base/*', 'cis/*']).all? do |dir|
      # only run inspec, if its a folder
      File.directory?(dir) ? sh("cd #{path} && bundle exec inspec check #{dir} --profiles-path .") : true
    end or fail 'Failures'
  end
end
