cover_me 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -34,7 +34,7 @@ After spending a morning playing with it, I was quickly able to grow the idea in
34
34
 
35
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.rc1', :group => :test
37
+ gem 'cover_me', '>= 1.0.0.rc2', :group => :test
38
38
 
39
39
  Now make sure to install the gem with Bundler:
40
40
 
@@ -71,3 +71,10 @@ CoverMe is easily configurable, under the covers it uses the "Configatron":http:
71
71
  } (default)
72
72
  end
73
73
 
74
+ ==Contributors
75
+
76
+ * Mark Bates
77
+ * Alex Crichton
78
+ * Andrea Campi
79
+ * Rob Zolkos
80
+ * jmthomas
data/lib/cover_me.rb CHANGED
@@ -33,7 +33,7 @@ require File.expand_path(File.join(path, 'config'))
33
33
 
34
34
  CoverMe.set_defaults
35
35
 
36
- %w{index report formatter processor html_formatter results}.each do |file|
36
+ %w{index report formatter processor html_formatter emma_formatter results directory_report global_report}.each do |file|
37
37
  require File.expand_path(File.join(path, file))
38
38
  end
39
39
 
@@ -19,7 +19,8 @@ module CoverMe
19
19
 
20
20
  def set_defaults # :nodoc:
21
21
  CoverMe.config do |c|
