Class: Lemon::CoverageAnalyzer
- Inherits:
-
Object
- Object
- Lemon::CoverageAnalyzer
- Defined in:
- lib/lemon/coverage/analyzer.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Paths of lemon tests and/or ruby scripts to be compared and covered.
-
#format ⇒ Object
readonly
Report format.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
-
#calculate ⇒ Object
Trigger a full set of calculations.
- #canonical ⇒ Object
- #canonical_cases ⇒ Object
- #covered_namespaces ⇒ Object
- #covered_unit(test, list) ⇒ Object
- #covered_units ⇒ Object (also: #covered)
-
#current ⇒ Object
Current system snapshot.
-
#each(&block) ⇒ Object
Iterate over covered units.
-
#initialize(files, options = {}) ⇒ CoverageAnalyzer
constructor
New Coverage object.
-
#initialize_prerequisites(options) ⇒ Object
Load in prerequisites.
- #private? ⇒ Boolean
-
#public_only? ⇒ Boolean
Only use public methods for coverage.
- #render ⇒ Object
-
#reporter ⇒ Object
All output is handled by a reporter.
-
#reset! ⇒ Object
Reset coverage data for recalcuation.
- #reset_suite ⇒ Object
-
#size ⇒ Object
Number of covered units.
- #suite ⇒ Object
- #suite=(suite) ⇒ Object
-
#target ⇒ Object
Target system snapshot.
- #target_namespaces ⇒ Object
-
#uncovered_cases ⇒ Object
List of modules/classes not covered.
- #uncovered_system ⇒ Object
- #uncovered_units ⇒ Object (also: #uncovered)
- #undefined_units ⇒ Object (also: #undefined)
-
#zealous? ⇒ Boolean
Include methods of uncovered cases in uncovered units.
Constructor Details
#initialize(files, options = {}) ⇒ CoverageAnalyzer
New Coverage object.
CoverageAnalyzer.new(suite, :MyApp, :public => true)
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 62 63 64 |
# File 'lib/lemon/coverage/analyzer.rb', line 31 def initialize(files, ={}) @files = files @namespaces = [[:namespaces]].flatten.compact @private = [:private] @format = [:format] @zealous = [:zealous] @reporter = reporter_find(@format) reset_suite initialize_prerequisites() @canonical = Snapshot.capture #system #@suite.canonical #@suite = Lemon.suite #@suite = Lemon::TestSuite.new(files, :cover=>true) #@suite = suite #Lemon.suite = @suite files = files.map{ |f| Dir[f] }.flatten files = files.map{ |f| if File.directory?(f) Dir[File.join(f, '**/*.rb')] else f end }.flatten.uniq files = files.map{ |f| File.(f) } files.each{ |s| load s } #require s } @suite = $TEST_SUITE.dup end |
Instance Attribute Details
#files ⇒ Object (readonly)
Paths of lemon tests and/or ruby scripts to be compared and covered. This can include directories too, in which case all .rb scripts below then directory will be included.
88 89 90 |
# File 'lib/lemon/coverage/analyzer.rb', line 88 def files @files end |
#format ⇒ Object (readonly)
Report format.
94 95 96 |
# File 'lib/lemon/coverage/analyzer.rb', line 94 def format @format end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
97 98 99 |
# File 'lib/lemon/coverage/analyzer.rb', line 97 def namespaces @namespaces end |
Instance Method Details
#calculate ⇒ Object
Trigger a full set of calculations.
137 138 139 |
# File 'lib/lemon/coverage/analyzer.rb', line 137 def calculate uncovered_cases # that should be all it takes end |
#canonical ⇒ Object
100 101 102 |
# File 'lib/lemon/coverage/analyzer.rb', line 100 def canonical @canonical #= Snapshot.capture end |
#canonical_cases ⇒ Object
223 224 225 |
# File 'lib/lemon/coverage/analyzer.rb', line 223 def canonical_cases @canonical_cases ||= canonical.units.map{ |u| u.namespace }.uniq end |
#covered_namespaces ⇒ Object
171 172 173 |
# File 'lib/lemon/coverage/analyzer.rb', line 171 def covered_namespaces @covered_namespaces ||= covered_units.map{ |u| u.namespace }.uniq end |
#covered_unit(test, list) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/lemon/coverage/analyzer.rb', line 153 def covered_unit(test, list) case test when Lemon::TestModule test.each do |t| covered_unit(t, list) end when Lemon::TestMethod list << Snapshot::Unit.new( test.context.target, test.target, :function=>test.function? ) else # ignore end end |
#covered_units ⇒ Object Also known as: covered
142 143 144 145 146 147 148 149 150 |
# File 'lib/lemon/coverage/analyzer.rb', line 142 def covered_units @covered_units ||= ( list = [] suite.each do |test| covered_unit(test, list) end list.uniq ) end |
#current ⇒ Object
Current system snapshot.
186 187 188 |
# File 'lib/lemon/coverage/analyzer.rb', line 186 def current @current ||= Snapshot.capture end |
#each(&block) ⇒ Object
Iterate over covered units.
244 245 246 |
# File 'lib/lemon/coverage/analyzer.rb', line 244 def each(&block) covered_units.each(&block) end |
#initialize_prerequisites(options) ⇒ Object
Load in prerequisites
67 68 69 70 71 72 73 |
# File 'lib/lemon/coverage/analyzer.rb', line 67 def initialize_prerequisites() loadpath = [[:loadpath] || []].compact.flatten requires = [[:requires] || []].compact.flatten loadpath.each{ |path| $LOAD_PATH.unshift(path) } requires.each{ |path| require(path) } end |
#private? ⇒ Boolean
116 117 118 |
# File 'lib/lemon/coverage/analyzer.rb', line 116 def private? @private end |
#public_only? ⇒ Boolean
Only use public methods for coverage.
111 112 113 |
# File 'lib/lemon/coverage/analyzer.rb', line 111 def public_only? !@private end |
#render ⇒ Object
331 332 333 |
# File 'lib/lemon/coverage/analyzer.rb', line 331 def render reporter.render end |
#reporter ⇒ Object
All output is handled by a reporter.
336 337 338 |
# File 'lib/lemon/coverage/analyzer.rb', line 336 def reporter @reporter ||= reporter_find(format) end |
#reset! ⇒ Object
Reset coverage data for recalcuation.
233 234 235 236 237 238 239 240 241 |
# File 'lib/lemon/coverage/analyzer.rb', line 233 def reset! @covered_units = nil @covered_namespaces = nil @target_namespaces = nil @uncovered_units = nil @undefined_units = nil @target = nil @current = nil end |
#reset_suite ⇒ Object
76 77 78 |
# File 'lib/lemon/coverage/analyzer.rb', line 76 def reset_suite $TEST_SUITE = [] end |
#size ⇒ Object
Number of covered units.
249 250 251 |
# File 'lib/lemon/coverage/analyzer.rb', line 249 def size covered_units.size end |
#suite ⇒ Object
81 82 83 |
# File 'lib/lemon/coverage/analyzer.rb', line 81 def suite @suite end |
#suite=(suite) ⇒ Object
105 106 107 108 |
# File 'lib/lemon/coverage/analyzer.rb', line 105 def suite=(suite) raise ArgumentError unless TestSuite === suite @suite = suite end |
#target ⇒ Object
Target system snapshot.
181 182 183 |
# File 'lib/lemon/coverage/analyzer.rb', line 181 def target @target ||= Snapshot.capture(target_namespaces) end |
#target_namespaces ⇒ Object
176 177 178 |
# File 'lib/lemon/coverage/analyzer.rb', line 176 def target_namespaces @target_namespaces ||= filter(covered_namespaces) end |
#uncovered_cases ⇒ Object
List of modules/classes not covered.
209 210 211 212 213 214 215 |
# File 'lib/lemon/coverage/analyzer.rb', line 209 def uncovered_cases @uncovered_cases ||= ( list = current.units - (target.units + canonical.units) list = list.map{ |u| u.namespace }.uniq list - canonical_cases ) end |
#uncovered_system ⇒ Object
218 219 220 |
# File 'lib/lemon/coverage/analyzer.rb', line 218 def uncovered_system @uncovered_system ||= Snapshot.capture(uncovered_cases) end |
#uncovered_units ⇒ Object Also known as: uncovered
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/lemon/coverage/analyzer.rb', line 191 def uncovered_units @uncovered_units ||= ( units = target.units if public_only? units = units.select{ |u| u.public? } end units -= (covered_units + canonical.units) units += uncovered_system.units if zealous? units ) end |
#undefined_units ⇒ Object Also known as: undefined
204 205 206 |
# File 'lib/lemon/coverage/analyzer.rb', line 204 def undefined_units @undefined_units ||= covered_units - target.units end |
#zealous? ⇒ Boolean
Include methods of uncovered cases in uncovered units.
121 122 123 |
# File 'lib/lemon/coverage/analyzer.rb', line 121 def zealous? @zealous end |