cover-up 0.1 → 0.2
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/lib/cover-up.rb +17 -10
- metadata +2 -2
data/lib/cover-up.rb
CHANGED
@@ -57,14 +57,14 @@ module CoverUp
|
|
57
57
|
|
58
58
|
# This calculates the percentage of lines that were hit by the code being covered
|
59
59
|
def hit_percentage
|
60
|
-
return 0 if self.
|
61
|
-
(self.hit.length.to_f / self.
|
60
|
+
return 0 if self.lines_without_exclusions.to_f == 0.0
|
61
|
+
(self.hit.length.to_f / self.lines_without_exclusions.to_f) * 100.0
|
62
62
|
end
|
63
63
|
|
64
64
|
# This calculates the percentage of lines that were missed by the code being covered
|
65
65
|
def missed_percentage
|
66
|
-
return 0 if self.
|
67
|
-
(self.missed.length.to_f / self.
|
66
|
+
return 0 if self.lines_without_exclusions.to_f == 0.0
|
67
|
+
(self.missed.length.to_f / self.lines_without_exclusions.to_f) * 100.0
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -77,11 +77,12 @@ def coverage(options = {}, &block)
|
|
77
77
|
trace = {}
|
78
78
|
# Let's set a trace function so that every method call can be tracked
|
79
79
|
set_trace_func(proc do |event, file, line, id, binding, klass|
|
80
|
-
#
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
80
|
+
# Ignore certain trace events that we aren't interested in
|
81
|
+
next if event == 'c-call' || event == 'c-return' || event == 'class' || event == 'end'
|
82
|
+
# We log the line, if we were given a logger block that can deal with it
|
83
|
+
options[:logger].call(event, file, line, id, binding, klass) unless options[:logger].nil?
|
84
|
+
# Add the line number that was hit for this file
|
85
|
+
(trace[file] ||= []) << line
|
85
86
|
end)
|
86
87
|
# Now that we've set up the trace function, we can execute the code (trapping any exceptions)
|
87
88
|
begin
|
@@ -91,6 +92,12 @@ def coverage(options = {}, &block)
|
|
91
92
|
end
|
92
93
|
# Once that's run, we stop the trace function
|
93
94
|
set_trace_func(nil)
|
95
|
+
# Now let's expand upon any paths in the trace, and make sure we remove duplicate lines
|
96
|
+
coverage = {}
|
97
|
+
trace.keys.each do |key|
|
98
|
+
coverage[File.expand_path(key)] = trace[key].uniq
|
99
|
+
end
|
100
|
+
trace = nil
|
94
101
|
# Now we collate the results
|
95
102
|
results = []
|
96
103
|
# Loop through all files
|
@@ -111,7 +118,7 @@ def coverage(options = {}, &block)
|
|
111
118
|
# If the line is a comment or an empty line, or it's the last line and it's "end", it's excluded
|
112
119
|
if line.strip[0...1] == "#" || line.strip.empty? || (number == lines.length && line.strip == "end")
|
113
120
|
excluded << number
|
114
|
-
elsif (
|
121
|
+
elsif (coverage[file] || []).include?(number)
|
115
122
|
# Otherwise, if it was in the trace, it was hit
|
116
123
|
hit << number
|
117
124
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cover-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- El Draper
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-18 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|