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



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



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.



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



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



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

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

#to_aObject



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

def to_a
  @log
end