Revisions

gist: 152937 Download_button fork
public
Public Clone URL: git://gist.github.com/152937.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Rakefile
 
task :stats => "stats:stats_fix"
namespace :stats do
  # Fix statistics calculation to allow file type regex be included
  task :stats_fix do
    require "code_statistics"
    class CodeStatistics
      private
      def calculate_statistics
        @pairs.inject({}) do |stats, pair|
          stats[pair[0]] = calculate_directory_statistics(pair[1], pair[2])
          stats
        end
      end
 
      def calculate_directory_statistics_with_override(directory, pattern = nil)
        calculate_directory_statistics_without_override(directory, pattern || /.*\.rb$/)
      end
 
      alias_method_chain :calculate_directory_statistics, :override
    end
  end
end
 
task :stats => "stats:include_views"
namespace :stats do
  task :include_views do
    require "code_statistics"
    location_to_insert = 0
    ::STATS_DIRECTORIES.each_with_index do |dir, idx|
      location_to_insert = (idx + 1) if dir.first == "Models"
    end
    ::STATS_DIRECTORIES.insert location_to_insert, ["Views", "app/views", /.*\.erb$/]
  end
end
 
# lib/tasks/cucumber.rake
task :stats => "stats:include_cucumber"
 
namespace :stats do
  # Setup specs for stats
  task :include_cucumber do
    require 'code_statistics'
    if File.exist?("features")
      ::STATS_DIRECTORIES << ["Cucumber coverage", "features", /.+\.feature$/]
      ::CodeStatistics::TEST_TYPES << "Cucumber coverage"
    end
  end
end