indirect-metric_fu 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/HISTORY +19 -0
  2. data/MIT-LICENSE +1 -1
  3. data/Manifest.txt +25 -0
  4. data/README +74 -21
  5. data/Rakefile +4 -10
  6. data/lib/metric_fu/base.rb +116 -9
  7. data/lib/metric_fu/churn.rb +8 -7
  8. data/lib/metric_fu/flay.rb +17 -0
  9. data/lib/metric_fu/flog.rb +129 -0
  10. data/lib/metric_fu/reek.rb +17 -0
  11. data/lib/metric_fu/roodi.rb +17 -0
  12. data/lib/metric_fu.rb +17 -3
  13. data/lib/tasks/churn.rake +1 -3
  14. data/lib/tasks/coverage.rake +19 -10
  15. data/lib/tasks/flay.rake +1 -4
  16. data/lib/tasks/flog.rake +10 -10
  17. data/lib/tasks/metric_fu.rake +8 -4
  18. data/lib/tasks/metric_fu.rb +1 -1
  19. data/lib/tasks/railroad.rake +39 -0
  20. data/lib/tasks/reek.rake +6 -0
  21. data/lib/tasks/roodi.rake +7 -0
  22. data/lib/tasks/saikuro.rake +1 -1
  23. data/lib/tasks/stats.rake +2 -3
  24. data/lib/templates/churn.html.erb +7 -4
  25. data/lib/templates/default.css +45 -0
  26. data/lib/templates/flay.html.erb +17 -10
  27. data/lib/templates/flog.html.erb +27 -15
  28. data/lib/templates/flog_page.html.erb +15 -3
  29. data/lib/templates/reek.html.erb +30 -0
  30. data/lib/templates/roodi.html.erb +26 -0
  31. data/spec/base_spec.rb +31 -9
  32. data/spec/churn_spec.rb +11 -4
  33. data/spec/config_spec.rb +110 -0
  34. data/spec/{flay_reporter_spec.rb → flay_spec.rb} +10 -3
  35. data/spec/flog_spec.rb +208 -0
  36. data/spec/md5_tracker_spec.rb +1 -3
  37. data/spec/reek_spec.rb +26 -0
  38. data/spec/spec_helper.rb +7 -3
  39. metadata +42 -18
  40. data/lib/metric_fu/flay_reporter.rb +0 -17
  41. data/lib/metric_fu/flog_reporter/base.rb +0 -49
  42. data/lib/metric_fu/flog_reporter/generator.rb +0 -39
  43. data/lib/metric_fu/flog_reporter/operator.rb +0 -10
  44. data/lib/metric_fu/flog_reporter/page.rb +0 -33
  45. data/lib/metric_fu/flog_reporter/scanned_method.rb +0 -28
  46. data/lib/metric_fu/flog_reporter.rb +0 -5
  47. data/lib/templates/churn.css +0 -38
  48. data/lib/templates/flay.css +0 -38
  49. data/lib/templates/flog.css +0 -39
  50. data/spec/flog_reporter/base_spec.rb +0 -69
@@ -1,12 +1,19 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe MetricFu::FlayReporter do
3
+ describe MetricFu::Flay do
4
4
 
5
5
  describe "generate_html" do
6
6
  it "should create a new Generator and call generate_report on it" do
