class Beaker::Tasks::RakeTask

Constants

COMMAND_OPTIONS
DEFAULT_ACCEPTANCE_ROOT

Public Class Methods

new(*args, &task_block) click to toggle source

Sets up the predefine task checking @param args [Array] First argument is always the name of the task if no additonal arguments are defined such as parameters it will default to [:hosts,:type]

Calls superclass method
# File lib/beaker/tasks/rake_task.rb, line 32
def initialize(*args, &task_block)
  super

  @name = args.shift || 'beaker:test'
  args = %i[hosts type] if args.empty?
  @acceptance_root = DEFAULT_ACCEPTANCE_ROOT
  @options_file = nil
  define(args, &task_block)
end

Private Instance Methods

beaker_command() click to toggle source

Generate the beaker command to run beaker with all possible options passed

# File lib/beaker/tasks/rake_task.rb, line 94
def beaker_command
  cmd_parts = []
  cmd_parts << "beaker"
  cmd_parts << "--keyfile #{@keyfile}" if @keyfile
  cmd_parts << "--hosts #{@hosts}" if (@hosts != nil && !@hosts.empty?)
  cmd_parts << "--tests #{tests}" if @tests
  cmd_parts << "--options-file #{@options_file}" if @options_file
  cmd_parts << "--type #{@type}" if @type
  cmd_parts << "--helper #{@helper}" if @helper
  cmd_parts << "--fail-mode #{@fail_mode}" if @fail_mode
  cmd_parts.flatten.join(" ")
end
check_env_variables() click to toggle source

Check for existence of ENV variables for test if !@tests is undef

# File lib/beaker/tasks/rake_task.rb, line 86
def check_env_variables
  @tests = File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests') if File.exist?(File.join(DEFAULT_ACCEPTANCE_ROOT, 'tests'))
  @tests = ENV['TESTS'] || ENV.fetch('TEST', nil) if !@tests
end
check_for_beaker_type_config() click to toggle source

If an options file exists in the acceptance path for the type given use it as a default options file

if no other options file is provided
# File lib/beaker/tasks/rake_task.rb, line 77
def check_for_beaker_type_config
  return unless !@options_file && File.exist?("#{@acceptance_root}/.beaker-#{@type}.cfg")

  @options_file = File.join(@acceptance_root, ".beaker-#{@type}.cfg")
end
define(args) { |*[self, task_args].slice(0, arity)| ... } click to toggle source

@private

# File lib/beaker/tasks/rake_task.rb, line 61
def define(args, &task_block)
  # Depending on the version of rake, either last_description or last_comment will be available.
  desc "Run Beaker Acceptance" unless (::Rake.application.respond_to?(:last_description) ? ::Rake.application.last_description : ::Rake
                                                                                                                          .application.last_comment)
  task name, *args do |_, task_args|
    RakeFileUtils.__send__(:verbose, verbose) do
      yield(*[self, task_args].slice(0, task_block.arity)) if task_block
      run_task verbose
    end
  end
end
run_task(verbose) click to toggle source

Run the task provided, implements the rake task interface

@param verbose [bool] Defines wether to run in verbose mode or not

# File lib/beaker/tasks/rake_task.rb, line 47
def run_task(verbose)
  puts "Running task"

  check_for_beaker_type_config
  command = beaker_command
  puts command if verbose
  success = system(command)
  return unless fail_mode == "fast" && !success

  $stderr.puts "#{command} failed"
  exit $?.exitstatus
end