class Lemon::Generator
Test Scaffold Generator
.
Attributes
files[R]
group[R]
Group tests by `:case` or `:file`.
namespaces[R]
List of class and module namespaces to limit scaffolding.
tests[R]
Public Class Methods
new(options={})
click to toggle source
New Scaffold Generator
.
@option options [Array] :files
Ruby scripts for which to generate tests.
@option options [Array] :tests
Test files that already exist.
@option options [Array] :namespaces
List of class/module names to limit scaffolding.
@option options [Boolean] :private
Include private methods in scaffolding.
@option options [Symbol] :group
Group by `:case` or by `:file`.
# File lib/lemon/coverage/generator.rb, line 29 def initialize(options={}) @files = options[:files] || [] @tests = options[:tests] || [] @group = options[:group] || :case @namespaces = options[:namespaces] #@coverage = options[:coverage] @private = options[:private] @caps = options[:caps] #if @namespaces # @coverage ||= :all #else # @coverage ||= :uncovered #end #@snapshot = Snapshot.capture @analyzer = CoverageAnalyzer.new(files + tests, options) @suite = @analyzer.suite end
Public Instance Methods
analyzer()
click to toggle source
Returns CoverageAnalyzer
instance.
# File lib/lemon/coverage/generator.rb, line 74 def analyzer @analyzer end
filter(units)
click to toggle source
Filter targets to include only specified namespaces.
# File lib/lemon/coverage/generator.rb, line 145 def filter(units) return units if namespaces.nil? or namespaces.empty? units.select do |u| namespaces.any? do |ns| /^#{ns}/ =~ u.namespace.to_s end end end
generate()
click to toggle source
Generate test template(s).
# File lib/lemon/coverage/generator.rb, line 91 def generate render_map = {} if tests.empty? grouped_units.each do |group, units| units = filter(units) render_map[group] = render(units) end else uncovered_units = analyzer.uncovered grouped_units.each do |group, units| units = filter(units) units = units & uncovered_units render_map[group] = render(units) end #when :covered # covered_units = analyzer.target.units # grouped_units.each do |group, units| # units = filter(units) # units = units & covered_units # map[group] = render(units) # end #else # #units = Snapshot.capture(namespaces).units # #units = (units - @snapshot.units) end render_map end
grouped_units()
click to toggle source
Units in groups, by file or by case.
# File lib/lemon/coverage/generator.rb, line 79 def grouped_units case group when :case units_by_case when :file units_by_file else units_by_case # default ? end end
private?()
click to toggle source
Include private and protected methods.
# File lib/lemon/coverage/generator.rb, line 69 def private? @private end
render(units)
click to toggle source
Generate code template.
# File lib/lemon/coverage/generator.rb, line 155 def render(units) code = [] mods = units.group_by{ |u| u.namespace } mods.each do |mod, units| code << "#{term_case} #{mod} do" units.each do |unit| next unless private? or unit.public? if unit.singleton? code << "\n #{term_class_method} :#{unit.method} do" code << "\n test '' do" code << "\n end" code << "\n end" else code << "\n #{term_method} :#{unit.method} do" code << "\n test '' do" code << "\n end" code << "\n end" end end code << "\nend\n" end code.join("\n") end
term_case()
click to toggle source
# File lib/lemon/coverage/generator.rb, line 180 def term_case @caps ? 'TestCase' : 'test_case' end
term_class_method()
click to toggle source
# File lib/lemon/coverage/generator.rb, line 185 def term_class_method @caps ? 'ClassMethod' : 'class_method' end
term_method()
click to toggle source
# File lib/lemon/coverage/generator.rb, line 190 def term_method @caps ? 'Method' : 'method' end
units_by_case()
click to toggle source
# File lib/lemon/coverage/generator.rb, line 126 def units_by_case units = [] files.each do |file| units.concat SourceParser.parse_units(File.read(file)) end units.group_by{ |u| u.namespace } end
units_by_file()
click to toggle source
# File lib/lemon/coverage/generator.rb, line 135 def units_by_file map = {} files.each do |file| units = SourceParser.parse_units(File.read(file)) map[file] = units end map end