lib/common/tests_result.rb in liri-0.3.0 vs lib/common/tests_result.rb in liri-0.3.1
- old
+ new
@@ -6,16 +6,23 @@
module Liri
module Common
# Esta clase se encarga de guardar y procesar el archivo de resultados
class TestsResult
+ attr_reader :examples, :failures, :pending, :passed, :files_processed
+
def initialize(folder_path)
@folder_path = folder_path
- @example_quantity = 0
- @failure_quantity = 0
- @passed_quantity = 0
- @failures = ''
+ @examples = 0
+ @failures = 0
+ @pending = 0
+ @passed = 0
+ @finish_in = 0
+ @files_load = 0
+ @files_processed = 0
+ @failures_list = ''
+ @failed_examples = ''
end
def save(file_name, raw_tests_result)
file_path = File.join(@folder_path, '/', file_name)
File.write(file_path, raw_tests_result)
@@ -26,37 +33,45 @@
"batch_#{tests_batch_number}_agent_#{agent_ip_address}_tests_results"
end
# Procesa el resultado crudo de las pruebas unitarias y lo devuelve en formato hash manejable
# Ejemplo del hash retornado:
- # {example_quantity: 2, failure_quantity: 1}
- def process(tests_result_file_name)
+ # { examples: 0, failures: 0, pending: 0, passed: 0, finish_in: 0, files_load: 0,
+ # failures_list: '', failed_examples: '' }
+ def process(tests_result_file_name, files_processed)
file_path = File.join(@folder_path, '/', tests_result_file_name)
result_hash = process_tests_result_file(file_path)
+ result_hash[:files_processed] = files_processed
update_partial_result(result_hash)
- #print_partial_result(result_hash)
result_hash
end
def print_summary
- puts "\n#{@example_quantity} examples, #{@failure_quantity} failures\n"
+ puts "\n#{@examples} examples, #{@failures} failures, #{@pending} pending\n\n"
end
- def print_failures
- puts "\nFailures: " if !@failures.empty?
- puts @failures
+ def print_failures_list
+ puts "\nFailures: " unless @failures_list.empty?
+ puts @failures_list
end
+ def print_failed_examples
+ puts "\nFailed examples: " unless @failed_examples.empty?
+ puts @failed_examples
+ end
+
private
# Recibe el resultado crudo de las pruebas unitarias
# Procesa el archivo con los resultados crudos y lo devuelve en formato hash manejable
# Ejemplo del hash retornado:
- # {result: '.F', failures: '', example_quantity: 2, failure_quantity: 1, failed_examples: ''}
+ # {result: '.F', failures: '', examples: 2, failures: 1, failed_examples: ''}
def process_tests_result_file(file_path)
- result_hash = {failures: '', example_quantity: 0, failure_quantity: 0, passed_quantity: 0, failed_examples: ''}
+ result_hash = { examples: 0, failures: 0, pending: 0, passed: 0, finish_in: 0, files_load: 0,
+ failures_list: '', failed_examples: '' }
flag = ''
+ @failures_lists_count = @failures
File.foreach(file_path) do |line|
if flag == '' && line.strip.start_with?('Randomized')
flag = 'Randomized'
next
end
@@ -65,10 +80,13 @@
flag = 'Failures'
next
end
if ['Randomized', 'Failures', ''].include?(flag) && line.strip.start_with?('Finished')
+ values = finish_in_values(line)
+ result_hash[:finish_in] = values[:finish_in]
+ result_hash[:files_load] = values[:files_load]
flag = 'Finished'
next
end
if ['Finished', ''].include?(flag) && line.strip.start_with?('Failed')
@@ -76,40 +94,51 @@
next
end
case flag
when 'Failures'
- result_hash[:failures] << line
+ line = fix_failure_number(line)
+ result_hash[:failures_list] << line
when 'Finished'
- values = line.to_s.match(/([\d]+) example.?, ([\d]+) failure.?/)
- result_hash[:example_quantity] = values[1].to_i
- result_hash[:failure_quantity] = values[2].to_i
- result_hash[:passed_quantity] = result_hash[:example_quantity] - result_hash[:failure_quantity]
+ values = finished_summary_values(line)
+ result_hash[:examples] = values[:examples]
+ result_hash[:failures] = values[:failures]
+ result_hash[:passed] = result_hash[:examples] - result_hash[:failures]
+ result_hash[:pending] = values[:pending]
flag = ''
when 'Failed'
- result_hash[:failed_examples] << line
+ result_hash[:failed_examples] << line if line.strip.start_with?('rspec')
end
end
result_hash
end
def update_partial_result(hash_result)
- @example_quantity += hash_result[:example_quantity]
- @failure_quantity += hash_result[:failure_quantity]
- @passed_quantity += hash_result[:passed_quantity]
- @failures << hash_result[:failures]
+ @examples += hash_result[:examples]
+ @failures += hash_result[:failures]
+ @pending += hash_result[:pending]
+ @passed += hash_result[:passed]
+ @files_processed += hash_result[:files_processed]
+ @failures_list << hash_result[:failures_list]
+ @failed_examples << hash_result[:failed_examples]
end
- def print_partial_result(result_hash)
- result_hash[:passed_quantity].times do
- print '.'
- end
+ def finish_in_values(line)
+ UnitTest::RspecResultParser.finish_in_values(line)
+ end
- result_hash[:failure_quantity].times do
- print 'F'
- end
+ def finished_summary_values(line)
+ UnitTest::RspecResultParser.finished_summary_values(line)
end
+ def fix_failure_number(line)
+ line_number_regex = /(\d+\))/
+ if line.strip.start_with?(line_number_regex)
+ @failures_lists_count += 1
+ line.gsub!(line_number_regex, "#{@failures_lists_count})")
+ end
+ line
+ end
end
end
end