Class: CemAcpt::Bolt::Tests::Test

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/bolt/tests.rb

Overview

Provides an interface for running tests against Bolt tasks

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

Instance 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?

Constructor Details

#initialize(name, data, object, *groups) ⇒ Test

Returns a new instance of Test.



239
240
241
242
243
244
245
246
247
# File 'lib/cem_acpt/bolt/tests.rb', line 239

def initialize(name, data, object, *groups)
  @name = name
  @data = data.is_a?(Hash) ? TestData.new(**data) : TestData.new
  @object = object
  @groups = groups
  @command_result = nil
  @result = TestResults.new(name)
  @validation_results = {}
end

Instance Attribute Details

#command_resultObject (readonly)

Returns the value of attribute command_result.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def command_result
  @command_result
end

#dataObject (readonly)

Returns the value of attribute data.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def data
  @data
end

#groupsObject (readonly)

Returns the value of attribute groups.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def groups
  @groups
end

#nameObject (readonly)

Returns the value of attribute name.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def object
  @object
end

#resultObject (readonly)

Returns the value of attribute result.



237
238
239
# File 'lib/cem_acpt/bolt/tests.rb', line 237

def result
  @result
end

Instance Method Details

#add_group(group) ⇒ Object

Groups in this context refers to the acceptance test names. Because the acceptance tests act like logical groups, we refer to them as groups here to avoid confusion with the Bolt tests.



251
252
253
# File 'lib/cem_acpt/bolt/tests.rb', line 251

def add_group(group)
  @groups << group unless @groups.include?(group)
end

#inspectObject



267
268
269
# File 'lib/cem_acpt/bolt/tests.rb', line 267

def inspect
  to_s
end

#runObject



255
256
257
258
259
260
261
# File 'lib/cem_acpt/bolt/tests.rb', line 255

def run
  logger.debug('CemAcpt::Bolt::Tests::Test') { "Running test #{name}" }
  @command_result = @object.run(**@data.params)
  validate!
rescue StandardError => e
  new_wrapped_error("Error running test #{name}", e)
end

#to_sObject



263
264
265
# File 'lib/cem_acpt/bolt/tests.rb', line 263

def to_s
  "#<#{self.class}:#{object_id.to_s(16)} #{name},#{object},#{groups.join(',')}>"
end