Class: RSpec::CoverIt::CoverageState

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/cover_it/coverage_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter: nil, autoenforce: false, default_threshold: 100.0) ⇒ CoverageState

Returns a new instance of CoverageState.



7
8
9
10
11
# File 'lib/rspec/cover_it/coverage_state.rb', line 7

def initialize(filter: nil, autoenforce: false, default_threshold: 100.0)
  @filter, @autoenforce, @default_threshold = filter, autoenforce, default_threshold
  @pretest_results = nil
  @context_coverages = {}
end

Instance Attribute Details

#context_coveragesObject (readonly)

Returns the value of attribute context_coverages.



5
6
7
# File 'lib/rspec/cover_it/coverage_state.rb', line 5

def context_coverages
  @context_coverages
end

#filterObject (readonly)

Returns the value of attribute filter.



5
6
7
# File 'lib/rspec/cover_it/coverage_state.rb', line 5

def filter
  @filter
end

#pretest_resultsObject

Returns the value of attribute pretest_results.



4
5
6
# File 'lib/rspec/cover_it/coverage_state.rb', line 4

def pretest_results
  @pretest_results
end

Instance Method Details

#finish_load_trackingObject



19
20
21
# File 'lib/rspec/cover_it/coverage_state.rb', line 19

def finish_load_tracking
  @pretest_results = PretestCoverage.new(filter: filter, results: get_current_coverage)
end

#finish_tracking_for(scope, rspec_context) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rspec/cover_it/coverage_state.rb', line 32

def finish_tracking_for(scope, rspec_context)
  context = context_for(scope, rspec_context)
  return unless context.cover_it?

  context_coverage = @context_coverages.fetch(context.target_class)
  context_coverage.postcontext_coverage = get_current_coverage(context.target_path)
  context_coverage.enforce!(default_threshold: default_threshold_rate)
end

#start_trackingObject

If SimpleCov or something like it is already running, Coverage may be started already. For our purposes, that should be fine.



15
16
17
# File 'lib/rspec/cover_it/coverage_state.rb', line 15

def start_tracking
  Coverage.start unless Coverage.running?
end

#start_tracking_for(scope, rspec_context) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rspec/cover_it/coverage_state.rb', line 23

def start_tracking_for(scope, rspec_context)
  context = context_for(scope, rspec_context)
  return unless context.cover_it?

  context_coverage = ContextCoverage.new(context: context, pretest_results: pretest_results)
  context_coverage.precontext_coverage = get_current_coverage(context.target_path)
  @context_coverages[context.target_class] = context_coverage
end