rcov_stats 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
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,46 @@
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
+ 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 (from github)
12
+ or gem install rcov_stats (from gemcutter)
13
+
14
+ cd your_application
15
+ a) as a unpacked gem or bundler gem
16
+ rake gems:unpack GEM=bartes-rcov_stats
17
+ add in RakeFile.rb :
18
+ import(File.join(File.dirname(__FILE__),'vendor','gems',"bartes-rcov_stats*",'tasks','*.rake'))
19
+ 3) As a gem for Merb:
20
+ gem install bartes-rcov_stats
21
+ a) standard inside your config/init.rb : dependency "bartes-rcov_stats" , :require_as => 'rcov_stats' dependency
22
+ b) with bundler in Gemfile : gem "bartes-rcov_stats" , :require_as => 'rcov_stats'
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
+ You can grab rcov gem with :
43
+ gem install relevance-rcov
44
+
45
+
46
+ Copyright (c) 2009 [bartes], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ Dir['tasks/*.rake'].each { |f| import f }
5
+
6
+
7
+
8
+
9
+
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,11 @@
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
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rcov_stats'
2
+
data/lib/rcov_stats.rb ADDED
@@ -0,0 +1,189 @@
1
+ module RcovStats
2
+
3
+ class << self
4
+
5
+ def plugin_root
6
+ File.join(File.dirname(__FILE__),'..')
7
+ end
8
+
9
+ def is_rails?
10
+ Object.const_defined?('RAILS_ROOT')
11
+ end
12
+
13
+ def is_merb?
14
+ Object.const_defined?('Merb')
15
+ end
16
+
17
+ def root
18
+ root_dir = RAILS_ROOT if is_rails?
19
+ root_dir = Merb.root if is_merb?
20
+ root_dir
21
+ end
22
+
23
+ def get_config(name)
24
+ YAML::load(File.open(File.join(root ,'config','rcov_stats.yml')))[name]
25
+ end
26
+
27
+ def get_array_data(name)
28
+ (get_config(name) || []).reject{|d| d.blank?}.uniq
29
+ end
30
+
31
+ def units_files_to_cover
32
+ get_array_data "units_files_to_cover"
33
+ end
34
+
35
+ def functionals_files_to_cover
36
+ get_array_data "functionals_files_to_cover"
37
+ end
38
+
39
+ def units_files_to_test
40
+ get_array_data "units_files_to_test"
41
+ end
42
+
43
+ def functionals_files_to_test
44
+ get_array_data "functionals_files_to_test"
45
+ end
46
+
47
+ def igonored_paths
48
+ %w(. .. .svn)
49
+ end
50
+
51
+ def test_file_indicator
52
+ "*_#{test_name}.rb"
53
+ end
54
+
55
+ def before_rcov
56
+ (pre_rcov = get_config("before_rcov")).blank? ? nil : pre_rcov
57
+ end
58
+
59
+ def use_rspec?
60
+ File.exists?(File.join(root, 'spec'))
61
+ end
62
+
63
+ def test_name
64
+ use_rspec? ? "spec" : "test"
65
+ end
66
+
67
+ def parse_file_to_test(file_list)
68
+ rcov_tests = []
69
+ file_list.each do |f|
70
+ dir_or_file = File.join(root, test_name,f)
71
+ next unless File.exists?(dir_or_file)
72
+ unless File.directory?(dir_or_file)
73
+ rcov_tests << File.join(dir_or_file)
74
+ else
75
+ sub_elements = Dir.entries(dir_or_file) - igonored_paths
76
+ next if sub_elements.size.zero?
77
+ main_tests_not_included = true
78
+ sub_elements.each do |sub_element|
79
+ if File.directory?(File.join(dir_or_file,sub_element))
80
+ rcov_tests << File.join(dir_or_file,sub_element,test_file_indicator)
81
+ elsif main_tests_not_included
82
+ rcov_tests << File.join(dir_or_file,test_file_indicator)
83
+ main_tests_not_included = false
84
+ end
85
+ end
86
+ end
87
+ end
88
+ rcov_tests
89
+ end
90
+
91
+ def parse_file_to_cover(file_list)
92
+ rcov_covers = []
93
+ file_list.each do |f|
94
+ dir_or_file = File.join(root,f)
95
+ next unless File.exists?(dir_or_file)
96
+ unless File.directory?(dir_or_file)
97
+ rcov_covers << f
98
+ else
99
+ sub_elements = Dir.entries(dir_or_file) - igonored_paths
100
+ next if sub_elements.size.zero?
101
+ main_tests_not_included = true
102
+ sub_elements.each do |sub_element|
103
+ if File.directory?(File.join(dir_or_file,sub_element))
104
+ rcov_covers << File.join(f,sub_element)
105
+ elsif main_tests_not_included
106
+ rcov_covers << File.join(f)
107
+ main_tests_not_included = false
108
+ end
109
+ end
110
+ end
111
+ end
112
+ rcov_covers
113
+ end
114
+
115
+ def invoke_rcov_task(options)
116
+ require 'rake/win32'
117
+ files_to_cover = parse_file_to_cover(options[:files_to_cover].uniq).map{|f| "(#{f})".gsub("/","\/")}.join("|")
118
+ rcov_settings = "--sort coverage --text-summary -x \"^(?!(#{files_to_cover}))\" "
119
+ rcov_settings +="--output=#{File.join(root,"coverage",options[:output])} " if options[:output]
120
+ rcov_tests = parse_file_to_test(options[:files_to_test].uniq)
121
+ return false if rcov_tests.empty?
122
+ rcov_settings += rcov_tests.join(' ')
123
+ cmd = "rcov #{rcov_settings}"
124
+ Rake::Win32.windows? ? Rake::Win32.rake_system(cmd) : system(cmd)
125
+ end
126
+
127
+ def invoke_rcov_spec_task(options)
128
+ require 'spec/rake/spectask'
129
+ rcov_tests = parse_file_to_test(options[:files_to_test].uniq)
130
+ return false if rcov_tests.empty?
131
+ Spec::Rake::SpecTask.new(options[:name]) do |t|
132
+ spec_opts = File.join(root,'spec','spec.opts')
133
+ t.spec_opts = ['--options', "\"#{spec_opts}\""] if File.exists?(spec_opts)
134
+ t.spec_files = rcov_tests
135
+ t.rcov = true
136
+ t.rcov_dir = File.join(root,"coverage",options[:output]) if options[:output]
137
+ files_to_cover = parse_file_to_cover(options[:files_to_cover].uniq).map{|f| "(#{f})".gsub("/","\/")}.join("|")
138
+ t.rcov_opts = ["--text-summary","--sort","coverage","-x","\"^(?!(#{files_to_cover}))\""]
139
+ end
140
+ end
141
+
142
+ def invoke(type)
143
+ options = {}
144
+ case type.to_s
145
+ when "units"
146
+ options[:name] = "rcov:units"
147
+ options[:files_to_cover] = units_files_to_cover
148
+ options[:files_to_test] = units_files_to_test
149
+ options[:output] = "units"
150
+ when "functionals"
151
+ options[:name] = "rcov:functionals"
152
+ options[:files_to_cover] = functionals_files_to_cover
153
+ options[:files_to_test] = functionals_files_to_test
154
+ options[:output] = "functionals"
155
+ when "general"
156
+ options[:name] = "rcov:general"
157
+ options[:files_to_cover] = units_files_to_cover + functionals_files_to_cover
158
+ options[:files_to_test] = units_files_to_test + functionals_files_to_test
159
+ options[:output] = nil
160
+ else
161
+ raise "Not implemented task for that rcov #{type}"
162
+ end
163
+ use_rspec? ? invoke_rcov_spec_task(options) : invoke_rcov_task(options)
164
+ end
165
+ end
166
+
167
+ end
168
+
169
+ require 'fileutils'
170
+
171
+ unless Object.const_defined?('RCOV_STATS_ROOT')
172
+ RCOV_STATS_ROOT = RAILS_ROOT if RcovStats.is_rails?
173
+ RCOV_STATS_ROOT = Merb.root if RcovStats.is_merb?
174
+ if RcovStats.is_merb?
175
+ Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__),"rcov_stats_tasks"))
176
+ end
177
+ end
178
+
179
+
180
+ file_path = File.dirname(__FILE__)
181
+ config_file = File.join(RCOV_STATS_ROOT,'config','rcov_stats.yml')
182
+
183
+ unless File.exists?(config_file)
184
+ use_rspec = File.exists?(File.join(RCOV_STATS_ROOT, 'spec'))
185
+ config_file_base = (use_rspec ? 'rcov_rspec' : 'rcov_standard') + '.yml'
186
+ FileUtils.cp(File.join(file_path, '..','config', config_file_base), config_file)
187
+ end
188
+
189
+
@@ -0,0 +1,27 @@
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.invoke('units')
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.invoke('functionals')
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
+ end
21
+
22
+ desc "run general rcov tests"
23
+ task(RcovStats.before_rcov ? ({:general => RcovStats.before_rcov}) : :general ) do
24
+ puts '** rcov:general **'
25
+ RcovStats.invoke('general')
26
+ end
27
+ end
data/tasks/rcov.rake ADDED
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), "../lib/rcov_stats_tasks")
2
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcov_stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.6
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 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rcov
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Rcov Stats provides rcov extension, so you could select test files and test covered files for units and functionals tests.
26
+ email: bartesrlz_at_gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/rcov_stats.rb
35
+ - lib/rcov_stats_tasks.rb
36
+ - tasks/rcov.rake
37
+ - config/rcov_standard.yml
38
+ - config/rcov_rspec.yml
39
+ - README
40
+ - init.rb
41
+ - Rakefile
42
+ - MIT-LICENSE
43
+ has_rdoc: true
44
+ homepage: http://www.lunarlogicpolska.com
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Rcov Stats provides rcov extension, so you could select test files and test covered files for units and functionals tests.
71
+ test_files: []
72
+