Class: FlakyStats::LogFile

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky_stats/logfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LogFile

Returns a new instance of LogFile.



8
9
10
11
# File 'lib/flaky_stats/logfile.rb', line 8

def initialize(options = {})
  @failing_log = options[:failing_log]
  @logfile = options[:logfile]
end

Instance Method Details

#get_error_info(line) ⇒ Object



13
14
15
16
17
18
# File 'lib/flaky_stats/logfile.rb', line 13

def get_error_info(line)
  information= line.partition(/\.\/.*.rb/)
  filename = information[1]
  lineno = information[2].partition(/:/)[2].to_i
  return {filename: filename, lineno: lineno}
end

#read_failing_logObject

Read the failing log from our test stack



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flaky_stats/logfile.rb', line 21

def read_failing_log()
  failed_files = []

  # Read in the file
  file = File.readlines(@failing_log)

  # Get lines which begin with rspec
  file.each do |line|
    if line =~ /rspec \.\//
      # Get the file name only
      failed_files << get_error_info(line)
    end
  end

  return failed_files
end

#write_flaky_stats(real_flaky_tests) ⇒ Object

Log flaky stats



39
40
41
42
43
# File 'lib/flaky_stats/logfile.rb', line 39

def write_flaky_stats(real_flaky_tests)
  File.open(@logfile, "a") do |log|
    real_flaky_tests.each {|data| log.puts data}
  end
end