rcov_stats 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,17 +1,19 @@
1
- 2.2.1 (September 2010)
2
- fixed generating index.html coverage summary values
3
- 2.2.0 (September 2010)
4
- fixed root paths
5
- added rspec2 support
6
- added support of no bundler
7
- some code improvements
8
- 2.1.1 (September 2010)
9
- missing require
10
- 2.1.0 (September 2010)
11
- replaced ReXML with Hpricot
12
- made it working only with bundler > 0.9
13
- made it working with rcov 0.9.9
14
- 2.0.1 (May 2010)
15
- fixed bug for merb with wrong bracket use
16
- 2.0.0 (April 2010)
1
+ 2.2.2 (September 2010)
2
+ fixed requiring path for rails 2.3.x
3
+ 2.2.1 (September 2010)
4
+ fixed generating index.html coverage summary values
5
+ 2.2.0 (September 2010)
6
+ fixed root paths
7
+ added rspec2 support
8
+ added support of no bundler
9
+ some code improvements
10
+ 2.1.1 (September 2010)
11
+ missing require
12
+ 2.1.0 (September 2010)
13
+ replaced ReXML with Hpricot
14
+ made it working only with bundler > 0.9
15
+ made it working with rcov 0.9.9
16
+ 2.0.1 (May 2010)
17
+ fixed bug for merb with wrong bracket use
18
+ 2.0.0 (April 2010)
17
19
  refactor
data/README CHANGED
@@ -1,43 +1,43 @@
1
- RcovStats
2
- =========
3
-
4
- RcovStats provides rcov extension, so you can select test files and test covered files for unit and functional tests.
5
-
6
- How to install :
7
-
8
- ** for Merb:
9
- gem install rcov_stats
10
- ## puts this dependency inside your config/init.rb file ##
11
- dependency "rcov_stats"
12
- ** for Rails
13
- ## puts this into Gemfile file ##
14
- gem "rcov_stats"
15
-
16
- ## puts also this code to RakeFile (for Rails3 before Application.load_tasks)
17
-
18
- begin
19
- require 'rcov_stats_tasks'
20
- rescue LoadError; end
21
-
22
-
23
-
24
- How to configure
25
-
26
- After installation (initialization) you can see rcov_stats.yml in /config directory.
27
- You can specify there :
28
- - files or directories to be covered by unit tests to cover (units_files_to_cover)
29
- - files or directories to be covered by functional tests to cover (functionals_files_to_cover)
30
- - test files or directories with test files which will be used for unit testing (units_files_to_test)
31
- - test files or directories with test files which will be used for functional testing (functionals_files_to_test)
32
- - action which will be used before running test suite (before_rcov -> by default db:test:prepare)
33
-
34
-
35
- You can run:
36
- - rake rcov:stats (includes rcov:units and rcov:functionals)
37
- - rake rcov:units
38
- - rake rcov:functionals
39
- - rake rcov:general (includes rcov:units and rcov:functionals, but counts one general coverage and puts all results in one output directory)
40
-
41
-
42
-
43
- Copyright (c) 2010 [bartes], released under the MIT license
1
+ RcovStats
2
+ =========
3
+
4
+ RcovStats provides rcov extension, so you can select test files and test covered files for unit and functional tests.
5
+
6
+ How to install :
7
+
8
+ ** for Merb:
9
+ gem install rcov_stats
10
+ ## puts this dependency inside your config/init.rb file ##
11
+ dependency "rcov_stats"
12
+ ** for Rails
13
+ ## puts this into Gemfile file ##
14
+ gem "rcov_stats"
15
+
16
+ ## puts also this code to RakeFile (for Rails3 before Application.load_tasks)
17
+
18
+ begin
19
+ require 'rcov_stats_tasks'
20
+ rescue LoadError; end
21
+
22
+
23
+
24
+ How to configure
25
+
26
+ After installation (initialization) you can see rcov_stats.yml in /config directory.
27
+ You can specify there :
28
+ - files or directories to be covered by unit tests to cover (units_files_to_cover)
29
+ - files or directories to be covered by functional tests to cover (functionals_files_to_cover)
30
+ - test files or directories with test files which will be used for unit testing (units_files_to_test)
31
+ - test files or directories with test files which will be used for functional testing (functionals_files_to_test)
32
+ - action which will be used before running test suite (before_rcov -> by default db:test:prepare)
33
+
34
+
35
+ You can run:
36
+ - rake rcov:stats (includes rcov:units and rcov:functionals)
37
+ - rake rcov:units
38
+ - rake rcov:functionals
39
+ - rake rcov:general (includes rcov:units and rcov:functionals, but counts one general coverage and puts all results in one output directory)
40
+
41
+
42
+
43
+ Copyright (c) 2010 [bartes], released under the MIT license
@@ -1,13 +1,13 @@
1
- units_files_to_cover:
2
- - app/models
3
- functionals_files_to_cover:
4
- - app/controllers
5
- - app/helpers
6
- units_files_to_test:
7
- - models
8
- functionals_files_to_test:
9
- - controllers
10
- - helpers
11
- before_rcov: db:test:prepare
12
-
1
+ units_files_to_cover:
2
+ - app/models
3
+ functionals_files_to_cover:
4
+ - app/controllers
5
+ - app/helpers
6
+ units_files_to_test:
7
+ - models
8
+ functionals_files_to_test:
9
+ - controllers
10
+ - helpers
11
+ before_rcov: db:test:prepare
12
+
13
13
  #you can select files also this way app/*/*.rb
