Class: RSpec::CoverIt::ContextCoverage
- Inherits:
-
Object
- Object
- RSpec::CoverIt::ContextCoverage
- Defined in:
- lib/rspec/cover_it/context_coverage.rb
Instance Attribute Summary collapse
-
#postcontext_coverage ⇒ Object
Returns the value of attribute postcontext_coverage.
-
#precontext_coverage ⇒ Object
Returns the value of attribute precontext_coverage.
Instance Method Summary collapse
- #enforce!(default_threshold:) ⇒ Object
-
#initialize(context:, pretest_results:) ⇒ ContextCoverage
constructor
A new instance of ContextCoverage.
- #local_coverage ⇒ Object
- #local_coverage_rate ⇒ Object
Constructor Details
#initialize(context:, pretest_results:) ⇒ ContextCoverage
Returns a new instance of ContextCoverage.
4 5 6 7 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 4 def initialize(context:, pretest_results:) @context, @pretest_results = context, pretest_results @precontext_coverage = @postcontext_coverage = nil end |
Instance Attribute Details
#postcontext_coverage ⇒ Object
Returns the value of attribute postcontext_coverage.
9 10 11 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 9 def postcontext_coverage @postcontext_coverage end |
#precontext_coverage ⇒ Object
Returns the value of attribute precontext_coverage.
9 10 11 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 9 def precontext_coverage @precontext_coverage end |
Instance Method Details
#enforce!(default_threshold:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 25 def enforce!(default_threshold:) assert_ready! if precovered? fail_with_missing_code! elsif local_coverage_rate < (context.specific_threshold || default_threshold) fail_with_missing_coverage! end end |
#local_coverage ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 11 def local_coverage assert_ready! return nil unless precontext_coverage && postcontext_coverage && coverable_lines? @_local_coverage ||= pretest_coverage .zip(precontext_coverage, postcontext_coverage) .map { |a, b, c| line_calculation(a, b, c) } end |
#local_coverage_rate ⇒ Object
19 20 21 22 23 |
# File 'lib/rspec/cover_it/context_coverage.rb', line 19 def local_coverage_rate assert_ready! return nil unless covered_line_count covered_line_count.to_f / coverable_line_count.to_f end |