Object
Representation of a source file including it’s coverage data, source code, source lines and featuring helpers to interpret that data.
Returns all covered lines as SimpleCov::SourceFile::Line
# File lib/simplecov/source_file.rb, line 126 def covered_lines @covered_lines ||= lines.select {|c| c.covered? } end
The coverage for this file in percent. 0 if the file has no relevant lines
# File lib/simplecov/source_file.rb, line 109 def covered_percent return 100.0 if lines.length == 0 or lines.length == never_lines.count (covered_lines.count) * 100 / (lines.count - never_lines.count - skipped_lines.count).to_f end
# File lib/simplecov/source_file.rb, line 114 def covered_strength return 0 if lines.length == 0 or lines.length == never_lines.count lines_strength = 0 lines.each do |c| lines_strength += c.coverage if c.coverage end effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f strength = lines_strength / effective_lines_count round_float(strength, 1) end
Access SimpleCov::SourceFile::Line source lines by line number
# File lib/simplecov/source_file.rb, line 104 def line(number) lines[number-1] end
Returns all source lines for this file as instances of SimpleCov::SourceFile::Line, and thus including coverage data. Aliased as :source_lines
# File lib/simplecov/source_file.rb, line 85 def lines return @lines unless @lines.nil? # Warning to identify condition from Issue #56 if coverage.size > src.size $stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]" end # Initialize lines @lines = [] src.each_with_index do |src, i| @lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i]) end process_skipped_lines! @lines end
Returns the number of relevant lines (covered + missed)
# File lib/simplecov/source_file.rb, line 148 def lines_of_code covered_lines.count + missed_lines.count end
Returns all lines that should have been, but were not covered as instances of SimpleCov::SourceFile::Line
# File lib/simplecov/source_file.rb, line 132 def missed_lines @missed_lines ||= lines.select {|c| c.missed? } end
Returns all lines that are not relevant for coverage as SimpleCov::SourceFile::Line instances
# File lib/simplecov/source_file.rb, line 138 def never_lines @never_lines ||= lines.select {|c| c.never? } end
Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks as skipped.
# File lib/simplecov/source_file.rb, line 154 def process_skipped_lines! skipping = false lines.each do |line| if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/ skipping = !skipping else line.skipped! if skipping end end end
Returns all lines that were skipped as SimpleCov::SourceFile::Line instances
# File lib/simplecov/source_file.rb, line 143 def skipped_lines @skipped_lines ||= lines.select {|c| c.skipped? } end
Generated with the Darkfish Rdoc Generator 2.