Class: QaServer::ScenarioLogger
- Inherits:
-
Object
- Object
- QaServer::ScenarioLogger
- 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
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#test_count ⇒ Object
readonly
Returns the value of attribute test_count.
Instance Method Summary collapse
-
#add(status_info) ⇒ Object
Add a scenario to the log.
-
#append(other) ⇒ Object
Append a log to this log.
-
#delete_passing ⇒ Object
Delete from the log any tests that passed.
-
#filter(type: nil, group: false) ⇒ Object
Selected scenario test results data as an array limited to the specified type or all scenarios if type is nil.
- #group_data(log) ⇒ Object
-
#initialize(test_count = 0, failure_count = 0) ⇒ ScenarioLogger
constructor
A new instance of ScenarioLogger.
-
#size ⇒ Object
The number of scenarios recorded in the log.
-
#to_a ⇒ Object
The scenario test results data as an array.
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_count ⇒ Object (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_count ⇒ Object (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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 38 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] || '', request_data: status_info[:request_data] || '', 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, pending: status_info[:pending] || false } end |
#append(other) ⇒ Object
Append a log to this log.
65 66 67 68 69 70 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 65 def append(other) return if other.blank? @log += other.to_a @test_count += other.test_count @failure_count += other.failure_count end |
#delete_passing ⇒ Object
Delete from the log any tests that passed.
59 60 61 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 59 def delete_passing @log.delete_if { |entry| entry[:status] == PASS } end |
#filter(type: nil, group: false) ⇒ Object
Returns selected scenario test results data as an array limited to the specified type or all scenarios if type is nil.
128 129 130 131 132 133 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 128 def filter(type: nil, group: false) return group_data(@log) if group && type.blank? return @log if type.blank? filtered_log = @log.select { |entry| entry[:type] == type } group ? group_data(filtered_log) : filtered_log end |
#group_data(log) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 135 def group_data(log) grouped_data = {} log.each do |datum| auth_name = datum[:authority_name] grouped_data[auth_name] = [] unless grouped_data.key? auth_name grouped_data[auth_name] << datum end grouped_data end |
#size ⇒ Object
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_a ⇒ Object
Returns the scenario test results data as an array.
146 147 148 |
# File 'app/loggers/qa_server/scenario_logger.rb', line 146 def to_a @log end |