lib/lemon/coverage.rb in lemon-0.5 vs lib/lemon/coverage.rb in lemon-0.6

- old
+ new

@@ -1,27 +1,35 @@ module Lemon # class Coverage - # Paths of ruby scripts to be covered. - attr :paths + # 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. + attr :files # Conical snapshot of system (before loading libraries to be covered). attr :conical + # + attr :namespaces + # New Coverage object. # - # Coverage.new('lib/', :public => true) + # Coverage.new('lib/', :MyApp, :public => true) # - def initialize(paths, options={}) - @public = options[:public] + def initialize(files, namespaces=nil, options={}) + @namespaces = namespaces || [] - @paths = paths + @files = files @conical = snapshot - load_system + @public = options[:public] + + # this must come after concial snapshot + @suite = Test::Suite.new(files) end # Over use public methods for coverage. def public_only? @public @@ -58,26 +66,35 @@ end cover end # Iterate over +paths+ and use #load to bring in all +.rb+ scripts. - def load_system - files = [] - paths.map do |path| - if File.directory?(path) - files.concat(Dir[File.join(path, '**', '*.rb')]) - else - files.concat(Dir[path]) - end - end - files.each{ |file| load(file) } - end + #def load_system + # files = [] + # paths.map do |path| + # if File.directory?(path) + # files.concat(Dir[File.join(path, '**', '*.rb')]) + # else + # files.concat(Dir[path]) + # end + # end + # files.each{ |file| load(file) } + #end # System to be covered. This takes a sanpshot of the system - # and then removes the conical snapshot. + # and then removes the conical snapshot, and then filters out + # the namespace. + # + # TODO: Perhaps get rid of the conical subtraction and require a namespace? def system - snapshot - conical + if namespaces.empty? + snapshot - conical + else + snapshot.select do |m| + namespaces.any?{ |n| m.name.start_with?(n) } + end + end end # Produces a list of all existent Modules and Classes. def snapshot sys = [] @@ -88,24 +105,26 @@ sys << m end sys end - # TODO: option to do only do what hasn't been covered thus far - def generate(opts={}) + # TODO: combine with coverage to provided option to do only do what hasn't been covered thus far. + # TODO: support output directory + + def generate(output=nil) code = [] system.each do |base| next if base.is_a?(Lemon::Test::Suite) - code << "testcase #{base}" + code << "TestCase #{base} do" base.public_instance_methods(false).each do |meth| - code << "\n unit :#{meth} => '' do\n pending\n end" + code << "\n Unit :#{meth} => '' do\n pending\n end" end unless public_only? base.private_instance_methods(false).each do |meth| - code << "\n unit :#{meth} => '' do\n pending\n end" + code << "\n Unit :#{meth} => '' do\n pending\n end" end base.protected_instance_methods(false).each do |meth| - code << "\n unit :#{meth} => '' do\n pending\n end" + code << "\n Unit :#{meth} => '' do\n pending\n end" end end code << "\nend\n" end code.join("\n")