Skip to content
Browse files

document and refactor

  • Loading branch information...
1 parent 24738d7 commit 9c9bf3e0eeef845b568df30ac7ecbbd523ac1c15 @lkdjiin committed Feb 26, 2011
View
3 TODO
@@ -14,3 +14,6 @@ Je voudrais qu'il ouvre le navigateur tout seul (que ce soit une option).
ok* option to exclude files from the coverage
ok* add colors to console output (*nix only)
+
+* readme: tested only with debian and rspec
+* doc task, yard
View
3 lib/coco/configuration.rb
@@ -15,6 +15,9 @@ module Coco
# in YAML format in the project root directory.
# @example to override the threeshold put this line in a '.coco' file:
# :threeshold: 70
+ #
+ # @note You can set the threeshold above 100% (to be sure to see all files) but you
+ # cannot set it under 0.
class Configuration < Hash
def initialize
View
8 lib/coco/cover/coverage_result.rb
@@ -4,13 +4,15 @@ module Coco
# Compute results of interest from the big results information (from Coverage.result)
class CoverageResult
+ # @return [Hash] Coverage for all the sources that live in the root project folder.
attr_reader :all_from_domain
+ # @return [Hash] Coverage for sources that are not sufficiently covered.
+ # More technically, the sources that live in the root project folder and for
+ # which the coverage percentage is under the threeshold.
attr_reader :covered_from_domain
# @param [Hash] config
- # @param [Hash] raw_results Must be the result from Coverage.result
- # @note You can set the threeshold above 100% (to be sure to see all files) but you
- # cannot set it under 0.
+ # @param [Hash] raw_results Results obtained from Coverage.result
def initialize config, raw_results
@exclude_files = config[:excludes]
@threeshold = config[:threeshold]
View
4 lib/coco/cover/coverage_stat.rb
@@ -5,7 +5,9 @@ module Coco
# Give statistics about an array of lines hit.
#
# An "array of lines hit" is an array of integers, possibly nil.
- # Each integer represents the state of a source line:
+ # Such array is obtain from Coverage.result.
+ #
+ # Each integer represent the state of a source line:
# * nil: source line will never be reached (like comments)
# * 0: source line could be reached, but was not
# * 1 and above: number of time the source line has been reached
View
2 lib/coco/formatter/colored_string.rb
@@ -3,6 +3,7 @@
module Coco
# Extend String with ANSI colorization.
+ # Do nothing on Windows.
class ColoredString < String
def initialize(str="")
@@ -26,6 +27,7 @@ def colorize color_code
"#{color_code}#{self}\033[0m"
end
end
+
end
end
View
5 lib/coco/formatter/console_formatter.rb
@@ -20,7 +20,7 @@ def initialize covered, uncovered
@formatted_output.sort!
@formatted_output.map! do |percentage, filename|
text = ColoredString.new "#{percentage}% #{filename}"
- if percentage <=50
+ if percentage <= 50
text.red
else
text.yellow
@@ -32,7 +32,8 @@ def initialize covered, uncovered
def compute_percentage
@raw_coverages.each do |filename, coverage|
- @formatted_output << [CoverageStat.coverage_percent(coverage), filename]
+ percentage = CoverageStat.coverage_percent(coverage)
+ @formatted_output << [percentage, filename]
end
end
View
2 lib/coco/formatter/formatter.rb
@@ -5,8 +5,10 @@ module Coco
# My childs will format coverages information.
# @abstract
class Formatter
+
# @param [Hash] raw_coverages The hash from Coverage.result
# @param [Array] uncovered List on uncovered files
+ # @todo I think covered is a better name than raw_coverages
def initialize raw_coverages, uncovered
@raw_coverages = raw_coverages
@uncovered = uncovered
View
1 lib/coco/formatter/html_formatter.rb
@@ -5,6 +5,7 @@
module Coco
# I format coverages information into html files.
+ # @todo document
class HtmlFormatter < Formatter
def initialize raw_coverages
View
1 lib/coco/formatter/html_index_formatter.rb
@@ -5,6 +5,7 @@
module Coco
# I format the index.html
+ # @todo document
class HtmlIndexFormatter < Formatter
def initialize raw_coverages, uncovered
View
2 lib/coco/formatter/template.rb
@@ -10,7 +10,7 @@ class Template
# @return [ERB]
def self.open filename
io = IO.readlines(filename, nil)
- return ERB.new(io[0], nil, '><')
+ ERB.new(io[0], nil, '><')
end
end
View
14 lib/coco/helpers.rb
@@ -2,17 +2,31 @@
module Coco
+ # @todo The app is full of <tt>Dir.pwd</tt>. This is the root project directory
+ # and must be in Configuration class (or Coco module ?).
module Helpers
+ # Get html filename (from a ruby filename) suitable for the coverage
+ # directory.
+ #
+ # @example
+ # ruby = '/home/user/my_project/lib/source.rb'
+ # html = Helpers.rb2html(ruby)
+ # => '_lib_source.rb.html'
+ #
+ # @param [String] name Ruby filename
+ # @return [String] Html filename
def Helpers.rb2html name
name.sub(Dir.pwd, '').tr('/\\', '_') + '.html'
end
+ # @return [String] The title of the index.html file
def Helpers.index_title
"COde COverage #{File.read(File.join($COCO_PATH, 'VERSION')).strip} for #{File.basename(Dir.pwd)}"
end
# @param [Array<String>] files List of filenames
+ # @return [Array<String>]
def Helpers.expand files
files.map {|file| File.expand_path file}
end
View
2 lib/coco/lister/source_lister.rb
@@ -18,7 +18,7 @@ def initialize config
@list = []
end
- # @return [Array<String>] A list of all .rb files from the directories given on instanciation.
+ # @return [Array<String>] A list of all .rb files from the directories found in configuration
def list
look_for_sources
@list.map! {|file| File.expand_path(file)}
View
3 lib/coco/lister/uncovered_lister.rb
@@ -2,7 +2,7 @@
module Coco
- # I retrieve the list of uncovered .rb files
+ # I retrieve the list of uncovered (0%) .rb files.
class UncoveredLister
# @param [Array<String>] sources List of filenames
@@ -12,6 +12,7 @@ def initialize sources, covered
@covered_files = Helpers.expand(covered.keys)
end
+ # @return [Array<String>] List of uncovered filenames
def list
list = []
@source_files.each do |elem|
View
3 lib/coco/writer/html_directory.rb
@@ -2,7 +2,7 @@
module Coco
- # I prepare the directory for html files.
+ # I prepare the coverage/ directory for html files.
class HtmlDirectory
attr_reader :coverage_dir
@@ -13,6 +13,7 @@ def initialize
@css_files = Dir.glob(css + '/*')
end
+ # Delete the coverage/ directory
def clean
FileUtils.remove_dir @coverage_dir if File.exist? @coverage_dir
end
View
2 lib/coco/writer/html_files_writer.rb
@@ -2,7 +2,7 @@
module Coco
- # I populate the html directory with files if any.
+ # I populate the coverage/ directory with files, if any.
class HtmlFilesWriter
# @param [Hash] html_files Key is filename, value is html content
View
4 lib/coco/writer/html_index_writer.rb
@@ -2,8 +2,9 @@
module Coco
- # I write the html index.
+ # I write the index.html
class HtmlIndexWriter
+
def initialize index
@index = index
@dir = HtmlDirectory.new.coverage_dir
@@ -14,6 +15,7 @@ def write
FileWriter.write File.join(@dir, 'index.html'), @index
end
end
+
end
end

0 comments on commit 9c9bf3e

Please sign in to comment.
Something went wrong with that request. Please try again.