7
- @generator = MetricFu::FlayReporter.new('other_dir')
7
+ @generator = MetricFu::Flay.new('other_dir')
8
8
  @generator.should_receive(:`).and_return("Matches found in :call (mass = 55)\n\tlib/metric_fu/flog_reporter.rb:2\n\tlib/metric_fu/flog_reporter.rb:3")
9
9
  @generator.generate_html
10
10
  end
11
11
  end
12
- end
12
+
13
+ describe "template_name" do
14
+ it "should return the class name in lowercase" do
15
+ flay = MetricFu::Flay.new('base_dir')
16
+ flay.template_name.should == 'flay'
17
+ end
18
+ end
19
+ end
data/spec/flog_spec.rb ADDED
@@ -0,0 +1,208 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ include MetricFu::Flog
3
+
4
+ describe "Flog::Base" do
5
+ before do
6
+ @alpha_only_method = <<-AOM
7
+ Total flog = 13.6283678106927
8
+
9
+ ErrorMailer#errormail: (12.5)
10
+ 12.0: assignment
11
+ 1.2: []
12
+ 1.2: now
13
+ 1.2: content_type
14
+ AOM
15
+
16
+ @method_that_has_digits = <<-MTHD
17
+ Total flog = 7.08378429936994
18
+
19
+ NoImmunizationReason#to_c32: (7.1)
20
+ 3.0: code
21
+ 2.3: branch
22
+ 1.4: templateId
23
+ 1.2: act
24
+ 1.1: entryRelationship
25
+ MTHD
26
+
27
+ @bang_method = <<-BM
28
+ Total flog = 7.08378429936994
29
+
30
+ NoImmunizationReason#to_c32!: (7.1)
31
+ 3.0: code
32
+ 2.3: branch
33
+ 1.4: templateId
34
+ 1.2: act
35
+ 1.1: entryRelationship
36
+ BM
37
+
38
+ @invalid_method = <<-IM
39
+ Total flog = 7.08378429936994
40
+
41
+ 3.0: code
42
+ 2.3: branch
43
+ 1.4: templateId
44
+ 1.2: act
45
+ 1.1: entryRelationship
46
+ IM
47
+
48
+ @assignment_method = <<-MTHD
49
+ Total Flog = 21.6 (5.4 +/- 3.3 flog / method)
50
+
51
+ ActivityReport#existing_measure_attributes=: (8.5)
52
+ 4.1: assignment
53
+ 1.8: id
54
+ 1.6: to_s
55
+ 1.4: []
56
+ 1.4: activity_report_measures
57
+ 1.2: each
58
+ 1.2: branch
59
+ MTHD
60
+
61
+ @class_methods_grouped_together = <<-MTHD
62
+ Total Flog = 61.8 (7.7 +/- 95.3 flog / method)
63
+
64
+ User#none: (32.8)
65
+ 7.2: include
66
+ 3.6: validates_length_of
67
+ 3.6: validates_format_of
68
+ 2.4: validates_presence_of
69
+ 2.4: validates_uniqueness_of
70
+ 1.4: bad_login_message
71
+ 1.4: name_regex
72
+ 1.4: bad_email_message
73
+ 1.4: bad_name_message
74
+ 1.4: login_regex
75
+ 1.4: email_regex
76
+ 1.2: private
77
+ 1.2: has_and_belongs_to_many
78
+ 1.2: before_create
79
+ 1.2: attr_accessible
80
+ 0.4: lit_fixnum
81
+ MTHD
82
+ end
83
+
84
+ it "should be able to parse class_methods_grouped_together" do
85
+ page = Base.parse(@class_methods_grouped_together)
86
+ page.should_not be_nil
87
+ page.score.should == 61.8
88
+ page.scanned_methods.size.should == 1
89
+ sm = page.scanned_methods.first
90
+ sm.name.should == 'User#none'
91
+ sm.score.should == 32.8
92
+
93
+ sm.operators.size.should == 16
94
+ sm.operators.first.score.should == 7.2
95
+ sm.operators.first.operator.should == "include"
96
+
97
+ sm.operators.last.score.should == 0.4
98
+ sm.operators.last.operator.should == "lit_fixnum"
99
+ end
100
+
101
+ it "should be able to parse an assignment method" do
102
+ page = Base.parse(@assignment_method)
103
+ page.should_not be_nil
104
+ page.score.should == 21.6
105
+ page.scanned_methods.size.should == 1
106
+ sm = page.scanned_methods.first
107
+ sm.name.should == 'ActivityReport#existing_measure_attributes='
108
+ sm.score.should == 8.5
109
+ end
110
+
111
+ it "should be able to parse an alpha only method" do
112
+ page = Base.parse(@alpha_only_method)
113
+ page.should_not be_nil
114
+ page.score.should == 13.6283678106927
115
+ page.scanned_methods.size.should == 1
116
+ sm = page.scanned_methods.first
117
+ sm.name.should == 'ErrorMailer#errormail'
118
+ sm.score.should == 12.5
119
+ end
120
+
121
+ it "should be able to parse method that has digits" do
122
+ page = Base.parse(@method_that_has_digits)
123
+ page.should_not be_nil
124
+ page.score.should == 7.08378429936994
125
+ page.scanned_methods.size.should == 1
126
+ sm = page.scanned_methods.first
127
+ sm.name.should == 'NoImmunizationReason#to_c32'
128
+ sm.score.should == 7.1
129
+ end
130
+
131
+ it "should be able to parse bang method" do
132
+ page = Base.parse(@bang_method)
133
+ page.should_not be_nil
134
+ page.score.should == 7.08378429936994
135
+ page.scanned_methods.size.should == 1
136
+ sm = page.scanned_methods.first
137
+ sm.name.should == 'NoImmunizationReason#to_c32!'
138
+ sm.score.should == 7.1
139
+ end
140
+
141
+ it "should return nil when parsing invalid method" do
142
+ page = Base.parse(@invalid_method)
143
+ page.should be_nil
144
+ end
145
+ end
146
+
147
+ IM = <<-IM
148
+ Total flog = 7.08378429936994
149
+
150
+ 3.0: code
151
+ 2.3: branch
152
+ 1.4: templateId
153
+ 1.2: act
154
+ 1.1: entryRelationship
155
+ IM
156
+ describe MetricFu::Flog do
157
+
158
+ describe "generate_report" do
159
+ it "should generate reports" do
160
+ generator = Flog::Generator.new('other_dir')
161
+ generator.should_receive(:flog_results).and_return(['A', 'B'])
162
+ generator.should_receive(:save_html).at_least(3).times.and_return('')
163
+ generator.should_receive(:open).any_number_of_times.and_return(['Total Flog = 1273.9 (9.3 +/- 259.2 flog / method)', 'TokenCounter#list_tokens_per_line: (15.2)', '9.0: assignment'].join("\n"))
164
+ generator.generate_report
165
+ end
166
+
167
+ it "should be able to handle InvalidFlogs" do
168
+ generator = Flog::Generator.new('other_dir')
169
+ generator.should_receive(:flog_results).and_return(['A', 'B'])
170
+ generator.should_receive(:inline_css).any_number_of_times.and_return('')
171
+ generator.should_receive(:save_html).once
172
+ generator.should_receive(:open).any_number_of_times.and_return(IM)
173
+ generator.generate_report
174
+ end
175
+ end
176
+
177
+ describe "template_name" do
178
+ it "should return the class name in lowercase" do
179
+ flog = Flog::Generator.new('base_dir')
180
+ Flog::Generator.template_name.should == 'flog'
181
+ end
182
+ end
183
+ end
184
+
185
+ describe MetricFu::Flog::Page do
186
+
187
+ describe "average_score" do
188
+ it "should calculate the average score" do
189
+ page = Page.new(10)
190
+ page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
191
+ page.average_score.should == 15
192
+ end
193
+
194
+ it "should be able to handle divide by zero" do
195
+ page = Page.new(10)
196
+ page.should_receive(:scanned_methods).any_number_of_times.and_return([])
197
+ page.average_score.should == 0
198
+ end
199
+ end
200
+
201
+ describe "highest_score" do
202
+ it "should calculate the average score" do
203
+ page = Page.new(10)
204
+ page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
205
+ page.highest_score.should == 20
206
+ end
207
+ end
208
+ end
@@ -1,6 +1,4 @@
1
- require 'spec'
2
- require File.join(File.dirname(__FILE__), '../lib/metric_fu/md5_tracker')
3
- include MetricFu
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
2
 
5
3
  describe MetricFu::MD5Tracker do
6
4
  before do
data/spec/reek_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ REEK_RESULT = %("lib/metric_fu/base.rb" -- 5 warnings:
4
+ [Utility Function] #configuration doesn't depend on instance state
5
+ [Utility Function] #open_in_browser? doesn't depend on instance state
6
+ [Long Method] Configuration#reset has approx 6 statements
7
+ [Utility Function] Generator#cycle doesn't depend on instance state
8
+ [Utility Function] Generator#link_to_filename doesn't depend on instance state)
9
+
10
+ describe MetricFu::Reek do
11
+
12
+ describe "generate_html" do
13
+ it "should create a new Generator and call generate_report on it" do
14
+ @generator = MetricFu::Reek.new('other_dir')
15
+ @generator.should_receive(:`).and_return(REEK_RESULT)
16
+ @generator.generate_html
17
+ end
18
+ end
19
+
20
+ describe "template_name" do
21
+ it "should return the class name in lowercase" do
22
+ flay = MetricFu::Reek.new('base_dir')
23
+ flay.template_name.should == 'reek'
24
+ end
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
+ require 'rubygems'
1
2
  require 'spec'
