class RSpecTracer::Cache

Attributes

all_examples[R]
all_files[R]
dependency[R]
failed_examples[R]
flaky_examples[R]
pending_examples[R]
run_id[R]

Public Class Methods

new() click to toggle source
# File lib/rspec_tracer/cache.rb, line 8
def initialize
  @run_id = last_run_id
  @cache_dir = File.join(RSpecTracer.cache_path, @run_id) if @run_id

  @cached = false

  @all_examples = {}
  @flaky_examples = Set.new
  @failed_examples = Set.new
  @pending_examples = Set.new
  @all_files = {}
  @dependency = Hash.new { |hash, key| hash[key] = Set.new }
end

Public Instance Methods

cached_examples_coverage() click to toggle source
# File lib/rspec_tracer/cache.rb, line 43
def cached_examples_coverage
  return @examples_coverage if defined?(@examples_coverage)
  return @examples_coverage = {} if @run_id.nil?

  starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  coverage = load_examples_coverage_cache
  ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  elpased = RSpecTracer::TimeFormatter.format_time(ending - starting)

  puts "RSpec tracer loaded cached examples coverage (took #{elpased})" if RSpecTracer.verbose?

  coverage
end
load_cache_for_run() click to toggle source
# File lib/rspec_tracer/cache.rb, line 22
def load_cache_for_run
  return if @run_id.nil? || @cached

  starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  load_all_examples_cache
  load_flaky_examples_cache
  load_failed_examples_cache
  load_pending_examples_cache
  load_all_files_cache
  load_dependency_cache

  ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  @cached = true

  elpased = RSpecTracer::TimeFormatter.format_time(ending - starting)

  puts "RSpec tracer loaded cache from #{@cache_dir} (took #{elpased})"
end

Private Instance Methods

last_run_id() click to toggle source
# File lib/rspec_tracer/cache.rb, line 59
def last_run_id
  file_name = File.join(RSpecTracer.cache_path, 'last_run.json')

  return unless File.file?(file_name)

  JSON.parse(File.read(file_name))['run_id']
end
load_all_examples_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 67
def load_all_examples_cache
  file_name = File.join(@cache_dir, 'all_examples.json')

  return unless File.file?(file_name)

  @all_examples = JSON.parse(File.read(file_name)).transform_values do |examples|
    examples.transform_keys(&:to_sym)
  end

  @all_examples.each_value do |example|
    example[:execution_result].transform_keys!(&:to_sym)

    example[:run_reason] = nil
  end
end
load_all_files_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 107
def load_all_files_cache
  file_name = File.join(@cache_dir, 'all_files.json')

  return unless File.file?(file_name)

  @all_files = JSON.parse(File.read(file_name)).transform_values do |files|
    files.transform_keys(&:to_sym)
  end
end
load_dependency_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 117
def load_dependency_cache
  file_name = File.join(@cache_dir, 'dependency.json')

  return unless File.file?(file_name)

  @dependency = JSON.parse(File.read(file_name)).transform_values(&:to_set)
end
load_examples_coverage_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 125
def load_examples_coverage_cache
  file_name = File.join(@cache_dir, 'examples_coverage.json')

  return unless File.file?(file_name)

  @examples_coverage = JSON.parse(File.read(file_name))
end
load_failed_examples_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 91
def load_failed_examples_cache
  file_name = File.join(@cache_dir, 'failed_examples.json')

  return unless File.file?(file_name)

  @failed_examples = JSON.parse(File.read(file_name)).to_set
end
load_flaky_examples_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 83
def load_flaky_examples_cache
  file_name = File.join(@cache_dir, 'flaky_examples.json')

  return unless File.file?(file_name)

  @flaky_examples = JSON.parse(File.read(file_name)).to_set
end
load_pending_examples_cache() click to toggle source
# File lib/rspec_tracer/cache.rb, line 99
def load_pending_examples_cache
  file_name = File.join(@cache_dir, 'pending_examples.json')

  return unless File.file?(file_name)

  @pending_examples = JSON.parse(File.read(file_name)).to_set
end