Browse files

added an option single_line_report

  • Loading branch information...
1 parent 71edd02 commit 74544fe31b3aef6cd884b481dfaecca6eb907d33 @lkdjiin committed Oct 30, 2011
Showing with 99 additions and 56 deletions.
  1. +5 −7 NEWS
  2. +1 −1 VERSION
  3. +1 −1 lib/coco.rb
  4. +1 −0 lib/coco/configuration.rb
  5. +16 −2 lib/coco/formatter/console_formatter.rb
  6. +54 −39 spec/configuration_spec.rb
  7. +21 −6 spec/formatters_spec.rb
View
12 NEWS
@@ -1,3 +1,8 @@
+v0.6 (2011-10-30)
+
+ * Added an option 'single_line_report'
+
+
v0.5.1 (2011-08-08)
* Fix a bug where excluding a whole folder from the report does not worked
@@ -6,7 +11,6 @@ v0.5.1 (2011-08-08)
v0.5 (2011-03-14)
* can exclude a whole folder of ruby files from the report
-
* works with unit/test framework
@@ -26,20 +30,16 @@ v0.4.1 (2011-02-27)
v0.4 (2011-02-26)
* add colors to console output (*nix only)
-
* it can exclude unwanted files from the report
v0.3 (2011-02-25)
* Report sources not covered at all
-
* Configurable via a simple yaml file
+ threeshold
+ source directories
-
* UTF-8 compliant
-
* Misc
+ sort index.html and console output by percentage
+ display coco's version in index.html
@@ -48,7 +48,5 @@ v0.3 (2011-02-25)
v0.2 (2011-02-24)
* Use coco from rspec with a simple require 'coco'
-
* Display filenames covered < 90% on console
-
* Build simple html report only for files covered < 90%
View
2 VERSION
@@ -1 +1 @@
-0.5.1
+0.6
View
2 lib/coco.rb
@@ -23,7 +23,7 @@ module Coco
sources = Coco::SourceLister.new(config).list
uncovered = Coco::UncoveredLister.new(sources, result.all_from_domain).list
- puts Coco::ConsoleFormatter.new(covered, uncovered).format
+ puts Coco::ConsoleFormatter.new(covered, uncovered).format(config[:single_line_report])
html_files = Coco::HtmlFormatter.new(covered).format
Coco::HtmlFilesWriter.new(html_files).write
View
1 lib/coco/configuration.rb
@@ -24,6 +24,7 @@ def initialize
self[:threeshold] = 90
self[:directories] = ['lib']
self[:excludes] = []
+ self[:single_line_report] = false
if File.exist?('.coco')
conf = YAML.load_file '.coco'
self.merge!(conf)
View
18 lib/coco/formatter/console_formatter.rb
@@ -5,9 +5,15 @@ module Coco
# I format coverages information for console output
class ConsoleFormatter < Formatter
+ # @param [Boolean] single_line_report
+ #
# return [string] percent covered and associated filenames
- def format
- @formatted_output.join("\n")
+ def format single_line_report = false
+ if single_line_report
+ single_line_message
+ else
+ @formatted_output.join("\n")
+ end
end
# @param [Hash] covered
@@ -41,6 +47,14 @@ def add_percentage_to_uncovered
@uncovered.each do |filename| @formatted_output << [0, filename] end
end
+ def single_line_message
+ if @formatted_output.empty?
+ "All files covered"
+ else
+ ColoredString.new("Some files are uncovered").yellow
+ end
+ end
+
end
end
View
93 spec/configuration_spec.rb
@@ -6,52 +6,67 @@
describe Configuration do
before :each do
- FileUtils.rm '.coco', :force => true
+ FileUtils.rm '.coco', force: true
end
after :each do
- FileUtils.rm '.coco', :force => true
+ FileUtils.rm '.coco', force: true
end
- it "must give a default threeshold of 90%" do
- config = Configuration.new
- config[:threeshold].should == 90
+ context "with no config file" do
+ before :each do
+ @config = Configuration.new
+ end
+
+ it "should give a default threeshold of 90%" do
+ @config[:threeshold].should == 90
+ end
+
+ it "should give a default list of directories" do
+ @config[:directories].should == ['lib']
+ end
+
+ it "should give an empty default list of files to excludes" do
+ @config[:excludes].should == []
+ end
+
+ it "should give false for 'single_line_report'" do
+ @config[:single_line_report].should be_false
+ end
end
- it "must read the threeshold from .coco file" do
- create_config({:threeshold => 50})
- config = Configuration.new
- config[:threeshold].should == 50
- end
-
- it "must give a default list of directories" do
- config = Configuration.new
- config[:directories].should == ['lib']
- end
-
- it "must give an empty default list of files to excludes" do
- config = Configuration.new
- config[:excludes].should == []
- end
-
- it "must read the excludes files from .coco file" do
- create_config({:excludes => ['a', 'b']})
- config = Configuration.new
- config[:excludes].should == ['a', 'b']
- end
-
- it "must read the excludes whole dirs from .coco file" do
- create_config({:directories => ['spec/project'],
- :excludes => ['spec/project/3_rb_files', 'spec/project/4_rb_files']})
- config = Configuration.new
- config[:excludes].size.should == 7
- end
-
- it "must read the excludes whole dirs and files from .coco file" do
- create_config({:directories => ['spec/project'],
- :excludes => ['spec/project/3_rb_files', 'spec/project/six_lines.rb']})
- config = Configuration.new
- config[:excludes].size.should == 4
+ context "with a config file" do
+ it "should read the threeshold from .coco file" do
+ create_config threeshold: 50
+ config = Configuration.new
+ config[:threeshold].should == 50
+ end
+
+ it "should read the excludes files from .coco file" do
+ create_config({:excludes => ['a', 'b']})
+ config = Configuration.new
+ config[:excludes].should == ['a', 'b']
+ end
+
+ it "should read the excludes whole dirs from .coco file" do
+ create_config directories: ['spec/project'],
+ excludes: ['spec/project/3_rb_files', 'spec/project/4_rb_files']
+ config = Configuration.new
+ config[:excludes].size.should == 7
+ end
+
+ it "should read the excludes whole dirs and files from .coco file" do
+ create_config directories: ['spec/project'],
+ excludes: ['spec/project/3_rb_files', 'spec/project/six_lines.rb']
+ config = Configuration.new
+ config[:excludes].size.should == 4
+ end
+
+ it "should read 'single_line_report' value from .coco file" do
+ create_config single_line_report: true
+ config = Configuration.new
+ config[:single_line_report].should == true
+ end
end
end
View
27 spec/formatters_spec.rb
@@ -3,34 +3,33 @@
require './spec/helper'
describe ConsoleFormatter do
-
- it "must respond to format" do
+ it "should respond to format" do
formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'])
formatter.respond_to?(:format).should == true
end
- it "must return percents and filename" do
+ it "should return percents and filename" do
formatter = ConsoleFormatter.new(COVERAGE_80, [])
result = formatter.format
result.should == "\e[33m80% the/filename/80\e[0m"
end
- it "must return percents and filename and uncovered" do
+ it "should return percents and filename and uncovered" do
formatter = ConsoleFormatter.new(COVERAGE_80, ['a'])
result = formatter.format
result.should == "\e[31m0% a\e[0m\n" +
"\e[33m80% the/filename/80\e[0m"
end
- it "must sort by percentage" do
+ it "should sort by percentage" do
formatter = ConsoleFormatter.new(COVERAGE_100_90_80, [])
result = formatter.format
result.should == "\e[33m80% the/filename/80\e[0m\n" +
"\e[33m90% the/filename/90\e[0m\n" +
"\e[33m100% the/filename/100\e[0m"
end
- it "must sort by percentage uncovered too" do
+ it "should sort by percentage uncovered too" do
formatter = ConsoleFormatter.new(COVERAGE_100_90_80, ['a', 'b'])
result = formatter.format
result.should == "\e[31m0% a\e[0m\n" +
@@ -40,6 +39,22 @@
"\e[33m100% the/filename/100\e[0m"
end
+ context "when 'single_line_report' is true" do
+ context "and there is some uncovered files" do
+ it "should return a message" do
+ formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'])
+ result = formatter.format true
+ result.should == "\e[33mSome files are uncovered\e[0m"
+ end
+ end
+ context "and there is no uncovered files" do
+ it "should return nothing" do
+ formatter = ConsoleFormatter.new(COVERAGE_90, [])
+ result = formatter.format true
+ result.should be_empty
+ end
+ end
+ end
end
describe HtmlFormatter do

0 comments on commit 74544fe

Please sign in to comment.