p8-metric_fu 0.9.0.6 → 0.9.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +1,119 @@
1
1
  module MetricFu
2
2
 
3
3
  def self.generate_heckle_report
4
- Heckle.generate_report
5
- system("open #{Heckle.metric_dir}/index.html") if open_in_browser?
4
+ Heckle::Generator.generate_report
5
+ system("open #{Heckle::Generator.metric_dir}/index.html") if open_in_browser?
6
6
  end
7
+
8
+ module Heckle
7
9
 
8
- class Heckle < Base::Generator
9
-
10
- def analyze
11
- files_to_heckle = MetricFu.heckle[:dirs_to_heckle].map{|dir| Dir[File.join(dir, "**/*.rb")] }
12
- class_names = files_to_heckle.flatten.collect do |f|
13
- buffer = open(f).readlines.join("\n")
14
- outline = buffer.scan(/class\s+([\w|:]*)+?/)
15
- klass = path_to_classname(f).split('::').last
16
- end
17
- class_names.flatten!
18
- output = ''
19
- ObjectSpace.each_object(Class) do |klass|
20
- class_names.each do |name|
21
- if klass.name =~ /::#{name}$/
22
- res = `heckle #{name} -t spec/**/#{name}_spec.rb`
23
- output << res
10
+ class Generator < Base::Generator
11
+
12
+ def analyze
13
+ files_to_heckle = MetricFu.heckle[:dirs_to_heckle].map{|dir| Dir[File.join(dir, "**/*.rb")] }
14
+ class_names = files_to_heckle.flatten.collect do |f|
15
+ buffer = open(f).readlines.join("\n")
16
+ outline = buffer.scan(/class\s+([\w|:]*)+?/)
17
+ klass = path_to_classname(f).split('::').last
18
+ end
19
+ class_names.flatten!
20
+ output = {}
21
+ ObjectSpace.each_object(Class) do |klass|
22
+ class_names.each do |name|
23
+ if klass.name =~ /::#{name}$/
24
+ output[name] = `heckle #{name} -t spec/**/#{underscore(name)}_spec.rb`
25
+ end
26
+ end
27
+ end
28
+
29
+ @pages = []
30
+ output.each_pair do |name, content|
31
+ page = Page.new(content)
32
+ if page
33
+ page.filename = name
34
+ @pages << page
24
35
  end
25
36
  end
37
+ generate_pages
38
+ end
39
+
40
+ def generate_pages
41
+ @pages.each do |page|
42
+ #unless MetricFu::MD5Tracker.file_already_counted?(page.filename)
43
+ generate_page(page)
44
+ #end
45
+ end
46
+ save_html(ERB.new(File.read(template_file)).result(binding))
26
47
  end
27
- @matches = output.chomp.split("\n\n").map{|m| m.split("\n") }
28
- end
29
48
 
30
- def path_to_classname(s)
31
- f = s.sub(/^lib/, '').sub(/\.rb$/, '').split('/')
32
- f = f.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
33
- f.join('::')
49
+ def generate_page(page)
50
+ save_html(page.to_html, page.path)
51
+ end
52
+
53
+ def path_to_classname(s)
54
+ f = s.sub(/^lib/, '').sub(/\.rb$/, '').split('/')
55
+ f = f.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
56
+ f.join('::')
57
+ end
58
+
59
+ def underscore(camel_cased_word)
60
+ camel_cased_word.to_s.gsub(/::/, '/').
61
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
62
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
63
+ gsub("-", "_").
64
+ downcase
65
+ end
66
+
67
+ def self.template_name
68
+ "heckle"
69
+ end
70
+
34
71
  end
35
72
 
73
+ class Page < MetricFu::Base::Generator
74
+ attr_accessor :filename, :content, :mutations, :score
75
+
76
+ def initialize(content)
77
+ @content = parse(content)
78
+ end
79
+
80
+ def parse(content)
81
+ split_content = content.split("\n\n")
82
+ method = split_content.shift
83
+ split_content.shift
84
+ doc = split_content.shift
85
+ split_content.pop
86
+ split_content.pop
87
+ split_content.pop
88
+ @mutations = split_content
89
+ end
90
+
91
+ def path
92
+ @path ||= File.basename(filename, ".txt") + '.html'
93
+ end
94
+
95
+ def to_html
96
+ ERB.new(File.read(template_file)).result(binding)
97
+ end
98
+
99
+ def average_score
100
+ return 0 if scanned_methods.length == 0
101
+ sum = 0
102
+ scanned_methods.each do |m|
103
+ sum += m.score
104
+ end
105
+ sum / scanned_methods.length
106
+ end
107
+
108
+ def highest_score
109
+ scanned_methods.inject(0) do |highest, m|
110
+ m.score > highest ? m.score : highest
111
+ end
112
+ end
113
+
114
+ def template_name
115
+ 'heckle_page'
116
+ end
117
+ end
36
118
  end
37
119
  end
@@ -11,17 +11,13 @@
11
11
  <p><a href="http://ruby.sadi.st/Heckle.html">Heckle</a> is a mutation tester.</p>
12
12
  <table>
13
13
  <tr>
14
- <th>File Path</th>
15
- <th>Code Smell</th>
14
+ <th>Class</th>
15
+ <th>Failed Mutations</th>
16
16
  </tr>
17
- <% @matches.each_with_index do |match, count| %>
17
+ <% @pages.each_with_index do |page, count| %>
18
18
  <tr class='<%= cycle("light", "dark", count) %>'>
19
- <td><%= match.first %></td>
20
- <td>
21
- <% match[1..-1].each do |line| %>
22
- <%= line %><br>
23
- <% end %>
24
- </td>
19
+ <td><a href='<%= page.path %>'><%= page.path.sub('.html', '.rb') %></a></td>
20
+ <td class='score'><%= page.mutations.size %></td>
25
21
  </tr>
26
22
  <% end %>
27
23
  </table>
@@ -5,6 +5,7 @@ require 'date'
5
5
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/base')
6
6
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/flay')
7
7
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/flog')
8
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/heckle')
8
9
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/md5_tracker')
9
10
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/churn')
10
11
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu/reek')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: p8-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.6
4
+ version: 0.9.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-02-25 00:00:00 -08:00
15
+ date: 2009-03-26 00:00:00 -07:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency