Sha256: 1b7920d1168eb88cd9367b5bc11b192bf11ec4ab2dac685235027ff87ab1e7b5

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'rspec/core/rake_task'
require 'rake/tasklib'
require 'rake/task'
require_relative '../puppet-check'

# the rake interface for PuppetCheck
class PuppetCheck::Tasks < ::Rake::TaskLib
  def initialize
    desc 'Execute all Puppet-Check checks'
    task :puppetcheck do
      %w(puppetcheck:file puppetcheck:spec puppetcheck:beaker).each { |task| Rake::Task[task.to_sym].invoke }
    end

    namespace :puppetcheck do
      desc 'Execute Puppet-Check file checks'
      task :file do
        exit_code = PuppetCheck.new.run(Dir.glob('*'))
        # changes nothing if this task is run separately; aborts 'puppetcheck' task if there are errors here
        exit exit_code if exit_code != 0
      end

      desc 'Execute RSpec and RSpec-Puppet tests'
      RSpec::Core::RakeTask.new(:spec) do |task|
        rspec_puppet_setup
        # generate tasks for all recognized directories inside of spec directories
        task.pattern = '**/{classes, defines, facter, functions, hosts, puppet, unit, types}/**/*_spec.rb'
      end

      desc 'Execute Beaker acceptance tests'
      RSpec::Core::RakeTask.new(:beaker) do |task|
        task.pattern = '**/acceptance'
      end
    end
  end

  # prepare the directories for rspec-puppet testing
  def rspec_puppet_setup
    # leave method immediately if there is no rspec-puppet installed
    begin
      require 'rspec-puppet/setup'
    rescue LoadError
      return
    end

    # executes rspec::puppet::setup in every module directory to ensure module spec directories are configured correctly
    Dir.glob('**/spec').each do |specdir|
      Dir.chdir(specdir + '/..')
      RSpec::Puppet::Setup.run
    end
  end
end

PuppetCheck::Tasks.new

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-check-1.1.0 lib/puppet-check/tasks.rb