2
3
  require 'date'
3
4
 
4
- require File.dirname(__FILE__) + '/../lib/metric_fu/base'
5
- require File.dirname(__FILE__) + '/../lib/metric_fu/flay_reporter'
6
- require File.dirname(__FILE__) + '/../lib/metric_fu/churn'
5
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/base')
6
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/flay')
7
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/flog')
8
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/md5_tracker')
9
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/churn')
10
+ require File.join(File.dirname(__FILE__), '/../lib/metric_fu/reek')
7
11
  include MetricFu
metadata CHANGED
@@ -1,19 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indirect-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
8
8
  - Sean Soper
9
9
  - Andre Arko
10
+ - Petrik de Heus
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
14
 
14
- date: 2008-10-27 00:00:00 -07:00
15
+ date: 2009-02-05 00:00:00 -08:00
15
16
  default_executable:
16
17
  dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: flay
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.0
26
+ version:
17
27
  - !ruby/object:Gem::Dependency
18
28
  name: flog
19
29
  version_requirement:
@@ -28,12 +38,21 @@ dependencies:
28
38
  version_requirement:
29
39
  version_requirements: !ruby/object:Gem::Requirement
30
40
  requirements:
31
- - - ">="
41
+ - - ">"
32
42
  - !ruby/object:Gem::Version
