Class: PuppetCheck::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/puppet-check/tasks.rb

Overview

the rake interface for PuppetCheck

Instance Method Summary collapse

Constructor Details

#initializeTasks

Returns a new instance of Tasks.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/puppet-check/tasks.rb', line 10

def initialize
  super

  desc 'Execute all Puppet-Check checks'
  task puppetcheck: %w[puppetcheck:file puppetcheck:spec puppetcheck:beaker puppetcheck:kitchen]

  namespace :puppetcheck do
    desc 'Execute Puppet-Check file checks'
    task :file, [:settings] do |_, wrapped_settings|
      PuppetCheck.new.run(wrapped_settings[:settings], Dir.glob('*'))
    end

    # rspec and rspec-puppet tasks
    begin
      require 'rspec/core/rake_task'
      require_relative 'rspec_puppet_support'

      desc 'Execute RSpec and RSpec-Puppet tests'
      RSpec::Core::RakeTask.new(:spec) do |task|
        RSpecPuppetSupport.run
        # generate tasks for all recognized directories and ensure spec tests inside module dependencies are ignored
        spec_dirs = Dir.glob('**/{classes,defines,facter,functions,hosts,puppet,unit,types}/**/*_spec.rb').grep_v(/fixtures/)
        task.pattern = spec_dirs.empty? ? 'skip_rspec' : spec_dirs
      end
    rescue LoadError
      desc 'RSpec is not installed.'
      task :spec do
        puts 'RSpec is not installed. The RSpec/RSpec-Puppet tasks will not be available.'
      end
    end

    # beaker tasks
    begin
      require 'beaker/tasks/quick_start'

      desc 'Execute Beaker acceptance tests'
      task :beaker, %i[hypervisor] do |_, args|
        args[:hypervisor] = 'vagrant' if args[:hypervisor].nil?
        Rake::Task["beaker_quickstart:run_test[#{args[:hypervisor]}]"].invoke
      end
    rescue LoadError
      desc 'Beaker is not installed.'
      task :beaker do
        puts 'Beaker is not installed. The Beaker tasks will not be available.'
      end
    end

    # test kitchen tasks
    begin
      require 'kitchen/rake_tasks'

      desc 'Execute Test Kitchen acceptance tests'
      task :kitchen do
        Rake::Task['kitchen:all'].invoke
      end
    rescue LoadError
      desc 'Test Kitchen is not installed.'
      task :kitchen do
        puts 'Test Kitchen is not installed. The Kitchen tasks will not be available.'
      end
    end
  end
end