rcov_stats 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/README +8 -1
- data/lib/rcov_stats.rb +56 -68
- metadata +5 -5
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -6,13 +6,20 @@ RcovStats provides rcov extension, so you can select test files and test covered
|
|
6
6
|
How to install :
|
7
7
|
|
8
8
|
** for Merb:
|
9
|
-
gem install rcov_stats
|
9
|
+
gem install rcov_stats
|
10
10
|
## puts this dependency inside your config/init.rb file ##
|
11
11
|
dependency "rcov_stats"
|
12
12
|
** for Rails
|
13
13
|
## puts this into Gemfile file ##
|
14
14
|
gem "rcov_stats"
|
15
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
|
+
|
16
23
|
|
17
24
|
How to configure
|
18
25
|
|
data/lib/rcov_stats.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "erb"
|
3
3
|
require "hpricot"
|
4
|
-
|
5
|
-
class RcovStatsForErb
|
6
|
-
|
7
|
-
def initialize( options )
|
8
|
-
options.each_pair do |key, value|
|
9
|
-
instance_variable_set(:"@#{key}",value)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_binding
|
14
|
-
binding
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
4
|
+
require 'rcov_stats_related/erb_binding'
|
19
5
|
|
20
6
|
class RcovStats
|
21
7
|
|
@@ -26,25 +12,31 @@ class RcovStats
|
|
26
12
|
self.send("#{name}=", value) if value
|
27
13
|
end
|
28
14
|
|
29
|
-
cattr_accessor_with_default :is_rails,
|
30
|
-
cattr_accessor_with_default :is_merb,
|
31
|
-
|
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
|
+
|
32
24
|
cattr_accessor_with_default :rcov_stats_dir, File.dirname(__FILE__)
|
33
|
-
cattr_accessor_with_default :rcov_stats_config_file, File.join(
|
34
|
-
|
35
|
-
cattr_accessor_with_default :test_name, @@use_rspec ? "spec" : "test"
|
36
|
-
cattr_accessor_with_default :test_file_indicator, "*_#{@@test_name}.rb"
|
25
|
+
cattr_accessor_with_default :rcov_stats_config_file, File.join(root, 'config', 'rcov_stats.yml')
|
26
|
+
|
37
27
|
cattr_accessor_with_default :cover_file_indicator, "*.rb"
|
38
28
|
|
39
29
|
attr_accessor :name, :sections
|
40
30
|
|
31
|
+
|
32
|
+
|
41
33
|
def initialize(name_, sections_ = nil)
|
42
34
|
self.name = name_
|
43
35
|
self.sections = sections_.blank? ? [name_] : sections_
|
44
36
|
end
|
45
37
|
|
46
38
|
def self.get_config(option)
|
47
|
-
YAML::load(File.open(File.join(
|
39
|
+
YAML::load(File.open(File.join(root, 'config', 'rcov_stats.yml')))[option]
|
48
40
|
end
|
49
41
|
|
50
42
|
def self.before_rcov
|
@@ -68,7 +60,7 @@ class RcovStats
|
|
68
60
|
def parse_file_to_test(list)
|
69
61
|
result = []
|
70
62
|
list.each do |f|
|
71
|
-
file_list = File.directory?(File.join(
|
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)
|
72
64
|
unless (list_of_read_files = Dir[file_list]).empty?
|
73
65
|
result += list_of_read_files
|
74
66
|
end
|
@@ -79,7 +71,7 @@ class RcovStats
|
|
79
71
|
def parse_file_to_cover(list)
|
80
72
|
result = []
|
81
73
|
list.each do |f|
|
82
|
-
file_list = File.directory?(File.join(
|
74
|
+
file_list = File.directory?(File.join(self.class.root, f)) ? File.join(f, "**", self.class.cover_file_indicator) : File.join(f)
|
83
75
|
unless (list_of_read_files = Dir[file_list]).empty?
|
84
76
|
result += list_of_read_files
|
85
77
|
end
|
@@ -87,46 +79,19 @@ class RcovStats
|
|
87
79
|
result.uniq
|
88
80
|
end
|
89
81
|
|
90
|
-
def
|
91
|
-
|
92
|
-
files_to_cover_parsed = parse_file_to_cover(files_to_cover).map { |f| "(#{f})".gsub("/", "\/") }.join("|")
|
93
|
-
rcov_settings = "--sort coverage --text-summary -x \"^(?!(#{files_to_cover_parsed}))\" "
|
94
|
-
rcov_settings +="--output=#{File.join(@@root, "coverage", @name)} "
|
95
|
-
rcov_tests = parse_file_to_test(files_to_test)
|
96
|
-
return false if rcov_tests.empty?
|
97
|
-
rcov_settings += rcov_tests.join(' ')
|
98
|
-
cmd = "bundle exec rcov #{rcov_settings}"
|
99
|
-
Rake::Win32.windows? ? Rake::Win32.rake_system(cmd) : system(cmd)
|
100
|
-
end
|
101
|
-
|
102
|
-
def invoke_rcov_spec_task
|
103
|
-
require 'spec/rake/spectask'
|
104
|
-
rcov_tests = parse_file_to_test(files_to_test)
|
105
|
-
return false if rcov_tests.empty?
|
106
|
-
Spec::Rake::SpecTask.new(@name) do |t|
|
107
|
-
spec_opts = File.join(@@root, @@test_name, 'spec.opts')
|
108
|
-
t.spec_opts = ['--options', "\"#{spec_opts}\""] if File.exists?(spec_opts)
|
109
|
-
t.spec_files = rcov_tests
|
110
|
-
t.rcov = true
|
111
|
-
t.rcov_dir = File.join(@@root, "coverage", @name)
|
112
|
-
files_to_cover_parsed = parse_file_to_cover(files_to_cover).map { |f| "(#{f})".gsub("/", "\/") }.join("|")
|
113
|
-
t.rcov_opts = ["--text-summary", "--sort", "coverage", "-x", "\"^(?!(#{files_to_cover_parsed}))\""]
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def invoke
|
118
|
-
@@use_rspec ? invoke_rcov_spec_task : invoke_rcov_task
|
82
|
+
def test_file_indicator
|
83
|
+
"*_#{test_name}.rb"
|
119
84
|
end
|
120
85
|
|
121
86
|
def generate_index
|
122
|
-
Dir[File.join(
|
123
|
-
FileUtils.
|
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))
|
124
90
|
end
|
125
91
|
|
126
|
-
|
127
|
-
|
128
92
|
@sections.each do |i|
|
129
|
-
|
93
|
+
FileUtils.mkdir_p File.join(self.class.root, 'coverage', i)
|
94
|
+
coverage_index = File.join(self.class.root, 'coverage', i, "index.html")
|
130
95
|
next unless File.exists?(coverage_index)
|
131
96
|
doc = open(coverage_index) { |f| Hpricot(f) }
|
132
97
|
footer_tts = doc.search("//tfoot/tr/td//tt")
|
@@ -145,23 +110,46 @@ class RcovStats
|
|
145
110
|
template_object["generated_on"] = "Generated on #{Time.now}"
|
146
111
|
|
147
112
|
|
148
|
-
template_source = ERB.new(IO.read(File.join(
|
113
|
+
template_source = ERB.new(IO.read(File.join(self.class.root, 'coverage', "index.html")))
|
149
114
|
|
150
|
-
File.open(File.join(
|
151
|
-
f.write( template_source.result(
|
115
|
+
File.open(File.join(self.class.root, 'coverage', "index.html"), "w+") do |f|
|
116
|
+
f.write( template_source.result(RcovStatsRelated::ErbBinding.new(template_object).get_binding))
|
152
117
|
end
|
153
118
|
end
|
154
119
|
end
|
155
120
|
|
121
|
+
def bundler?
|
122
|
+
File.exist?("./Gemfile")
|
123
|
+
end
|
124
|
+
|
156
125
|
def self.setup
|
157
|
-
if
|
158
|
-
Merb::Plugins.add_rakefiles(File.join(
|
126
|
+
if is_merb
|
127
|
+
Merb::Plugins.add_rakefiles(File.join(rcov_stats_dir, "rcov_stats_tasks"))
|
159
128
|
end
|
160
|
-
|
161
|
-
|
162
|
-
|
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)
|
163
148
|
end
|
164
149
|
end
|
165
150
|
end
|
166
151
|
|
167
|
-
|
152
|
+
|
153
|
+
RcovStats.setup
|
154
|
+
|
155
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcov_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Knapik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-15 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|