class RailsStats::SpecStatistics

Constants

SPEC_FOLDERS

Attributes

statistics[R]
test[R]
total[R]

Public Class Methods

new(directory, key_concepts) click to toggle source
# File lib/rails_stats/spec_statistics.rb, line 18
def initialize(directory, key_concepts)
  @test = true
  @directory    = directory
  @key_concepts = key_concepts
  @statistics   = calculate_statistics
  @total        = calculate_total
end

Private Instance Methods

calculate_statistics() click to toggle source
# File lib/rails_stats/spec_statistics.rb, line 36
def calculate_statistics
  out = {}
  categorize_files.each do |key, list|
    out[key] = Util.calculate_file_statistics(list)
  end 
  out
end
calculate_total() click to toggle source
# File lib/rails_stats/spec_statistics.rb, line 28
def calculate_total
  out = CodeStatisticsCalculator.new(true)
  @statistics.each do |key, stats|
    out.add(stats)
  end
  out
end
categorize_file(file_path) click to toggle source
# File lib/rails_stats/spec_statistics.rb, line 60
def categorize_file(file_path)
  types = (@key_concepts + SPEC_FOLDERS).uniq
  types.each do |folder|
    if file_path =~ /\/#{folder}\//
      folder = Inflector.humanize(folder)
      folder = Inflector.titleize(folder)
      folder = Inflector.singularize(folder)
      return "#{folder} Tests"
    end
  end

  # something else
  return "Other Tests"
end
categorize_files() click to toggle source
# File lib/rails_stats/spec_statistics.rb, line 44
def categorize_files
  out = {}
  Dir[File.join(@directory, "**", "*.rb")].each do |file_path|
    if file_path =~ /.*_spec.rb$/
      key = categorize_file(file_path)
    else
      key = "Spec Support"
    end

    out[key] ||= []
    out[key]  << file_path
  end

  out
end