Class: Teststats::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/teststats/cli.rb

Constant Summary collapse

DEFAULTS =
{
  'test_unit' => {
    :pattern => '*_test.rb',
    :directory => 'test'
  },
  'rspec' => {
    :pattern => '*_spec.rb',
    :directory => 'spec'
  }
}

Instance Method Summary collapse

Instance Method Details

#countObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/teststats/cli.rb', line 25

def count
  Dir.chdir(options[:repository]) do
    validate!
    f = framework
    current_branch = `git rev-parse --abbrev-ref HEAD`
    puts "Working on branch #{current_branch}"
    puts "List revisions"
    rev_list = `git log --pretty=tformat:%H,%aI -- #{f.directory}`.split("\n")
    puts "Found #{rev_list.size} revisions"

    data = {}
    rev_list.each do |rev|
      hash, date = rev.split(',')
      date = date.split('T')[0]
      next if data.has_key?(date)

      `git checkout -q -f #{hash}`
      files = Dir[f.test_files]
      puts "#{hash[0..8]} #{date} #{files.size} test files"
      data[date] = files.map(&f.count).reduce(:+).to_i
    end
    `git checkout #{current_branch}`
    output(data.to_a.sort_by{|d|d[0]})
  end
end