33
43
  version: 0.8.1
34
44
  version:
35
45
  - !ruby/object:Gem::Dependency
36
- name: flay
46
+ name: railroad
47
+ version_requirement:
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.5.0
53
+ version:
54
+ - !ruby/object:Gem::Dependency
55
+ name: reek
37
56
  version_requirement:
38
57
  version_requirements: !ruby/object:Gem::Requirement
39
58
  requirements:
@@ -42,7 +61,7 @@ dependencies:
42
61
  version: 0.0.0
43
62
  version:
44
63
  - !ruby/object:Gem::Dependency
45
- name: diff-lcs
64
+ name: roodi
46
65
  version_requirement:
47
66
  version_requirements: !ruby/object:Gem::Requirement
48
67
  requirements:
@@ -50,7 +69,7 @@ dependencies:
50
69
  - !ruby/object:Gem::Version
51
70
  version: 0.0.0
52
71
  version:
53
- description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, and Rails' stats task
72
+ description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, Reek, Roodi and Rails' stats task
54
73
  email: jake.scruggs@gmail.com
55
74
  executables: []
56
75
 
@@ -58,6 +77,7 @@ extensions: []
58
77
 
59
78
  extra_rdoc_files:
60
79
  - HISTORY
80
+ - Manifest.txt
61
81
  - README
62
82
  files:
63
83
  - README
@@ -67,13 +87,10 @@ files:
67
87
  - Rakefile
68
88
  - lib/metric_fu/base.rb
69
89
  - lib/metric_fu/churn.rb
70
- - lib/metric_fu/flay_reporter.rb
71
- - lib/metric_fu/flog_reporter/base.rb
72
- - lib/metric_fu/flog_reporter/generator.rb
73
- - lib/metric_fu/flog_reporter/operator.rb
74
- - lib/metric_fu/flog_reporter/page.rb
75
- - lib/metric_fu/flog_reporter/scanned_method.rb
76
- - lib/metric_fu/flog_reporter.rb
90
+ - lib/metric_fu/flay.rb
91
+ - lib/metric_fu/flog.rb
92
+ - lib/metric_fu/reek.rb
93
+ - lib/metric_fu/roodi.rb
77
94
  - lib/metric_fu/md5_tracker.rb
78
95
  - lib/metric_fu/saikuro/saikuro.rb
79
96
  - lib/metric_fu.rb
