Class: CodeStatistics::CodeStatistics

Inherits:
Object
  • Object
show all
Defined in:
lib/code_statistics/code_statistics.rb

Overview

:nodoc:

Constant Summary collapse

TEST_TYPES =
%w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)

Instance Method Summary collapse

Constructor Details

#initialize(*pairs) ⇒ CodeStatistics

Returns a new instance of CodeStatistics.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/code_statistics/code_statistics.rb', line 7

def initialize(*pairs)
  @pairs       = pairs
  @test_types  = []
  directory    = Dir.pwd
  @specs_found = false
  #todo for both spec and test look through top level add any directory seperately
  #get rid of the hard coded test/units / etc in this file and the rakefile.
  add_test_type("Model specs") if local_file_exists?(directory, 'spec/models')
  add_test_type("View specs") if local_file_exists?(directory, 'spec/views')
  add_test_type("Controller specs") if local_file_exists?(directory, 'spec/controllers')
  add_test_type("Helper specs") if local_file_exists?(directory, 'spec/helpers')
  add_test_type("Library specs") if local_file_exists?(directory, 'spec/lib')
  add_test_type("Routing specs") if local_file_exists?(directory, 'spec/routing')
  add_test_type("Integration specs") if local_file_exists?(directory, 'spec/integration')
  add_test_type("Public specs") if local_file_exists?(directory, 'spec/public')
  add_test_type("Semipublic specs") if local_file_exists?(directory, 'spec/semipublic')
  if @specs_found==false && local_file_exists?(directory, 'spec')
    @pairs << %w(Specs spec)
    add_test_type("Specs")
  end
  if local_file_exists?(directory, 'test') &&
      (!local_file_exists?(directory, 'test/unit') &&
       !local_file_exists?(directory, 'test/functional') &&
       !local_file_exists?(directory, 'test/integration'))
    @pairs << %w(Tests test)
    add_test_type("Tests")
  end
  @statistics  = calculate_statistics
  @total       = calculate_total if pairs.length > 1
end

Instance Method Details

#to_sObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/code_statistics/code_statistics.rb', line 38

def to_s
  print_header
  @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
  print_splitter
  
  if @total
    print_line("Total", @total)
    print_splitter
  end
  
  print_code_test_stats
end