p8-metric_fu 0.9.0.1 → 0.9.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Rakefile +2 -19
- data/TODO +1 -2
- data/lib/metric_fu.rb +3 -17
- data/lib/metric_fu/churn.rb +88 -0
- data/lib/metric_fu/flay.rb +17 -0
- data/lib/metric_fu/flog.rb +129 -0
- data/lib/metric_fu/md5_tracker.rb +52 -0
- data/lib/metric_fu/saikuro/saikuro.rb +1214 -0
- data/lib/tasks/churn.rake +9 -0
- data/lib/tasks/coverage.rake +54 -0
- data/lib/tasks/flay.rake +6 -0
- data/lib/tasks/flog.rake +69 -0
- data/lib/tasks/metric_fu.rake +24 -0
- data/lib/tasks/metric_fu.rb +6 -0
- data/lib/tasks/railroad.rake +39 -0
- data/lib/tasks/reek.rake +6 -0
- data/lib/tasks/roodi.rake +7 -0
- data/lib/tasks/saikuro.rake +35 -0
- data/lib/tasks/stats.rake +14 -0
- data/lib/templates/churn.html.erb +22 -0
- data/lib/templates/default.css +45 -0
- data/lib/templates/flay.html.erb +30 -0
- data/lib/templates/flog.html.erb +38 -0
- data/lib/templates/flog_page.html.erb +25 -0
- data/lib/templates/reek.html.erb +30 -0
- data/lib/templates/roodi.html.erb +26 -0
- data/spec/base_spec.rb +80 -0
- data/spec/churn_spec.rb +114 -114
- data/spec/config_spec.rb +103 -103
- data/spec/flay_spec.rb +16 -16
- data/spec/flog_spec.rb +205 -204
- data/spec/reek_spec.rb +23 -23
- data/spec/spec_helper.rb +7 -24
- metadata +1 -1
data/spec/flay_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe Flay do
|
3
|
+
describe MetricFu::Flay do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
5
|
+
describe "generate_html" do
|
6
|
+
it "should create a new Generator and call generate_report on it" do
|
7
|
+
@generator = MetricFu::Flay.new('other_dir')
|
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
|
+
@generator.generate_html
|
10
|
+
end
|
11
|
+
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
CHANGED
@@ -1,207 +1,208 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
include MetricFu::Flog
|
2
3
|
|
3
|
-
describe Flog do
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
# end
|
183
|
-
#
|
184
|
-
# describe MetricFu::Flog::Page do
|
185
|
-
#
|
186
|
-
# describe "average_score" do
|
187
|
-
# it "should calculate the average score" do
|
188
|
-
# page = Page.new(10)
|
189
|
-
# page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
190
|
-
# page.average_score.should == 15
|
191
|
-
# end
|
192
|
-
#
|
193
|
-
# it "should be able to handle divide by zero" do
|
194
|
-
# page = Page.new(10)
|
195
|
-
# page.should_receive(:scanned_methods).any_number_of_times.and_return([])
|
196
|
-
# page.average_score.should == 0
|
197
|
-
# end
|
198
|
-
# end
|
199
|
-
#
|
200
|
-
# describe "highest_score" do
|
201
|
-
# it "should calculate the average score" do
|
202
|
-
# page = Page.new(10)
|
203
|
-
# page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
204
|
-
# page.highest_score.should == 20
|
205
|
-
# end
|
206
|
-
# end
|
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
|
207
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
|
data/spec/reek_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
describe Reek do
|
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)
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
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
|