bartes-rcov_stats 1.0.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/MIT-LICENSE +20 -0
- data/README +29 -0
- data/Rakefile +9 -0
- data/config/rcov_rspec.yml +11 -0
- data/config/rcov_standard.yml +11 -0
- data/init.rb +10 -0
- data/lib/rcov_stats.rb +163 -0
- data/tasks/rcov.rake +27 -0
- metadata +60 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [bartes]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
RcovStats
|
2
|
+
=========
|
3
|
+
|
4
|
+
RcovStats provides rcov extension, so you could select test files and test covered files for units and functionals tests.
|
5
|
+
|
6
|
+
How to install :
|
7
|
+
|
8
|
+
1) As a Rails plugin:
|
9
|
+
./script/plugin install git://github.com/bartes/rcov_stats.git
|
10
|
+
2) As a gem for Rails:
|
11
|
+
gem install bartes-rcov_stats
|
12
|
+
gem install gemsonrails
|
13
|
+
cd your_application
|
14
|
+
gemsonrails
|
15
|
+
rake gems:freeze GEM=bartes-rcov_stats
|
16
|
+
|
17
|
+
How to configure
|
18
|
+
|
19
|
+
After installation you can see rcov_stats.yml in /config directory.
|
20
|
+
You can specify there :
|
21
|
+
- files or directories to be covered by units tests to cover (units_files_to_cover)
|
22
|
+
- files or directories to be covered by functionals tests to cover (functionals_files_to_cover)
|
23
|
+
- test files or directories with test files which will be used for units testing (units_files_to_test)
|
24
|
+
- test files or directories with test files which will be used for functionals 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
|
+
|
29
|
+
Copyright (c) 2009 [bartes], released under the MIT license
|
data/Rakefile
ADDED
data/init.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
plugin_root = File.dirname(__FILE__)
|
4
|
+
config_file = File.join(RAILS_ROOT,'config','rcov_stats.yml')
|
5
|
+
|
6
|
+
unless File.exists?(config_file)
|
7
|
+
use_rspec = File.exists?(File.join(RAILS_ROOT, 'spec'))
|
8
|
+
config_file_base = (use_rspec ? 'rcov_rspec' : 'rcov_standard') + '.yml'
|
9
|
+
FileUtils.cp(File.join(plugin_root, 'config', config_file_base), config_file)
|
10
|
+
end
|
data/lib/rcov_stats.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require File.join(RAILS_ROOT,'config','environment')
|
2
|
+
|
3
|
+
module RcovStats
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def plugin_root
|
8
|
+
File.join(File.dirname(__FILE__),'..')
|
9
|
+
end
|
10
|
+
|
11
|
+
def root
|
12
|
+
RAILS_ROOT
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_config(name)
|
16
|
+
YAML::load(File.open(File.join(root ,'config','rcov_stats.yml')))[name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_array_data(name)
|
20
|
+
(get_config(name) || []).reject{|d| d.blank?}.uniq
|
21
|
+
end
|
22
|
+
|
23
|
+
def units_files_to_cover
|
24
|
+
get_array_data "units_files_to_cover"
|
25
|
+
end
|
26
|
+
|
27
|
+
def functionals_files_to_cover
|
28
|
+
get_array_data "functionals_files_to_cover"
|
29
|
+
end
|
30
|
+
|
31
|
+
def units_files_to_test
|
32
|
+
get_array_data "units_files_to_test"
|
33
|
+
end
|
34
|
+
|
35
|
+
def functionals_files_to_test
|
36
|
+
get_array_data "functionals_files_to_test"
|
37
|
+
end
|
38
|
+
|
39
|
+
def excluded_paths
|
40
|
+
%w(spec gems plugins)
|
41
|
+
end
|
42
|
+
|
43
|
+
def igonored_paths
|
44
|
+
%w(. .. .svn)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_file_indicator
|
48
|
+
"*_#{test_name}.rb"
|
49
|
+
end
|
50
|
+
|
51
|
+
def before_rcov
|
52
|
+
(pre_rcov = get_config("before_rcov")).blank? ? "db:test:prepare" : pre_rcov
|
53
|
+
end
|
54
|
+
|
55
|
+
def use_rspec?
|
56
|
+
File.exists?(File.join(root, 'spec'))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_name
|
60
|
+
use_rspec? ? "spec" : "test"
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_file_to_test(file_list)
|
64
|
+
rcov_tests = []
|
65
|
+
file_list.each do |f|
|
66
|
+
dir_or_file = File.join(root, test_name,f)
|
67
|
+
next unless File.exists?(dir_or_file)
|
68
|
+
unless File.directory?(dir_or_file)
|
69
|
+
rcov_tests << File.join(dir_or_file)
|
70
|
+
else
|
71
|
+
sub_elements = Dir.entries(dir_or_file) - igonored_paths
|
72
|
+
next if sub_elements.size.zero?
|
73
|
+
main_tests_not_included = true
|
74
|
+
sub_elements.each do |sub_element|
|
75
|
+
if File.directory?(File.join(dir_or_file,sub_element))
|
76
|
+
rcov_tests << File.join(dir_or_file,sub_element,test_file_indicator)
|
77
|
+
elsif main_tests_not_included
|
78
|
+
rcov_tests << File.join(dir_or_file,test_file_indicator)
|
79
|
+
main_tests_not_included = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
rcov_tests
|
85
|
+
end
|
86
|
+
|
87
|
+
def parse_file_to_cover(file_list)
|
88
|
+
rcov_covers = []
|
89
|
+
file_list.each do |f|
|
90
|
+
dir_or_file = File.join(root,f)
|
91
|
+
next unless File.exists?(dir_or_file)
|
92
|
+
unless File.directory?(dir_or_file)
|
93
|
+
rcov_covers << f
|
94
|
+
else
|
95
|
+
sub_elements = Dir.entries(dir_or_file) - igonored_paths
|
96
|
+
next if sub_elements.size.zero?
|
97
|
+
main_tests_not_included = true
|
98
|
+
sub_elements.each do |sub_element|
|
99
|
+
if File.directory?(File.join(dir_or_file,sub_element))
|
100
|
+
rcov_covers << File.join(f,sub_element)
|
101
|
+
elsif main_tests_not_included
|
102
|
+
rcov_covers << File.join(f)
|
103
|
+
main_tests_not_included = false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
rcov_covers
|
109
|
+
end
|
110
|
+
|
111
|
+
def invoke_rcov_task(options)
|
112
|
+
require 'rake/win32'
|
113
|
+
files_to_cover = parse_file_to_cover(options[:files_to_cover].uniq).map{|f| "(#{f})".gsub("/","\/")}.join("|")
|
114
|
+
rcov_settings = "--sort coverage --text-summary --rails -x \"^(?!(#{files_to_cover}))\" "
|
115
|
+
rcov_settings +="--exclude \"#{excluded_paths.map{|p| "#{p}/*"}.join(",")}\" "
|
116
|
+
rcov_settings +="--output=#{File.join(root,"coverage",options[:output])} " if options[:output]
|
117
|
+
rcov_tests = parse_file_to_test(options[:files_to_test].uniq)
|
118
|
+
return false if rcov_tests.empty?
|
119
|
+
rcov_settings += rcov_tests.join(' ')
|
120
|
+
cmd = "rcov #{rcov_settings}"
|
121
|
+
Rake::Win32.windows? ? Rake::Win32.rake_system(cmd) : system(cmd)
|
122
|
+
end
|
123
|
+
|
124
|
+
def invoke_rcov_spec_task(options)
|
125
|
+
require 'spec/rake/spectask'
|
126
|
+
rcov_tests = parse_file_to_test(options[:files_to_test].uniq)
|
127
|
+
return false if rcov_tests.empty?
|
128
|
+
Spec::Rake::SpecTask.new(options[:name]) do |t|
|
129
|
+
t.spec_opts = ['--options', "\"#{File.join(root,'spec','spec.opts')}\""]
|
130
|
+
t.spec_files = rcov_tests
|
131
|
+
t.rcov = true
|
132
|
+
t.rcov_dir = File.join(root,"coverage",options[:output]) if options[:output]
|
133
|
+
files_to_cover = parse_file_to_cover(options[:files_to_cover].uniq).map{|f| "(#{f})".gsub("/","\/")}.join("|")
|
134
|
+
t.rcov_opts = ["--rails","--text-summary","--sort","coverage","--exclude","\"#{excluded_paths.map{|p| "#{p}/*"}.join(",")}\"","-x" , "\"^(?!(#{files_to_cover}))\""]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def invoke(type)
|
139
|
+
options = {}
|
140
|
+
case type.to_s
|
141
|
+
when "units"
|
142
|
+
options[:name] = "rcov:units"
|
143
|
+
options[:files_to_cover] = units_files_to_cover
|
144
|
+
options[:files_to_test] = units_files_to_test
|
145
|
+
options[:output] = "units"
|
146
|
+
when "functionals"
|
147
|
+
options[:name] = "rcov:functionals"
|
148
|
+
options[:files_to_cover] = functionals_files_to_cover
|
149
|
+
options[:files_to_test] = functionals_files_to_test
|
150
|
+
options[:output] = "functionals"
|
151
|
+
when "general"
|
152
|
+
options[:name] = "rcov:general"
|
153
|
+
options[:files_to_cover] = units_files_to_cover + functionals_files_to_cover
|
154
|
+
options[:files_to_test] = units_files_to_test + functionals_files_to_test
|
155
|
+
options[:output] = nil
|
156
|
+
else
|
157
|
+
raise "Not implemented task for that rcov #{type}"
|
158
|
+
end
|
159
|
+
use_rspec? ? invoke_rcov_spec_task(options) : invoke_rcov_task(options)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
data/tasks/rcov.rake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
namespace :rcov do
|
2
|
+
require File.join(File.dirname(__FILE__), "../lib/rcov_stats.rb")
|
3
|
+
desc "run rcov for units tests"
|
4
|
+
task :units => RcovStats.before_rcov do
|
5
|
+
puts '** rcov:units **'
|
6
|
+
RcovStats.invoke('units')
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "run rcov for functionals tests"
|
10
|
+
task :functionals => RcovStats.before_rcov do
|
11
|
+
puts '** rcov:functionals **'
|
12
|
+
RcovStats.invoke('functionals')
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "run rcov for functionals and units tests"
|
16
|
+
task :stats => RcovStats.before_rcov do
|
17
|
+
puts '** rcov:stats **'
|
18
|
+
Rake::Task['rcov:units'].invoke
|
19
|
+
Rake::Task['rcov:functionals'].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "run general rcov tests"
|
23
|
+
task :general => RcovStats.before_rcov do
|
24
|
+
puts '** rcov:general **'
|
25
|
+
RcovStats.invoke('general')
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bartes-rcov_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bartosz Knapik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Rcov Stats provides rcov extension, so you could select test files and test covered files for units and functionals tests.
|
17
|
+
email: bartesrlz_at_gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/rcov_stats.rb
|
26
|
+
- tasks/rcov.rake
|
27
|
+
- config/rcov_standard.yml
|
28
|
+
- config/rcov_rspec.yml
|
29
|
+
- README
|
30
|
+
- init.rb
|
31
|
+
- Rakefile
|
32
|
+
- MIT-LICENSE
|
33
|
+
has_rdoc: false
|
34
|
+
homepage: http://www.lunarlogicpolska.com
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Rcov Stats provides rcov extension, so you could select test files and test covered files for units and functionals tests.
|
59
|
+
test_files: []
|
60
|
+
|