class FlakyStats::FlakyTests

Public Class Methods

new(options = {}) click to toggle source
# File lib/flaky_stats/flaky_tests.rb, line 7
def initialize(options = {})
  @logfile = options[:logfile]
end

Public Instance Methods

form_data(failed_file = {}) click to toggle source
# File lib/flaky_stats/flaky_tests.rb, line 11
def form_data(failed_file = {})
  return [Time.now,failed_file[:filename],failed_file[:lineno],1].join ","
end
run(failed_files = []) click to toggle source

Run each failing test singularly and return a list of flaky tests.

# File lib/flaky_stats/flaky_tests.rb, line 16
def run(failed_files = [])
  real_flaky_tests = []

  if ENV['NO_FLAKY'] == "true"
    heading("Skipping flaky tests")
  else
    heading("Rerunning failing tests in single thread!")

    sleep 2
    system("sync")
    
    # Run all failing tests separately with '--format doc' on the end.
    failed_files.each do |failed_file|
      status = system("rspec --format doc #{failed_file[:filename]}")

      # This is a flaky test only, so record it
      real_flaky_tests << form_data(failed_file) if status == true
    end
  end

  return real_flaky_tests
end