Permalink
Browse files

The first Release Candidate.

  • Loading branch information...
1 parent 1ac9fcf commit 5a32f56badced66fe650ac8e48d37529af3e7a16 @markbates committed Sep 30, 2010
View
@@ -32,9 +32,9 @@ After spending a morning playing with it, I was quickly able to grow the idea in
==Use
-CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3.rc1. First, add CoverMe to your Gemfile:
+CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3. First, add CoverMe to your Gemfile:
- gem 'cover_me', '>= 1.0.0.pre2', :require => false, :group => :test
+ gem 'cover_me', '>= 1.0.0.rc1', :group => :test
Now make sure to install the gem with Bundler:
View
@@ -32,10 +32,10 @@ h3. Detail Page
h2. Use
-CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3.rc1. First, add CoverMe to your Gemfile:
+CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3. First, add CoverMe to your Gemfile:
<pre><code>
- gem 'cover_me', '>= 1.0.0.pre2', :require => false, :group => :test
+ gem 'cover_me', '>= 1.0.0.rc1', :group => :test
</code></pre>
Now make sure to install the gem with Bundler:
View
@@ -19,12 +19,30 @@ Gemstub.test_framework = :rspec
Gemstub.gem_spec do |s|
s.summary = 'CoverMe - Code Coverage for Ruby 1.9'
s.description = s.summary
- s.version = '1.0.0.pre4'
+ s.version = '1.0.0.rc1'
s.rubyforge_project = 'magrathea'
s.add_dependency('configatron')
s.add_dependency('hashie')
s.email = 'mark+cover_me@markbates.com'
s.homepage = 'http://www.metabates.com'
+ s.required_ruby_version = '>= 1.9.2'
+ s.post_install_message = <<-EOF
+Thank you for installing CoverMe!
+
+USAGE:
+At the top of your 'test_helper.rb' or 'spec_helper.rb' place the following:
+
+require 'cover_me'
+
+!!! IT IS VERY IMPORTANT THAT THE REQUIRE STATEMENT BE THE VERY FIRST LINE OF THE FILE !!!
+
+RAILS 3:
+If you are planning on using this with a Rails 3 project please run the following:
+
+$ rails g cover_me:install
+
+This will install a Rake task to wrap your tests in CoverMe.
+EOF
end
Gemstub.rdoc do |rd|
View
@@ -2,17 +2,34 @@
Gem::Specification.new do |s|
s.name = %q{cover_me}
- s.version = "1.0.0.pre4.20100824134546"
+ s.version = "1.0.0.rc1.20100930114022"
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["markbates"]
- s.date = %q{2010-08-24}
+ s.date = %q{2010-09-30}
s.description = %q{CoverMe - Code Coverage for Ruby 1.9}
s.email = %q{mark+cover_me@markbates.com}
s.extra_rdoc_files = ["README", "LICENSE"]
- s.files = ["lib/cover_me/config.rb", "lib/cover_me/formatter.rb", "lib/cover_me/hash.rb", "lib/cover_me/html_formatter.rb", "lib/cover_me/index.rb", "lib/cover_me/processor.rb", "lib/cover_me/report.rb", "lib/cover_me/templates/index.css", "lib/cover_me/templates/index.html.erb", "lib/cover_me/templates/jquery.js", "lib/cover_me/templates/jquery.tablesorter.js", "lib/cover_me/templates/report.css", "lib/cover_me/templates/report.html.erb", "lib/cover_me.rb", "README", "LICENSE"]
+ s.files = ["lib/cover_me/config.rb", "lib/cover_me/formatter.rb", "lib/cover_me/hash.rb", "lib/cover_me/html_formatter.rb", "lib/cover_me/index.rb", "lib/cover_me/processor.rb", "lib/cover_me/report.rb", "lib/cover_me/results.rb", "lib/cover_me/templates/index.css", "lib/cover_me/templates/index.html.erb", "lib/cover_me/templates/jquery.js", "lib/cover_me/templates/jquery.tablesorter.js", "lib/cover_me/templates/report.css", "lib/cover_me/templates/report.html.erb", "lib/cover_me.rb", "lib/generators/cover_me/install/install_generator.rb", "lib/generators/cover_me/install/templates/cover_me.rake", "README", "LICENSE"]
s.homepage = %q{http://www.metabates.com}
+ s.post_install_message = %q{Thank you for installing CoverMe!
+
+USAGE:
+At the top of your 'test_helper.rb' or 'spec_helper.rb' place the following:
+
+require 'cover_me'
+
+!!! IT IS VERY IMPORTANT THAT THE REQUIRE STATEMENT BE THE VERY FIRST LINE OF THE FILE !!!
+
+RAILS 3:
+If you are planning on using this with a Rails 3 project please run the following:
+
+$ rails g cover_me:install
+
+This will install a Rake task to wrap your tests in CoverMe.
+}
s.require_paths = ["lib"]
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
s.rubyforge_project = %q{magrathea}
s.rubygems_version = %q{1.3.7}
s.summary = %q{CoverMe - Code Coverage for Ruby 1.9}
View
@@ -1,12 +1,29 @@
# http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/
-
require 'coverage'
require 'erb'
require 'fileutils'
require 'configatron'
require 'hashie'
module CoverMe
+
+ class << self
+
+ def complete!
+ data_file = CoverMe.config.results.store
+
+ if File.exists?(data_file)
+ data = CoverMe::Results.read_results(data_file)
+
+ CoverMe::Processor.new(data).process!
+ CoverMe.config.at_exit.call
+
+ File.delete(data_file)
+ end
+ end
+
+ end
+
end
path = File.join(File.dirname(__FILE__), 'cover_me')
@@ -16,16 +33,13 @@ module CoverMe
CoverMe.set_defaults
-%w{index report formatter processor html_formatter}.each do |file|
+%w{index report formatter processor html_formatter results}.each do |file|
require File.expand_path(File.join(path, file))
end
# Start the code coverage
-# if ENV['use_coverage']
- Coverage.start
+Coverage.start
- at_exit do
- CoverMe::Processor.new(Coverage.result).process!
- CoverMe.config.at_exit.call
- end
-# end
+at_exit do
+ CoverMe::Results.merge_results!(Coverage.result)
+end
@@ -20,9 +20,14 @@ def config(&block)
def set_defaults # :nodoc:
CoverMe.config do |c|
c.project.set_default(:root, Configatron::Delayed.new {Rails.root.to_s})
+ c.results.set_default(:store, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage.data')})
c.set_default(:file_pattern, Configatron::Delayed.new do
/(#{CoverMe.config.project.root}\/app\/.+\.rb|#{CoverMe.config.project.root}\/lib\/.+\.rb)/ix
end)
+
+ c.proximity.set_default(:near, 90)
+ c.proximity.set_default(:hit, 100)
+
c.set_default(:formatter, Configatron::Delayed.new {CoverMe::HtmlFormatter})
c.set_default(:at_exit, Proc.new {
if CoverMe.config.formatter == CoverMe::HtmlFormatter
@@ -21,11 +21,11 @@ def process!
if filename.match(self.options.pattern)
report = CoverMe::Report.new(filename, coverage)
self.index.reports << report
- self.options.formatter.format(report)
+ self.options[:formatter].format(report)
end
end
- self.options.formatter.format(self.index)
- self.options.formatter.finalize
+ self.options[:formatter].format(self.index)
+ self.options[:formatter].finalize
end
end
@@ -23,8 +23,8 @@ def initialize(filename, coverage = []) # :nodoc:
def proximity
unless @proximity
@proximity = 'miss'
- @proximity = 'near' if self.executed_percent >= 90
- @proximity = 'hit' if self.executed_percent >= 100
+ @proximity = 'near' if self.executed_percent >= CoverMe.config.proximity.near
+ @proximity = 'hit' if self.executed_percent >= CoverMe.config.proximity.hit
end
return @proximity
end
@@ -0,0 +1,44 @@
+module CoverMe
+ module Results
+
+ class << self
+
+ def read_results(path = CoverMe.config.results.store)
+ data = {}
+ if File.exists?(path)
+ data = eval(File.read(path)) || {}
+ end
+ return data
+ end
+
+ def merge_results!(cov_results, path = CoverMe.config.results.store)
+
+ data = CoverMe::Results.read_results(path)
+
+ cov_results.each do |file, results|
+ if data.has_key?(file)
+ results.each_with_index do |result, i|
+ summed_value = result # default
+ if result.nil?
+ summed_value = data[file][i]
+ elsif !data[file][i].nil?
+ summed_value = data[file][i] + result
+ end
+ data[file][i] = summed_value
+ end
+ else
+ data[file] = results
+ end
+ end
+
+ File.open(path, 'w') do |f|
+ f.write(data.inspect)
+ end
+
+ return data
+ end
+
+ end
+
+ end # Results
+end # CoverMe
@@ -0,0 +1,33 @@
+require 'rails/generators/base'
+
+puts 'cover me generator!!'
+
+# class LayoutGenerator < Rails::Generators::Base
+# def self.source_root
+# @_cover_me_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
+# end
+#
+# def generate_layout
+# copy_file "cover_me.rake", "lib/tasks/cover_me.rake"
+# end
+# end
+
+module CoverMe
+ class InstallGenerator < Rails::Generators::Base #:nodoc:
+
+ desc 'Installs a Rake task for the CoverMe gem.'
+
+ def self.source_root
+ @_cover_me_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
+ end
+
+ def self.banner
+ "rails generate cover_me:install"
+ end
+
+ def copy_files
+ template 'cover_me.rake', 'lib/tasks/cover_me.rake'
+ end
+
+ end
+end
@@ -0,0 +1,16 @@
+namespace :cover_me do
+
+ task :report do
+ require 'cover_me'
+ CoverMe.complete!
+ end
+
+end
+
+task :test do
+ Rake::Task['cover_me:report'].invoke
+end
+
+task :spec do
+ Rake::Task['cover_me:report'].invoke
+end
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe CoverMe::Results do
+
+ before(:each) do
+ @idontexist_path = File.join(CoverMe.config.project.root, 'idontexist.data')
+
+ res = {'file1' => [0, nil, 1],
+ 'file2' => [nil, 1, nil]}
+ File.open(CoverMe.config.results.store, 'w') do |f|
+ f.write(res.inspect)
+ end
+ end
+
+ after(:each) do
+ [CoverMe.config.results.store, @idontexist_path].each do |file|
+ File.delete(file) if File.exists?(file)
+ end
+ end
+
+ describe "read_results" do
+
+ it "should return results as a Hash from the file" do
+ res = CoverMe::Results.read_results
+ res.should be_kind_of(Hash)
+ res.should_not be_empty
+ end
+
+ it "should return empty results if there aren't any" do
+ res = CoverMe::Results.read_results(@idontexist_path)
+ res.should be_kind_of(Hash)
+ res.should be_empty
+ end
+
+ end
+
+ describe "merge_results!" do
+
+ before(:each) do
+ @more_results = {'file1' => [nil, 1, 1],
+ 'file2' => [nil, nil, 0]}
+ end
+
+ it "should merge the results and update the file" do
+ res = CoverMe::Results.merge_results!(@more_results)
+ res.should be_kind_of(Hash)
+ res.should == {'file1' => [0, 1, 2],
+ 'file2' => [nil, 1, 0]}
+ File.read(CoverMe.config.results.store).should == res.inspect
+ end
+
+ it "should merge the results and create a new file if there isn't one" do
+ res = CoverMe::Results.merge_results!(@more_results, @idontexist_path)
+ res.should be_kind_of(Hash)
+ res.should == @more_results
+ File.read(@idontexist_path).should == res.inspect
+ end
+
+ end
+
+end

0 comments on commit 5a32f56

Please sign in to comment.