@@ -1,13 +1,13 @@
1
- units_files_to_cover:
2
- - app/models
3
- functionals_files_to_cover:
4
- - app/controllers
5
- - app/helpers
6
- units_files_to_test:
7
- - unit
8
- functionals_files_to_test:
9
- - functional
10
- - integration
11
- before_rcov: db:test:prepare
12
-
13
- #you can select files also this way app/*/*.rb
1
+ units_files_to_cover:
2
+ - app/models
3
+ functionals_files_to_cover:
4
+ - app/controllers
5
+ - app/helpers
6
+ units_files_to_test:
7
+ - unit
8
+ functionals_files_to_test:
9
+ - functional
10
+ - integration
11
+ before_rcov: db:test:prepare
12
+
13
+ #you can select files also this way app/*/*.rb
data/lib/rcov_stats.rb CHANGED
@@ -1,155 +1,155 @@
1
- require "fileutils"
2
- require "erb"
3
- require "hpricot"
4
- require 'rcov_stats_related/erb_binding'
5
-
6
- class RcovStats
7
-
8
- TYPES = ["units", "functionals"]
9
-
10
- def self.cattr_accessor_with_default(name, value = nil)
11
- cattr_accessor name
12
- self.send("#{name}=", value) if value
13
- end
14
-
15
- cattr_accessor_with_default :is_rails, defined?(Rails)
16
- cattr_accessor_with_default :is_merb, defined?(Merb)
17
-
18
- def self.root
19
- "."
20
- end
21
-
22
- raise "Rcov Stats could not detect Rails or Merb framework" unless root
23
-
24
- cattr_accessor_with_default :rcov_stats_dir, File.dirname(__FILE__)
25
- cattr_accessor_with_default :rcov_stats_config_file, File.join(root, 'config', 'rcov_stats.yml')
26
-
27
- cattr_accessor_with_default :cover_file_indicator, "*.rb"
28
-
29
- attr_accessor :name, :sections
30
-
31
-
32
-
33
- def initialize(name_, sections_ = nil)
34
- self.name = name_
35
- self.sections = sections_.blank? ? [name_] : sections_
36
- end
37
-
38
- def self.get_config(option)
39
- YAML::load(File.open(File.join(root, 'config', 'rcov_stats.yml')))[option]
40
- end
41
-
42
- def self.before_rcov
43
- (pre_rcov = get_config("before_rcov")).blank? ? nil : pre_rcov
44
- end
45
-
46
- def get_array_data(type)
47
- @sections.map do |section|
48
- (self.class.get_config("#{section}_#{type}") || []).reject { |d| d.blank? }
49
- end.flatten.uniq
50
- end
51
-
52
- def files_to_cover
53
- get_array_data "files_to_cover"
54
- end
55
-
56
- def files_to_test
57
- get_array_data "files_to_test"
58
- end
59
-
60
- def parse_file_to_test(list)
61
- result = []
62
- list.each do |f|
63
- file_list = File.directory?(File.join(self.class.root, test_name, f)) ? File.join(test_name, f, "**", test_file_indicator) : File.join(test_name, f)
64
- unless (list_of_read_files = Dir[file_list]).empty?
65
- result += list_of_read_files
66
- end
67
- end
68
- result.uniq
69
- end
70
-
71
- def parse_file_to_cover(list)
72
- result = []
73
- list.each do |f|
74
- file_list = File.directory?(File.join(self.class.root, f)) ? File.join(f, "**", self.class.cover_file_indicator) : File.join(f)
75
- unless (list_of_read_files = Dir[file_list]).empty?
76
- result += list_of_read_files
77
- end
78
- end
79
- result.uniq
80
- end
81
-
82
- def test_file_indicator
83
- "*_#{test_name}.rb"
84
- end
85
-
86
- def generate_index
87
- Dir[File.join(self.class.rcov_stats_dir, '..', 'templates/*')].each do |i|
88
- FileUtils.mkdir_p File.join(self.class.root, 'coverage')
89
- FileUtils.cp(i, File.join(self.class.root, 'coverage', i.split("/").last))
90
- end
91
-
92
- template_object = {}
93
-
94
- @sections.each do |i|
95
- FileUtils.mkdir_p File.join(self.class.root, 'coverage', i)
96
- coverage_index = File.join(self.class.root, 'coverage', i, "index.html")
97
- next unless File.exists?(coverage_index)
98
- doc = open(coverage_index) { |f| Hpricot(f) }
99
- footer_tts = doc.search("//tfoot/tr/td//tt")
100
- footer_div_covered = doc.search("//tfoot/tr/td//div[@class='covered']")
101
- footer_div_uncovered = doc.search("//tfoot/tr/td//div[@class='uncovered']")
102
-
103
- template_object["#{i}_total_lines"] = footer_tts[0].inner_text
104
- template_object["#{i}_code_lines"] = footer_tts[1].inner_text
105
- template_object["#{i}_total_result"] = footer_tts[2].inner_text
106
- template_object["#{i}_code_result"] = footer_tts[3].inner_text
107
- template_object["#{i}_total_rpx"] = footer_div_covered[0].get_attribute("style")
108
- template_object["#{i}_total_cpx"] = footer_div_covered[1].get_attribute("style")
109
- template_object["#{i}_total_lrpx"] = footer_div_uncovered[0].get_attribute("style")
110
- template_object["#{i}_total_lcpx"] = footer_div_uncovered[1].get_attribute("style")
111
- end
112
-
113
- template_object["generated_on"] = "Generated on #{Time.now}"
114
- template_source = ERB.new(IO.read(File.join(self.class.root, 'coverage', "index.html")))
115
-
116
- File.open(File.join(self.class.root, 'coverage', "index.html"), "w+") do |f|
117
- f.write( template_source.result(RcovStatsRelated::ErbBinding.new(template_object).get_binding))
118
- end
119
- end
120
-
121
- def bundler?
122
- File.exist?("./Gemfile")
123
- end
124
-
125
- def self.setup
126
- if is_merb
127
- Merb::Plugins.add_rakefiles(File.join(rcov_stats_dir, "rcov_stats_tasks"))
128
- end
129
-
130
- if defined?(RSpec)
131
- require 'rcov_stats_related/integrations/rspec2'
132
- include RcovStatsRelated::Integrations::Rspec2
133
- which_conf_use = 'rcov_rspec'
134
- elsif defined?(Spec)
135
- require 'rcov_stats_related/integrations/rspec'
136
- include RcovStatsRelated::Integrations::Rspec
137
- which_conf_use = 'rcov_rspec'
138
- else
139
- require 'rcov_stats_related/integrations/test_unit'
140
- include RcovStatsRelated::Integrations::TestUnit
141
- which_conf_use = 'rcov_standard'
142
- end
143
-
144
-
145
- unless File.exists?(rcov_stats_config_file)
146
- which_conf_use += '.yml'
147
- FileUtils.cp(File.join(rcov_stats_dir, '..', 'config', which_conf_use), rcov_stats_config_file)
148
- end
149
- end
150
- end
151
-
152
-
153
- RcovStats.setup
154
-
155
-
1
+ require "fileutils"
2
+ require "erb"
3
+ require "hpricot"
4
+ require File.expand_path(File.dirname(__FILE__) + '/rcov_stats_related/erb_binding')
5
+
6
+ class RcovStats
7
+
8
+ TYPES = ["units", "functionals"]
9
+
10
+ def self.cattr_accessor_with_default(name, value = nil)
11
+ cattr_accessor name
12
+ self.send("#{name}=", value) if value
13
+ end
14
+
15
+ cattr_accessor_with_default :is_rails, defined?(Rails)
16
+ cattr_accessor_with_default :is_merb, defined?(Merb)
17
+
18
+ def self.root
19
+ "."
20
+ end
21
+
22
+ raise "Rcov Stats could not detect Rails or Merb framework" unless root
23
+
24
+ cattr_accessor_with_default :rcov_stats_dir, File.dirname(__FILE__)
25
+ cattr_accessor_with_default :rcov_stats_config_file, File.join(root, 'config', 'rcov_stats.yml')
26
+
27
+ cattr_accessor_with_default :cover_file_indicator, "*.rb"
28
+
29
+ attr_accessor :name, :sections
30
+
31
+
32
+
33
+ def initialize(name_, sections_ = nil)
34
+ self.name = name_
35
+ self.sections = sections_.blank? ? [name_] : sections_
36
+ end
37
+
38
+ def self.get_config(option)
39
+ YAML::load(File.open(File.join(root, 'config', 'rcov_stats.yml')))[option]
40
+ end
41
+
42
+ def self.before_rcov
43
+ (pre_rcov = get_config("before_rcov")).blank? ? nil : pre_rcov
44
+ end
45
+
46
+ def get_array_data(type)
47
+ @sections.map do |section|
48
+ (self.class.get_config("#{section}_#{type}") || []).reject { |d| d.blank? }
49
+ end.flatten.uniq
50
+ end
51
+
52
+ def files_to_cover
53
+ get_array_data "files_to_cover"
54
+ end
55
+
56
+ def files_to_test
57
+ get_array_data "files_to_test"
58
+ end
59
+
60
+ def parse_file_to_test(list)
61
+ result = []
62
+ list.each do |f|
63
+ file_list = File.directory?(File.join(self.class.root, test_name, f)) ? File.join(test_name, f, "**", test_file_indicator) : File.join(test_name, f)
64
+ unless (list_of_read_files = Dir[file_list]).empty?
65
+ result += list_of_read_files
66
+ end
67
+ end
68
+ result.uniq
69
+ end
70
+
71
+ def parse_file_to_cover(list)
72
+ result = []
73
+ list.each do |f|
74
+ file_list = File.directory?(File.join(self.class.root, f)) ? File.join(f, "**", self.class.cover_file_indicator) : File.join(f)
75
+ unless (list_of_read_files = Dir[file_list]).empty?
76
+ result += list_of_read_files
77
+ end
78
+ end
79
+ result.uniq
80
+ end
81
+
82
+ def test_file_indicator
83
+ "*_#{test_name}.rb"
84
+ end
85
+
86
+ def generate_index
87
+ Dir[File.join(self.class.rcov_stats_dir, '..', 'templates/*')].each do |i|
88
+ FileUtils.mkdir_p File.join(self.class.root, 'coverage')
89
+ FileUtils.cp(i, File.join(self.class.root, 'coverage', i.split("/").last))
90
+ end
91
+
92
+ template_object = {}
93
+
94
+ @sections.each do |i|
95
+ FileUtils.mkdir_p File.join(self.class.root, 'coverage', i)
96
+ coverage_index = File.join(self.class.root, 'coverage', i, "index.html")
97
+ next unless File.exists?(coverage_index)
98
+ doc = open(coverage_index) { |f| Hpricot(f) }
99
+ footer_tts = doc.search("//tfoot/tr/td//tt")
100
+ footer_div_covered = doc.search("//tfoot/tr/td//div[@class='covered']")
101
+ footer_div_uncovered = doc.search("//tfoot/tr/td//div[@class='uncovered']")
102
+
103
+ template_object["#{i}_total_lines"] = footer_tts[0].inner_text
104
+ template_object["#{i}_code_lines"] = footer_tts[1].inner_text
105
+ template_object["#{i}_total_result"] = footer_tts[2].inner_text
106
+ template_object["#{i}_code_result"] = footer_tts[3].inner_text
107
+ template_object["#{i}_total_rpx"] = footer_div_covered[0].get_attribute("style")
108
+ template_object["#{i}_total_cpx"] = footer_div_covered[1].get_attribute("style")
109
+ template_object["#{i}_total_lrpx"] = footer_div_uncovered[0].get_attribute("style")
110
+ template_object["#{i}_total_lcpx"] = footer_div_uncovered[1].get_attribute("style")
111
+ end
112
+
113
+ template_object["generated_on"] = "Generated on #{Time.now}"
114
+ template_source = ERB.new(IO.read(File.join(self.class.root, 'coverage', "index.html")))
115
+
116
+ File.open(File.join(self.class.root, 'coverage', "index.html"), "w+") do |f|
117
+ f.write( template_source.result(RcovStatsRelated::ErbBinding.new(template_object).get_binding))
118
+ end
119
+ end
120
+
121
+ def bundler?
122
+ File.exist?("./Gemfile")
123
+ end
124
+
125
+ def self.setup
126
+ if is_merb
127
+ Merb::Plugins.add_rakefiles(File.join(rcov_stats_dir, "rcov_stats_tasks"))
128
+ end
129
+
130
+ if defined?(RSpec)
131
+ require 'rcov_stats_related/integrations/rspec2'
132
+ include RcovStatsRelated::Integrations::Rspec2
133
+ which_conf_use = 'rcov_rspec'
134
+ elsif defined?(Spec)
135
+ require 'rcov_stats_related/integrations/rspec'
136
+ include RcovStatsRelated::Integrations::Rspec
137
+ which_conf_use = 'rcov_rspec'
138
+ else
139
+ require 'rcov_stats_related/integrations/test_unit'
140
+ include RcovStatsRelated::Integrations::TestUnit
141
+ which_conf_use = 'rcov_standard'
142
+ end
143
+
144
+
145
+ unless File.exists?(rcov_stats_config_file)
146
+ which_conf_use += '.yml'
147
+ FileUtils.cp(File.join(rcov_stats_dir, '..', 'config', which_conf_use), rcov_stats_config_file)
148
+ end
149
+ end
150
+ end
151
+
152
+
153
+ RcovStats.setup
154
+
155
+
@@ -1,34 +1,34 @@
1
- namespace :rcov do
2
- require File.join(File.dirname(__FILE__), "rcov_stats.rb")
3
- desc "run rcov for units tests"
4
- task(RcovStats.before_rcov ? ({:units => RcovStats.before_rcov}) : :units) do
5
- puts '** rcov:units **'
6
- RcovStats.new('units').invoke
7
- end
8
-
9
- desc "run rcov for functionals tests"
10
- task(RcovStats.before_rcov ? ({:functionals => RcovStats.before_rcov}) : :functionals) do
11
- puts '** rcov:functionals **'
12
- RcovStats.new('functionals').invoke
13
- end
14
-
15
- desc "run rcov for functionals and units tests"
16
- task(RcovStats.before_rcov ? ({:stats => RcovStats.before_rcov}) : :stats) do
17
- puts '** rcov:stats **'
18
- Rake::Task['rcov:units'].invoke
19
- Rake::Task['rcov:functionals'].invoke
20
- Rake::Task['rcov:generate_index'].invoke
21
- end
22
-
23
- desc "run general rcov tests"
24
- task(RcovStats.before_rcov ? ({:general => RcovStats.before_rcov}) : :general) do
25
- puts '** rcov:general **'
26
- RcovStats.new('general',["units", "functionals"]).invoke
27
- end
28
-
29
- desc "generate index for all suites"
30
- task :generate_index do
31
- puts '** rcov:generate_index **'
32
- RcovStats.new('general',["units", "functionals"]).generate_index
33
- end
34
- end
1
+ namespace :rcov do
2
+ require File.join(File.dirname(__FILE__), "rcov_stats.rb")
3
+ desc "run rcov for units tests"
4
+ task(RcovStats.before_rcov ? ({:units => RcovStats.before_rcov}) : :units) do
5
+ puts '** rcov:units **'
6
+ RcovStats.new('units').invoke
7
+ end
8
+
9
+ desc "run rcov for functionals tests"
10
+ task(RcovStats.before_rcov ? ({:functionals => RcovStats.before_rcov}) : :functionals) do
11
+ puts '** rcov:functionals **'
12
+ RcovStats.new('functionals').invoke
13
+ end
14
+
15
+ desc "run rcov for functionals and units tests"
16
+ task(RcovStats.before_rcov ? ({:stats => RcovStats.before_rcov}) : :stats) do
17
+ puts '** rcov:stats **'
18
+ Rake::Task['rcov:units'].invoke
19
+ Rake::Task['rcov:functionals'].invoke
20
+ Rake::Task['rcov:generate_index'].invoke
21
+ end
22
+
23
+ desc "run general rcov tests"
24
+ task(RcovStats.before_rcov ? ({:general => RcovStats.before_rcov}) : :general) do
25
+ puts '** rcov:general **'
26
+ RcovStats.new('general',["units", "functionals"]).invoke
27
+ end
28
+
29
+ desc "generate index for all suites"
30
+ task :generate_index do
31
+ puts '** rcov:generate_index **'
32
+ RcovStats.new('general',["units", "functionals"]).generate_index
33
+ end
34
+ end