cover_me 1.0.0.pre4 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -32,9 +32,9 @@ After spending a morning playing with it, I was quickly able to grow the idea in
32
32
 
33
33
  ==Use
34
34
 
35
- 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:
35
+ CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3. First, add CoverMe to your Gemfile:
36
36
 
37
- gem 'cover_me', '>= 1.0.0.pre2', :require => false, :group => :test
37
+ gem 'cover_me', '>= 1.0.0.rc1', :group => :test
38
38
 
39
39
  Now make sure to install the gem with Bundler:
40
40
 
data/lib/cover_me.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/
2
-
3
2
  require 'coverage'
4
3
  require 'erb'
5
4
  require 'fileutils'
@@ -7,6 +6,24 @@ require 'configatron'
7
6
  require 'hashie'
8
7
 
9
8
  module CoverMe
9
+
10
+ class << self
11
+
12
+ def complete!
13
+ data_file = CoverMe.config.results.store
14
+
15
+ if File.exists?(data_file)
16
+ data = CoverMe::Results.read_results(data_file)
17
+
18
+ CoverMe::Processor.new(data).process!
19
+ CoverMe.config.at_exit.call
20
+
21
+ File.delete(data_file)
22
+ end
23
+ end
24
+
25
+ end
26
+
10
27
  end
11
28
 
12
29
  path = File.join(File.dirname(__FILE__), 'cover_me')
@@ -16,16 +33,13 @@ require File.expand_path(File.join(path, 'config'))
16
33
 
17
34
  CoverMe.set_defaults
18
35
 
19
- %w{index report formatter processor html_formatter}.each do |file|
36
+ %w{index report formatter processor html_formatter results}.each do |file|
20
37
  require File.expand_path(File.join(path, file))
21
38
  end
22
39
 
23
40
  # Start the code coverage
24
- # if ENV['use_coverage']
25
- Coverage.start
41
+ Coverage.start
26
42
 
27
- at_exit do
28
- CoverMe::Processor.new(Coverage.result).process!
29
- CoverMe.config.at_exit.call
30
- end
31
- # end
43
+ at_exit do
44
+ CoverMe::Results.merge_results!(Coverage.result)
45
+ end
@@ -20,9 +20,14 @@ module CoverMe
20
20
  def set_defaults # :nodoc:
21
21
  CoverMe.config do |c|
22
22
  c.project.set_default(:root, Configatron::Delayed.new {Rails.root.to_s})
