Class: Liri::Common::TestsResult

Inherits:
Object
  • Object
show all
Defined in:
lib/common/tests_result.rb

Overview

Esta clase se encarga de guardar y procesar el archivo de resultados

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_path) ⇒ TestsResult

Returns a new instance of TestsResult.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/common/tests_result.rb', line 13

def initialize(folder_path)
  @folder_path = folder_path
  @examples = 0
  @failures = 0
  @pending = 0
  @passed = 0
  @finish_in = 0
  @files_load = 0
  @failures_list = ''
  @failed_examples = ''
  @failed_files = ''
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



11
12
13
# File 'lib/common/tests_result.rb', line 11

def examples
  @examples
end

#failuresObject (readonly)

Returns the value of attribute failures.



11
12
13
# File 'lib/common/tests_result.rb', line 11

def failures
  @failures
end

#passedObject (readonly)

Returns the value of attribute passed.



11
12
13
# File 'lib/common/tests_result.rb', line 11

def passed
  @passed
end

#pendingObject (readonly)

Returns the value of attribute pending.



11
12
13
# File 'lib/common/tests_result.rb', line 11

def pending
  @pending
end

Instance Method Details

#build_file_name(agent_ip_address, batch_num) ⇒ Object



32
33
34
# File 'lib/common/tests_result.rb', line 32

def build_file_name(agent_ip_address, batch_num)
  "batch_#{batch_num}_agent_#{agent_ip_address}_tests_results"
end


54
55
56
57
# File 'lib/common/tests_result.rb', line 54

def print_detailed_failures
  Liri.logger.info("\nFailures: ", true) unless @failures_list.empty?
  Liri.logger.info(@failures_list, true)
end


50
51
52
# File 'lib/common/tests_result.rb', line 50

def print_summary
  Liri.logger.info("\n#{@examples} examples, #{@passed} passed, #{@failures} failures\n", true)
end


59
60
61
62
# File 'lib/common/tests_result.rb', line 59

def print_summary_failures
  Liri.logger.info("\nFailed examples: ", true) unless @failed_examples.empty?
  Liri.logger.info(@failed_examples, true)
end

#process(tests_result_file_name) ⇒ Object

Procesa el resultado crudo de las pruebas unitarias y lo devuelve en formato hash manejable Ejemplo del hash retornado: { examples: 0, failures: 0, pending: 0, passed: 0, finish_in: 0, files_load: 0,

failures_list: '', failed_examples: '' }


40
41
42
43
44
45
46
47
48
# File 'lib/common/tests_result.rb', line 40

def process(tests_result_file_name)
  file_path = File.join(@folder_path, '/', tests_result_file_name)
  # A veces no se encuentra el archivo de resultados, la siguiente condicional es para evitar errores relativos a esto
  return {} unless File.exist?(file_path)

  result_hash = process_tests_result_file(file_path)
  update_partial_result(result_hash)
  result_hash
end

#save(file_name, raw_tests_result) ⇒ Object



26
27
28
29
30
# File 'lib/common/tests_result.rb', line 26

def save(file_name, raw_tests_result)
  file_path = File.join(@folder_path, '/', file_name)
  File.write(file_path, raw_tests_result)
  file_path
end