class TestDiff::ExecutionTimes

runs each spec and saves it to storage

Public Class Methods

new(directory = 'test_diff_coverage', filename = 'execution_times.txt') click to toggle source
# File lib/test_diff/execution_times.rb, line 8
def initialize(directory = 'test_diff_coverage', filename = 'execution_times.txt')
  @file_name = "#{directory}/#{filename}"
end

Public Instance Methods

[](file)
Alias for: get
add(main_spec_file, execution_time) click to toggle source
# File lib/test_diff/execution_times.rb, line 19
def add(main_spec_file, execution_time)
  File.open(@file_name, 'a+') do |file|
    file.write "#{main_spec_file}:#{execution_time}\n"
  end
  reset_times
end
clear() click to toggle source
# File lib/test_diff/execution_times.rb, line 12
def clear
  return unless file_exist?
  log_debug "Deleting #{@file_name}"
  File.delete(@file_name)
  reset_times
end
get(file) click to toggle source
# File lib/test_diff/execution_times.rb, line 26
def get(file)
  time = times[file]
  return nil if time.nil?
  time.to_i
end
Also aliased as: []

Private Instance Methods

file_exist?() click to toggle source
# File lib/test_diff/execution_times.rb, line 45
def file_exist?
  File.exist?(@file_name)
end
reset_times() click to toggle source
# File lib/test_diff/execution_times.rb, line 41
def reset_times
  @times = nil
end
times() click to toggle source
# File lib/test_diff/execution_times.rb, line 36
def times
  return {} unless file_exist?
  @times ||= Hash[File.readlines(@file_name).map(&:chomp).map { |line| line.split(':') }]
end