Skip to content

Instantly share code, notes, and snippets.

@jinjagit
Last active August 16, 2021 07:14
Show Gist options
  • Save jinjagit/0e35277b3dada484b2a42dad37e04a9c to your computer and use it in GitHub Desktop.
Save jinjagit/0e35277b3dada484b2a42dad37e04a9c to your computer and use it in GitHub Desktop.
# Print summary of test failures and write to file.
# Intended to work with log files generated by log_rand_specs.zsh
# https://gist.github.com/jinjagit/1607b817df5dbaa5d443ea1a9a60938c
errors = {}
read_failures = false
n = 0
def record_errors(line, errors)
unless line.include?("Failed examples:") || line.include?("Randomized with seed") || line.chomp.empty?
if errors.key?(line)
count = errors[line]
errors[line] = count + 1
else
errors[line] = 1
end
end
end
Dir.glob("*.txt") {|filename|
if filename.include?("specs_log")
n += 1
File.readlines(filename).each do |line|
read_failures = true if line.include?("Failed example")
record_errors(line, errors) if read_failures == true
read_failures = false if line.include?("Randomized with seed")
end
end
}
puts "From #{n} * docker-compose run --rm web rspec --order rand,\n"
puts "the following test failures occurred:\n\n"
errors.sort_by {|_k, v| -v}.to_h.each do |k, v|
puts "#{v}* #{k}"
end
datetime = Time.now.strftime('%d-%m-%y_%H-%M-%S')
File.open("spec_failures_report_#{datetime}.txt", "w") { |f|
f << "From #{n} * docker-compose run --rm web rspec --order rand,\n"
f << "the following test failures occurred:\n\n"
errors.sort_by {|_k, v| -v}.to_h.each do |k, v|
f << "#{v}* #{k}"
end
}
puts "\nWritten to file 'spec_failures_report_#{datetime}.txt'"
@jinjagit
Copy link
Author

jinjagit commented Aug 14, 2021

The script used to generate the log files that this script summarises is log_rand_specs.zsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment