Module: CemAcpt::Platform

Extended by:
Logging
Defined in:
lib/cem_acpt/platform.rb,
lib/cem_acpt/platform/base.rb

Overview

CemAcpt::Platform manages creating and configring platform specific objects for the acceptance test suites.

Defined Under Namespace

Classes: Base, Error, TestBase

Constant Summary collapse

PLATFORM_DIR =
File.expand_path(File.join(__dir__, 'platform'))
BASE_TYPES =
%i[base test].freeze

Constants included from Logging

Logging::LEVEL_MAP

Class Method Summary collapse

Methods included from Logging

current_log_config, current_log_config, current_log_format, current_log_format, current_log_level, current_log_level, included, logger, logger, new_log_config, new_log_config, new_log_formatter, new_log_formatter, new_log_level, new_log_level, new_logger, new_logger, verbose?, verbose?

Class Method Details

.get(platform, base_type: :test) ⇒ Object

Returns an un-initialized platform specific Class of the given platform.

Parameters:

  • platform (String)

    the name of the platform

  • base_type (Symbol) (defaults to: :test)

    the type of base class to use.

Raises:



36
37
38
39
40
41
# File 'lib/cem_acpt/platform.rb', line 36

def get(platform, base_type: :test)
  raise Error, "Platform #{platform} is not supported" unless platforms.include?(platform)
  raise Error, "Base type #{base_type} is not supported" unless BASE_TYPES.include?(base_type.to_sym)

  platform_class(base_type, platform)
end

.platformsObject

Returns an array of the names of the supported platforms. Supported platforms are discovered by looking for files in the platform directory, and platform names are the basename (no extension) of the files. We deliberately exclude the base class, as it is not a platform.



48
49
50
51
52
53
54
55
56
57
# File 'lib/cem_acpt/platform.rb', line 48

def platforms
  return @platforms if defined?(@platforms)

  @platforms = Dir.glob(File.join(PLATFORM_DIR, '*.rb')).map do |file|
    File.basename(file, '.rb') unless file.end_with?('base.rb')
  end
  @platforms.compact!
  logger.debug('CemAcpt::Platform') { "Discovered platform(s): #{@platforms}" }
  @platforms
end

.use(platform, config, run_data) ⇒ Object

Creates a new platform specific object of the given platform for each item in the test data.

Parameters:

  • platform (String)

    the name of the platform

  • config (CemAcpt::Config)

    the config object

  • run_data (Hash)

    the current run data. Must include a :test_data key

Raises:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cem_acpt/platform.rb', line 21

def use(platform, config, run_data)
  raise Error, "Platform #{platform} is not supported" unless platforms.include?(platform)
  raise Error, 'run_data must be an Hash' unless run_data.is_a?(Hash)
  raise Error, 'run_data must include a :test_data key' unless run_data.key?(:test_data)
  raise Error, 'run_data[:test_data] must be an Array' unless run_data[:test_data].is_a?(Array)

  logger.info('CemAcpt::Platform') { "Using #{platform} for #{run_data[:test_data].length} tests..." }
  run_data[:test_data].dup.each_with_object([]) do |single_test_data, ary|
    ary << new_test_platform_object(platform, config, single_test_data, **run_data.reject { |k, _| k == :test_data })
  end
end