23
+ c.results.set_default(:store, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage.data')})
23
24
  c.set_default(:file_pattern, Configatron::Delayed.new do
24
25
  /(#{CoverMe.config.project.root}\/app\/.+\.rb|#{CoverMe.config.project.root}\/lib\/.+\.rb)/ix
25
26
  end)
27
+
28
+ c.proximity.set_default(:near, 90)
29
+ c.proximity.set_default(:hit, 100)
30
+
26
31
  c.set_default(:formatter, Configatron::Delayed.new {CoverMe::HtmlFormatter})
27
32
  c.set_default(:at_exit, Proc.new {
28
33
  if CoverMe.config.formatter == CoverMe::HtmlFormatter
@@ -21,11 +21,11 @@ class CoverMe::Processor
21
21
  if filename.match(self.options.pattern)
22
22
  report = CoverMe::Report.new(filename, coverage)
23
23
  self.index.reports << report
24
- self.options.formatter.format(report)
24
+ self.options[:formatter].format(report)
25
25
  end
26
26
  end
27
- self.options.formatter.format(self.index)
28
- self.options.formatter.finalize
27
+ self.options[:formatter].format(self.index)
28
+ self.options[:formatter].finalize
29
29
  end
30
30
 
31
31
  end
@@ -23,8 +23,8 @@ class CoverMe::Report
23
23
  def proximity
24
24
  unless @proximity
25
25
  @proximity = 'miss'
26
- @proximity = 'near' if self.executed_percent >= 90
27
- @proximity = 'hit' if self.executed_percent >= 100
26
+ @proximity = 'near' if self.executed_percent >= CoverMe.config.proximity.near
27
+ @proximity = 'hit' if self.executed_percent >= CoverMe.config.proximity.hit
28
28
  end
29
29
  return @proximity
30
30
  end
@@ -0,0 +1,44 @@
1
+ module CoverMe
2
+ module Results
3
+
4
+ class << self
5
+
6
+ def read_results(path = CoverMe.config.results.store)
7
+ data = {}
8
+ if File.exists?(path)
9
+ data = eval(File.read(path)) || {}
10
+ end
11
+ return data
12
+ end
13
+
14
+ def merge_results!(cov_results, path = CoverMe.config.results.store)
15
+
16
+ data = CoverMe::Results.read_results(path)
17
+
18
+ cov_results.each do |file, results|
19
+ if data.has_key?(file)
20
+ results.each_with_index do |result, i|
21
+ summed_value = result # default
22
+ if result.nil?
23
+ summed_value = data[file][i]
24
+ elsif !data[file][i].nil?
25
+ summed_value = data[file][i] + result
26
+ end
27
+ data[file][i] = summed_value
28
+ end
29
+ else
30
+ data[file] = results
31
+ end
32
+ end
33
+
34
+ File.open(path, 'w') do |f|
35
+ f.write(data.inspect)
36
+ end
37
+
38
+ return data
39
+ end
40
+
41
+ end
42
+
43
+ end # Results
44
+ end # CoverMe
@@ -0,0 +1,33 @@
1
+ require 'rails/generators/base'
2
+
3
+ puts 'cover me generator!!'
4
+
5
+ # class LayoutGenerator < Rails::Generators::Base
6
+ # def self.source_root
7
+ # @_cover_me_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
8
+ # end
9
+ #
10
+ # def generate_layout
11
+ # copy_file "cover_me.rake", "lib/tasks/cover_me.rake"
12
+ # end
13
+ # end
14
+
15
+ module CoverMe
16
+ class InstallGenerator < Rails::Generators::Base #:nodoc:
17
+
18
+ desc 'Installs a Rake task for the CoverMe gem.'
19
+
20
+ def self.source_root
21
+ @_cover_me_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
22
+ end
23
+
24
+ def self.banner
25
+ "rails generate cover_me:install"
26
+ end
27
+
28
+ def copy_files
29
+ template 'cover_me.rake', 'lib/tasks/cover_me.rake'
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ namespace :cover_me do
2
+
3
+ task :report do
4
+ require 'cover_me'
5
+ CoverMe.complete!
6
+ end
7
+
8
+ end
9
+
10
+ task :test do
11
+ Rake::Task['cover_me:report'].invoke
12
+ end
13
+
14
+ task :spec do
15
+ Rake::Task['cover_me:report'].invoke
16
+ end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - pre4
10
- version: 1.0.0.pre4
9
+ - rc1
10
+ version: 1.0.0.rc1
11
11
  platform: ruby
12
12
  authors:
13
13
  - markbates
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 -04:00
18
+ date: 2010-09-30 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ files:
61
61
  - lib/cover_me/index.rb
62
62
  - lib/cover_me/processor.rb
63
63
  - lib/cover_me/report.rb
64
+ - lib/cover_me/results.rb
64
65
  - lib/cover_me/templates/index.css
65
66
  - lib/cover_me/templates/index.html.erb
66
67
  - lib/cover_me/templates/jquery.js
@@ -68,13 +69,31 @@ files:
68
69
  - lib/cover_me/templates/report.css
69
70
  - lib/cover_me/templates/report.html.erb
70
71
  - lib/cover_me.rb
72
+ - lib/generators/cover_me/install/install_generator.rb
73
+ - lib/generators/cover_me/install/templates/cover_me.rake
71
74
  - README
72
75
  - LICENSE
73
76
  has_rdoc: true
74
77
  homepage: http://www.metabates.com
75
78
  licenses: []
76
79
 
77
- post_install_message:
80
+ post_install_message: |
81
+ Thank you for installing CoverMe!
82
+
83
+ USAGE:
84
+ At the top of your 'test_helper.rb' or 'spec_helper.rb' place the following:
85
+
86
+ require 'cover_me'
87
+
88
+ !!! IT IS VERY IMPORTANT THAT THE REQUIRE STATEMENT BE THE VERY FIRST LINE OF THE FILE !!!
89
+
90
+ RAILS 3:
91
+ If you are planning on using this with a Rails 3 project please run the following:
92
+
93
+ $ rails g cover_me:install
94
+
95
+ This will install a Rake task to wrap your tests in CoverMe.
96
+
78
97
  rdoc_options: []
79
98
 
80
99
  require_paths:
@@ -84,10 +103,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
103
  requirements:
85
104
  - - ">="
86
105
  - !ruby/object:Gem::Version
87
- hash: -280141288175222533
88
106
  segments:
89
- - 0
90
- version: "0"
107
+ - 1
108
+ - 9
109
+ - 2
110
+ version: 1.9.2
91
111
  required_rubygems_version: !ruby/object:Gem::Requirement
92
112
  none: false
93
113
  requirements: