Class: RSpecTracer::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_tracer/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec_tracer/cache.rb', line 9

def initialize
  @cached = false

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

Instance Attribute Details

#all_examplesObject (readonly)

Returns the value of attribute all_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def all_examples
  @all_examples
end

#all_filesObject (readonly)

Returns the value of attribute all_files.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def all_files
  @all_files
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def dependency
  @dependency
end

#duplicate_examplesObject (readonly)

Returns the value of attribute duplicate_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def duplicate_examples
  @duplicate_examples
end

#examples_coverageObject (readonly)

Returns the value of attribute examples_coverage.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def examples_coverage
  @examples_coverage
end

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def failed_examples
  @failed_examples
end

#flaky_examplesObject (readonly)

Returns the value of attribute flaky_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def flaky_examples
  @flaky_examples
end

#interrupted_examplesObject (readonly)

Returns the value of attribute interrupted_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def interrupted_examples
  @interrupted_examples
end

#pending_examplesObject (readonly)

Returns the value of attribute pending_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def pending_examples
  @pending_examples
end

#run_idObject (readonly)

Returns the value of attribute run_id.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def run_id
  @run_id
end

#skipped_examplesObject (readonly)

Returns the value of attribute skipped_examples.



5
6
7
# File 'lib/rspec_tracer/cache.rb', line 5

def skipped_examples
  @skipped_examples
end

Instance Method Details

#cached_examples_coverageObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rspec_tracer/cache.rb', line 52

def cached_examples_coverage
  return @examples_coverage if defined?(@examples_coverage)

  cache_path = RSpecTracer.cache_path
  cache_path = File.dirname(cache_path) if RSpecTracer.parallel_tests?
  run_id = last_run_id(cache_path)

  return @examples_coverage = {} if run_id.nil?

  starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  cache_dir = File.join(cache_path, run_id)
  coverage = load_examples_coverage_cache(cache_dir)
  ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  elapsed = RSpecTracer::TimeFormatter.format_time(ending - starting)

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

  coverage
end

#load_cache_for_runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec_tracer/cache.rb', line 22

def load_cache_for_run
  return if @cached

  cache_path = RSpecTracer.cache_path
  cache_path = File.dirname(cache_path) if RSpecTracer.parallel_tests?
  run_id = last_run_id(cache_path)

  return if run_id.nil?

  starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  cache_dir = File.join(cache_path, run_id)

  load_all_examples_cache(cache_dir)
  load_duplicate_examples_cache(cache_dir)
  load_interrupted_examples_cache(cache_dir)
  load_flaky_examples_cache(cache_dir)
  load_failed_examples_cache(cache_dir)
  load_pending_examples_cache(cache_dir)
  load_all_files_cache(cache_dir)
  load_dependency_cache(cache_dir)

  ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  @cached = true

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

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