22
- c.project.set_default(:root, Configatron::Delayed.new {Rails.root.to_s})
22
+ c.project.set_default(:root,
23
+ Configatron::Delayed.new{defined?(Rails) ? Rails.root.to_s : Dir.pwd})
23
24
  c.results.set_default(:store, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage.data')})
24
25
  c.set_default(:file_pattern, Configatron::Delayed.new do
25
26
  /(#{CoverMe.config.project.root}\/app\/.+\.rb|#{CoverMe.config.project.root}\/lib\/.+\.rb)/ix
@@ -40,6 +41,7 @@ module CoverMe
40
41
  c.html_formatter.set_default(:output_path, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage')})
41
42
  c.html_formatter.set_default(:finalizer_files, {'report.css' => 'report.css', 'index.css' => 'index.css',
42
43
  'jquery.js' => 'jquery.js', 'jquery.tablesorter.js' => 'jquery.tablesorter.js'})
44
+ c.emma_formatter.set_default(:output_path, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage')})
43
45
  end
44
46
  end
45
47
 
@@ -0,0 +1,35 @@
1
+ # Used to represent the directory summary.
2
+ class CoverMe::DirectoryReport
3
+ attr_accessor :name
4
+ attr_accessor :reports
5
+ attr_accessor :lines_of_code
6
+ attr_accessor :lines_executed
7
+
8
+ def initialize(name, reports) # :nodoc:
9
+ self.name = name
10
+ self.reports = reports
11
+ self.lines_of_code = 0
12
+ self.lines_executed = 0
13
+ reports.each do |report|
14
+ self.lines_of_code += report.lines_of_code
15
+ self.lines_executed += report.lines_executed
16
+ end
17
+ end
18
+
19
+ class << self
20
+ def summarize(reports)
21
+ reports_by_dir = reports.group_by do |report|
22
+ dir_for_file(report.filename)
23
+ end
24
+
25
+ reports_by_dir.map do |dir,reports|
26
+ self.new(dir, reports)
27
+ end
28
+ end
29
+
30
+ private
31
+ def dir_for_file(filename)
32
+ File.dirname(filename).split(File::SEPARATOR).join('.')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ # Generates Emma-style xml coverage files.
2
+ class CoverMe::EmmaFormatter < CoverMe::Formatter
3
+
4
+ def initialize(options = {}) # :nodoc:
5
+ super
6
+ self.options = ({:output_path => CoverMe.config.emma_formatter.output_path}.merge(self.options)).to_mash
7
+ end
8
+
9
+ def format_report(report)
10
+ # nothing to do
11
+ end
12
+
13
+ # Formats a CoverMe::Index object using the _emma.xml.erb_ template
14
+ def format_index(index)
15
+ reports_by_dir = CoverMe::DirectoryReport.summarize(index.reports)
16
+ global = CoverMe::GlobalReport.new(reports_by_dir)
17
+ write_file('coverage') do |file|
18
+ file.write(self.template('emma.xml.erb').result(binding))
19
+ end
20
+ end
21
+
22
+ protected
23
+ def write_file(filename, extension = '.xml', &block) # :nodoc:
24
+ path = File.join(self.options.output_path, filename)
25
+ FileUtils.mkdir_p(File.dirname(path))
26
+ File.open(path + extension, 'w', &block)
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # Used to represent the module summary.
2
+ class CoverMe::GlobalReport
3
+ attr_accessor :lines_of_code
4
+ attr_accessor :lines_executed
5
+
6
+ def initialize(reports) # :nodoc:
7
+ self.lines_of_code = 0
8
+ self.lines_executed = 0
9
+ reports.each do |report|
10
+ self.lines_of_code += report.lines_of_code
11
+ self.lines_executed += report.lines_executed
12
+ end
13
+ end
14
+ end
@@ -5,6 +5,7 @@ class CoverMe::Report
5
5
  attr_accessor :coverage
6
6
  attr_accessor :lines
7
7
  attr_accessor :lines_of_code
8
+ attr_accessor :lines_executed
8
9
  attr_accessor :executed_percent
9
10
  attr_accessor :unexecuted_percent
10
11
 
@@ -14,7 +15,8 @@ class CoverMe::Report
14
15
  self.coverage = coverage
15
16
  self.lines = self.coverage.size
16
17
  self.lines_of_code = self.coverage.reject{|x| x.nil?}.size
17
- self.executed_percent = ((self.coverage.reject{|x| x.nil? || x < 1}.size.to_f / self.lines_of_code.to_f) * 100).round(1)
18
+ self.lines_executed = self.coverage.reject{|x| x.nil? || x < 1}.size
19
+ self.executed_percent = ((self.lines_executed.to_f / self.lines_of_code.to_f) * 100).round(1)
18
20
  self.unexecuted_percent = (100 - self.executed_percent).round(1)
19
21
  end
20
22
 
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><!-- cover_me report -->
2
+
3
+ <report>
4
+ <stats>
5
+ <packages value="42"/>
6
+ <classes value="42"/>
7
+ <methods value="42"/>
8
+ <srcfiles value="42"/>
9
+ <srclines value="42"/>
10
+ </stats>
11
+ <data>
12
+ <all name="all classes">
13
+ <coverage type="class, %" value="0% (0/0)"/>
14
+ <coverage type="method, %" value="0% (0/0)"/>
15
+ <coverage type="block, %" value="0% (0/0)"/>
16
+ <coverage type="line, %" value="0% (<%= global.lines_executed %>/<%= global.lines_of_code %>)"/>
17
+
18
+ <% reports_by_dir.sort_by(&:name).each do |dir| %>
19
+ <package name="<%= dir.name %>">
20
+ <coverage type="class, %" value="0% (0/0)"/>
21
+ <coverage type="method, %" value="0% (0/0)"/>
22
+ <coverage type="block, %" value="0% (0/0)"/>
23
+ <coverage type="line, %" value="0% (<%= dir.lines_executed %>/<%= dir.lines_of_code %>)"/>
24
+
25
+ <% dir.reports.sort.each do |report| %>
26
+ <srcfile name="<%= File.basename(report.filename) %>">
27
+ <coverage type="class, %" value="0% (0/0)"/>
28
+ <coverage type="method, %" value="0% (0/0)"/>
29
+ <coverage type="block, %" value="0% (0/0)"/>
30
+ <coverage type="line, %" value="<%= report.executed_percent.to_i %>% (<%= report.lines_executed %>/<%= report.lines_of_code %>)"/>
31
+ </srcfile>
32
+ <% end %>
33
+ </package>
34
+ <% end %>
35
+ </all>
36
+ </data>
37
+ </report>
@@ -3,8 +3,8 @@
3
3
  <title><%= report.filename %></title>
4
4
  <%
5
5
  root = CoverMe.config.project.root.split(File::SEPARATOR)
6
- file = File.dirname(report.filename).split(File::SEPARATOR)
7
- diff = file - root
6
+ file = File.dirname(report.original_filename).split(File::SEPARATOR)
7
+ diff = file[root.size..-1]
8
8
  rel = (['..'] * diff.count).join(File::SEPARATOR)
9
9
  %>
10
10
  <link href="<%= File.join(rel, "report.css?#{rand}") %>" media="screen" rel="stylesheet" type="text/css" />
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - rc2
10
- version: 1.0.0.rc2
9
+ - rc3
10
+ version: 1.0.0.rc3
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-10-14 00:00:00 -04:00
18
+ date: 2010-10-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,13 +55,17 @@ extra_rdoc_files:
55
55
  - LICENSE
56
56
  files:
57
57
  - lib/cover_me/config.rb
58
+ - lib/cover_me/directory_report.rb
59
+ - lib/cover_me/emma_formatter.rb
58
60
  - lib/cover_me/formatter.rb
61
+ - lib/cover_me/global_report.rb
59
62
  - lib/cover_me/hash.rb
60
63
  - lib/cover_me/html_formatter.rb
61
64
  - lib/cover_me/index.rb
62
65
  - lib/cover_me/processor.rb
63
66
  - lib/cover_me/report.rb
64
67
  - lib/cover_me/results.rb
68
+ - lib/cover_me/templates/emma.xml.erb
65
69
  - lib/cover_me/templates/index.css
66
70
  - lib/cover_me/templates/index.html.erb
67
71
  - lib/cover_me/templates/jquery.js