rcov_stats 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -0
- data/README +36 -52
- data/config/rcov_rspec.yml +12 -12
- data/config/rcov_standard.yml +13 -13
- data/lib/rcov_stats.rb +166 -147
- data/lib/rcov_stats_tasks.rb +34 -34
- data/templates/index.html +107 -107
- data/templates/jquery-1.3.2.min.js +18 -18
- data/templates/jquery.tablesorter.min.js +14 -14
- data/templates/print.css +11 -11
- data/templates/rcov.js +41 -41
- data/templates/screen.css +270 -270
- metadata +55 -13
data/CHANGELOG
ADDED
data/README
CHANGED
@@ -1,52 +1,36 @@
|
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
- test files or directories with test files which will be used for functional testing (functionals_files_to_test)
|
38
|
-
- action which will be used before running test suite (before_rcov -> by default db:test:prepare)
|
39
|
-
|
40
|
-
|
41
|
-
You can run:
|
42
|
-
- rake rcov:stats (includes rcov:units and rcov:functionals)
|
43
|
-
- rake rcov:units
|
44
|
-
- rake rcov:functionals
|
45
|
-
- rake rcov:general (includes rcov:units and rcov:functionals, but counts one general coverage and puts all results in one output directory)
|
46
|
-
|
47
|
-
|
48
|
-
You can grab rcov gem with :
|
49
|
-
gem install rcov
|
50
|
-
|
51
|
-
|
52
|
-
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 #from gemcutter
|
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
|
+
|
17
|
+
How to configure
|
18
|
+
|
19
|
+
After installation (initialization) you can see rcov_stats.yml in /config directory.
|
20
|
+
You can specify there :
|
21
|
+
- files or directories to be covered by unit tests to cover (units_files_to_cover)
|
22
|
+
- files or directories to be covered by functional tests to cover (functionals_files_to_cover)
|
23
|
+
- test files or directories with test files which will be used for unit testing (units_files_to_test)
|
24
|
+
- test files or directories with test files which will be used for functional testing (functionals_files_to_test)
|
25
|
+
- action which will be used before running test suite (before_rcov -> by default db:test:prepare)
|
26
|
+
|
27
|
+
|
28
|
+
You can run:
|
29
|
+
- rake rcov:stats (includes rcov:units and rcov:functionals)
|
30
|
+
- rake rcov:units
|
31
|
+
- rake rcov:functionals
|
32
|
+
- rake rcov:general (includes rcov:units and rcov:functionals, but counts one general coverage and puts all results in one output directory)
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
Copyright (c) 2010 [bartes], released under the MIT license
|
data/config/rcov_rspec.yml
CHANGED
@@ -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
|
data/config/rcov_standard.yml
CHANGED
@@ -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,147 +1,166 @@
|
|
1
|
-
require
|
2
|
-
require "
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
def
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
1
|
+
require "fileutils"
|
2
|
+
require "erb"
|
3
|
+
|
4
|
+
class RcovStatsForErb
|
5
|
+
|
6
|
+
def initialize( options )
|
7
|
+
options.each_pair do |key, value|
|
8
|
+
instance_variable_set(:"@#{key}",value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_binding
|
13
|
+
binding
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class RcovStats
|
20
|
+
|
21
|
+
TYPES = ["units", "functionals"]
|
22
|
+
|
23
|
+
def self.cattr_accessor_with_default(name, value = nil)
|
24
|
+
cattr_accessor name
|
25
|
+
self.send("#{name}=", value) if value
|
26
|
+
end
|
27
|
+
|
28
|
+
cattr_accessor_with_default :is_rails, Object.const_defined?('Rails')
|
29
|
+
cattr_accessor_with_default :is_merb, Object.const_defined?('Merb')
|
30
|
+
cattr_accessor_with_default :root, ((@@is_rails && Rails.root) or (@@is_merb && Merb.root) or nil)
|
31
|
+
cattr_accessor_with_default :rcov_stats_dir, File.dirname(__FILE__)
|
32
|
+
cattr_accessor_with_default :rcov_stats_config_file, File.join(@@root, 'config', 'rcov_stats.yml')
|
33
|
+
cattr_accessor_with_default :use_rspec, File.exists?(File.join(@@root, 'spec'))
|
34
|
+
cattr_accessor_with_default :test_name, @@use_rspec ? "spec" : "test"
|
35
|
+
cattr_accessor_with_default :test_file_indicator, "*_#{@@test_name}.rb"
|
36
|
+
cattr_accessor_with_default :cover_file_indicator, "*.rb"
|
37
|
+
|
38
|
+
attr_accessor :name, :sections
|
39
|
+
|
40
|
+
def initialize(name_, sections_ = nil)
|
41
|
+
self.name = name_
|
42
|
+
self.sections = sections_.blank? ? [name_] : sections_
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_config(option)
|
46
|
+
YAML::load(File.open(File.join(@@root, 'config', 'rcov_stats.yml')))[option]
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.before_rcov
|
50
|
+
(pre_rcov = get_config("before_rcov")).blank? ? nil : pre_rcov
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_array_data(type)
|
54
|
+
@sections.map do |section|
|
55
|
+
(self.class.get_config("#{section}_#{type}") || []).reject { |d| d.blank? }
|
56
|
+
end.flatten.uniq
|
57
|
+
end
|
58
|
+
|
59
|
+
def files_to_cover
|
60
|
+
get_array_data "files_to_cover"
|
61
|
+
end
|
62
|
+
|
63
|
+
def files_to_test
|
64
|
+
get_array_data "files_to_test"
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_file_to_test(list)
|
68
|
+
result = []
|
69
|
+
list.each do |f|
|
70
|
+
file_list = File.directory?(File.join(@@root, @@test_name, f)) ? File.join(@@test_name, f, "**", @@test_file_indicator) : File.join(@@test_name, f)
|
71
|
+
unless (list_of_read_files = Dir[file_list]).empty?
|
72
|
+
result += list_of_read_files
|
73
|
+
end
|
74
|
+
end
|
75
|
+
result.uniq
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse_file_to_cover(list)
|
79
|
+
result = []
|
80
|
+
list.each do |f|
|
81
|
+
file_list = File.directory?(File.join(@@root, f)) ? File.join(f, "**", @@cover_file_indicator) : File.join(f)
|
82
|
+
unless (list_of_read_files = Dir[file_list]).empty?
|
83
|
+
result += list_of_read_files
|
84
|
+
end
|
85
|
+
end
|
86
|
+
result.uniq
|
87
|
+
end
|
88
|
+
|
89
|
+
def invoke_rcov_task
|
90
|
+
require 'rake/win32'
|
91
|
+
files_to_cover_parsed = parse_file_to_cover(files_to_cover).map { |f| "(#{f})".gsub("/", "\/") }.join("|")
|
92
|
+
rcov_settings = "--sort coverage --text-summary -x \"^(?!(#{files_to_cover_parsed}))\" "
|
93
|
+
rcov_settings +="--output=#{File.join(@@root, "coverage", @name)} "
|
94
|
+
rcov_tests = parse_file_to_test(files_to_test)
|
95
|
+
return false if rcov_tests.empty?
|
96
|
+
rcov_settings += rcov_tests.join(' ')
|
97
|
+
cmd = "bundle exec rcov #{rcov_settings}"
|
98
|
+
Rake::Win32.windows? ? Rake::Win32.rake_system(cmd) : system(cmd)
|
99
|
+
end
|
100
|
+
|
101
|
+
def invoke_rcov_spec_task
|
102
|
+
require 'spec/rake/spectask'
|
103
|
+
rcov_tests = parse_file_to_test(files_to_test)
|
104
|
+
return false if rcov_tests.empty?
|
105
|
+
Spec::Rake::SpecTask.new(@name) do |t|
|
106
|
+
spec_opts = File.join(@@root, @@test_name, 'spec.opts')
|
107
|
+
t.spec_opts = ['--options', "\"#{spec_opts}\""] if File.exists?(spec_opts)
|
108
|
+
t.spec_files = rcov_tests
|
109
|
+
t.rcov = true
|
110
|
+
t.rcov_dir = File.join(@@root, "coverage", @name)
|
111
|
+
files_to_cover_parsed = parse_file_to_cover(files_to_cover).map { |f| "(#{f})".gsub("/", "\/") }.join("|")
|
112
|
+
t.rcov_opts = ["--text-summary", "--sort", "coverage", "-x", "\"^(?!(#{files_to_cover_parsed}))\""]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def invoke
|
117
|
+
@@use_rspec ? invoke_rcov_spec_task : invoke_rcov_task
|
118
|
+
end
|
119
|
+
|
120
|
+
def generate_index
|
121
|
+
Dir[File.join(@@rcov_stats_dir, '..', 'templates/*')].each do |i|
|
122
|
+
FileUtils.cp(i, File.join(@@root, 'coverage', i.split("/").last))
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
@sections.each do |i|
|
128
|
+
coverage_index = File.join(@@root, 'coverage', i, "index.html")
|
129
|
+
next unless File.exists?(coverage_index)
|
130
|
+
doc = open(coverage_index) { |f| Hpricot(f) }
|
131
|
+
footer_tts = doc.search("//tfoot/tr/td//tt")
|
132
|
+
footer_div_covered = doc.search("//tfoot/tr/td//div[@class='covered']")
|
133
|
+
footer_div_uncovered = doc.search("//tfoot/tr/td//div[@class='uncovered']")
|
134
|
+
|
135
|
+
template_object = {}
|
136
|
+
template_object["#{i}_total_lines"] = footer_tts[0].inner_text
|
137
|
+
template_object["#{i}_code_lines"] = footer_tts[1].inner_text
|
138
|
+
template_object["#{i}_total_result"] = footer_tts[2].inner_text
|
139
|
+
template_object["#{i}_code_result"] = footer_tts[3].inner_text
|
140
|
+
template_object["#{i}_total_rpx"] = footer_div_covered[0].get_attribute("style")
|
141
|
+
template_object["#{i}_total_cpx"] = footer_div_covered[1].get_attribute("style")
|
142
|
+
template_object["#{i}_total_lrpx"] = footer_div_uncovered[0].get_attribute("style")
|
143
|
+
template_object["#{i}_total_lcpx"] = footer_div_uncovered[1].get_attribute("style")
|
144
|
+
template_object["generated_on"] = "Generated on #{Time.now}"
|
145
|
+
|
146
|
+
|
147
|
+
template_source = ERB.new(IO.read(File.join(@@root, 'coverage', "index.html")))
|
148
|
+
|
149
|
+
File.open(File.join(@@root, 'coverage', "index.html"), "w+") do |f|
|
150
|
+
f.write( template_source.result(RcovStatsForErb.new(template_object).get_binding))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.setup
|
156
|
+
if @@is_merb
|
157
|
+
Merb::Plugins.add_rakefiles(File.join(@@rcov_stats_dir, "rcov_stats_tasks"))
|
158
|
+
end
|
159
|
+
unless File.exists?(@@rcov_stats_config_file)
|
160
|
+
which_conf_use = (@@use_rspec ? 'rcov_rspec' : 'rcov_standard') + '.yml'
|
161
|
+
FileUtils.cp(File.join(@@rcov_stats_dir, '..', 'config', which_conf_use), @@rcov_stats_config_file)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
RcovStats.setup
|
data/lib/rcov_stats_tasks.rb
CHANGED
@@ -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
|