@@ -83,15 +100,19 @@ files:
83
100
  - lib/tasks/flay.rake
84
101
  - lib/tasks/flog.rake
85
102
  - lib/tasks/metric_fu.rake
103
+ - lib/tasks/railroad.rake
104
+ - lib/tasks/reek.rake
105
+ - lib/tasks/roodi.rake
86
106
  - lib/tasks/saikuro.rake
87
107
  - lib/tasks/stats.rake
88
- - lib/templates/churn.css
89
108
  - lib/templates/churn.html.erb
90
- - lib/templates/flay.css
109
+ - lib/templates/default.css
91
110
  - lib/templates/flay.html.erb
92
- - lib/templates/flog.css
93
111
  - lib/templates/flog.html.erb
94
112
  - lib/templates/flog_page.html.erb
113
+ - lib/templates/reek.html.erb
114
+ - lib/templates/roodi.html.erb
115
+ - Manifest.txt
95
116
  has_rdoc: true
96
117
  homepage: http://metric-fu.rubyforge.org/
97
118
  post_install_message:
@@ -122,7 +143,10 @@ summary: A fistful of code metrics
122
143
  test_files:
123
144
  - spec/base_spec.rb
124
145
  - spec/churn_spec.rb
125
- - spec/flay_reporter_spec.rb
126
- - spec/flog_reporter/base_spec.rb
146
+ - spec/config_spec.rb
147
+ - spec/flay_spec.rb
148
+ - spec/flog_spec.rb
127
149
  - spec/md5_tracker_spec.rb
150
+ - spec/reek_spec.rb
151
+ - spec/roodi_spec.rb
128
152
  - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- require 'erb'
2
-
3
- module MetricFu
4
- class FlayReporter < Base::Generator
5
-
6
- def analyze
7
- files_to_flay = MetricFu::CODE_DIRS.map{|dir| Dir[File.join(dir, "**/*.rb")] }
8
- output = `flay #{files_to_flay.join(" ")}`
9
- @matches = output.chomp.split("\n\n").map{|m| m.split("\n ") }
10
- end
11
-
12
- def template_name
13
- 'flay'
14
- end
15
-
16
- end
17
- end
@@ -1,49 +0,0 @@
1
- module MetricFu::FlogReporter
2
-
3
- SCORE_FORMAT = "%0.2f"
4
-
5
- class InvalidFlog < RuntimeError
6
- end
7
-
8
- class Base
9
- MODULE_NAME = "([A-Za-z]+)+"
10
- METHOD_NAME = "#([a-z0-9]+_?)+\\??\\!?"
11
- SCORE = "\\d+\\.\\d+"
12
-
13
- METHOD_NAME_RE = Regexp.new("#{MODULE_NAME}#{METHOD_NAME}")
14
- SCORE_RE = Regexp.new(SCORE)
15
-
16
- METHOD_LINE_RE = Regexp.new("#{MODULE_NAME}#{METHOD_NAME}:\\s\\(#{SCORE}\\)")
17
- OPERATOR_LINE_RE = Regexp.new("\\s+(#{SCORE}):\\s(.*)$")
18
-
19
- class << self
20
- def cycle(first_value, second_value, iteration)
21
- return first_value if iteration % 2 == 0
22
- return second_value
23
- end
24
-
25
- def parse(text)
26
- score = text[/\w+ = (\d+\.\d+)/, 1]
27
- return nil unless score
28
- page = Page.new(score)
29
-
30
- text.each_line do |method_line|
31
- if METHOD_LINE_RE =~ method_line and
32
- method_name = method_line[METHOD_NAME_RE] and
33
- score = method_line[SCORE_RE]
34
- page.scanned_methods << ScannedMethod.new(method_name, score)
35
- end
36
-
37
- if OPERATOR_LINE_RE =~ method_line and
38
- operator = method_line[OPERATOR_LINE_RE, 2] and
39
- score = method_line[SCORE_RE]
40
- raise InvalidFlog if page.scanned_methods.empty?
41
- page.scanned_methods.last.operators << Operator.new(score, operator)
42
- end
43
- end
44
-
45
- page
46
- end
47
- end
48
- end
49
- end