Class: QaServer::ScenarioLogger

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/loggers/qa_server/scenario_logger.rb

Constant Summary collapse

PASS =
QaServer::ScenarioValidator::PASS
FAIL =
QaServer::ScenarioValidator::FAIL
UNKNOWN =
QaServer::ScenarioValidator::UNKNOWN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_count = 0, failure_count = 0) ⇒ ScenarioLogger

Returns a new instance of ScenarioLogger.



16
17
18
19
20
# File 'app/loggers/qa_server/scenario_logger.rb', line 16

def initialize(test_count = 0, failure_count = 0)
  @log = []
  @test_count = test_count
  @failure_count = failure_count
end

Instance Attribute Details

#failure_countObject (readonly)

Returns the value of attribute failure_count.



10
11
12
# File 'app/loggers/qa_server/scenario_logger.rb', line 10

def failure_count
  @failure_count
end

#test_countObject (readonly)

Returns the value of attribute test_count.



10
11
12
# File 'app/loggers/qa_server/scenario_logger.rb', line 10

def test_count
  @test_count
end

Instance Method Details

#add(status_info) ⇒ Object

Add a scenario to the log

Parameters:

  • status_info (Hash)

    holding information to be logged

  • authority_name (Hash)

    a customizable set of options

  • status (Hash)

    a customizable set of options

  • validation_type (Hash)

    a customizable set of options

  • subauth (Hash)

    a customizable set of options

  • service (Hash)

    a customizable set of options

  • action (Hash)

    a customizable set of options

  • url (Hash)

    a customizable set of options

  • error_message (Hash)

    a customizable set of options

  • expected (Hash)

    a customizable set of options

  • actual (Hash)

    a customizable set of options

  • target (Hash)

    a customizable set of options

  • request_run_time (Hash)

    a customizable set of options

  • normalization_run_time (Hash)

    a customizable set of options



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/loggers/qa_server/scenario_logger.rb', line 37

def add(status_info) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
  @test_count += 1
  @failure_count += 1 unless status_info[:status] == PASS
  @log << { type: status_info[:validation_type] || '',
            status: status_info[:status] || '',
            authority_name: status_info[:authority_name] || '',
            subauthority_name: status_info[:subauth] || '',
            service: status_info[:service] || '',
            action: status_info[:action] || '',
            url: status_info[:url] || '',
            expected: status_info[:expected] || nil,
            actual: status_info[:actual] || nil,
            target: status_info[:target] || nil,
            err_message: status_info[:error_message] || '',
            request_run_time: status_info[:request_run_time] || nil,
            normalization_run_time: status_info[:normalization_run_time] || nil }
end

#append(other) ⇒ Object

Append a log to this log.

Parameters:

  • the (ScenarioLog)

    log to append to this log



62
63
64
65
66
67
# File 'app/loggers/qa_server/scenario_logger.rb', line 62

def append(other)
  return unless other.present?
  @log += other.to_a
  @test_count += other.test_count
  @failure_count += other.failure_count
end

#delete_passingObject

Delete from the log any tests that passed.



56
57
58
# File 'app/loggers/qa_server/scenario_logger.rb', line 56

def delete_passing
  @log.delete_if { |entry| entry[:status] == PASS }
end

#filter(type: nil) ⇒ Object

Returns selected scenario test results data as an array limited to the specified type or all scenarios if type is nil.

Returns:

  • selected scenario test results data as an array limited to the specified type or all scenarios if type is nil



70
71
72
73
# File 'app/loggers/qa_server/scenario_logger.rb', line 70

def filter(type: nil)
  return @log if type.blank?
  @log.select { |entry| entry[:type] == type }
end

#sizeObject

Returns the number of scenarios recorded in the log.

Returns:

  • the number of scenarios recorded in the log



8
# File 'app/loggers/qa_server/scenario_logger.rb', line 8

delegate :size, :each, to: :@log

#to_aObject

Returns the scenario test results data as an array.

Returns:

  • the scenario test results data as an array



76
77
78
# File 'app/loggers/qa_server/scenario_logger.rb', line 76

def to_a
  @log
end