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

Constant Summary collapse

PLATFORM_DIR =
File.expand_path(File.join(__dir__, 'platform'))

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

Class Method Details

.get(platform) ⇒ Object

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

Parameters:

  • platform (String)

    the name of the platform

Raises:



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

def get(platform)
  raise Error, "Platform #{platform} is not supported" unless platforms.include?(platform)

  platform_class(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.



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

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 "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 "Using #{platform} for #{run_data[:test_data].length} tests..."
  run_data[:test_data].dup.each_with_object([]) do |single_test_data, ary|
    ary << new_platform_object(platform, config, single_test_data, **run_data.except(:test_data))
  end
end