p8-metric_fu 0.9.0.1 → 0.9.0.2

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.
@@ -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
- # describe "generate_output" 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_output
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
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
@@ -1,207 +1,208 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ include MetricFu::Flog
2
3
 
3
- describe Flog do
4
- # before do
5
- # @alpha_only_method = <<-AOM
6
- # Total flog = 13.6283678106927
7
- #
8
- # ErrorMailer#errormail: (12.5)
9
- # 12.0: assignment
10
- # 1.2: []
11
- # 1.2: now
12
- # 1.2: content_type
13
- # AOM
14
- #
15
- # @method_that_has_digits = <<-MTHD
16
- # Total flog = 7.08378429936994
17
- #
18
- # NoImmunizationReason#to_c32: (7.1)
19
- # 3.0: code
20
- # 2.3: branch
21
- # 1.4: templateId
22
- # 1.2: act
23
- # 1.1: entryRelationship
24
- # MTHD
25
- #
26
- # @bang_method = <<-BM
27
- # Total flog = 7.08378429936994
28
- #
29
- # NoImmunizationReason#to_c32!: (7.1)
30
- # 3.0: code
31
- # 2.3: branch
32
- # 1.4: templateId
33
- # 1.2: act
34
- # 1.1: entryRelationship
35
- # BM
36
- #
37
- # @invalid_method = <<-IM
38
- # Total flog = 7.08378429936994
39
- #
40
- # 3.0: code
41
- # 2.3: branch
42
- # 1.4: templateId
43
- # 1.2: act
44
- # 1.1: entryRelationship
45
- # IM
46
- #
47
- # @assignment_method = <<-MTHD
48
- # Total Flog = 21.6 (5.4 +/- 3.3 flog / method)
49
- #
50
- # ActivityReport#existing_measure_attributes=: (8.5)
51
- # 4.1: assignment
52
- # 1.8: id
53
- # 1.6: to_s
54
- # 1.4: []
55
- # 1.4: activity_report_measures
56
- # 1.2: each
57
- # 1.2: branch
58
- # MTHD
59
- #
60
- # @class_methods_grouped_together = <<-MTHD
61
- # Total Flog = 61.8 (7.7 +/- 95.3 flog / method)
62
- #
63
- # User#none: (32.8)
64
- # 7.2: include
65
- # 3.6: validates_length_of
66
- # 3.6: validates_format_of
67
- # 2.4: validates_presence_of
68
- # 2.4: validates_uniqueness_of
69
- # 1.4: bad_login_message
70
- # 1.4: name_regex
71
- # 1.4: bad_email_message
72
- # 1.4: bad_name_message
73
- # 1.4: login_regex
74
- # 1.4: email_regex
75
- # 1.2: private
76
- # 1.2: has_and_belongs_to_many
77
- # 1.2: before_create
78
- # 1.2: attr_accessible
79
- # 0.4: lit_fixnum
80
- # MTHD
81
- # end
82
- #
83
- # it "should be able to parse class_methods_grouped_together" do
84
- # page = Base.parse(@class_methods_grouped_together)
85
- # page.should_not be_nil
86
- # page.score.should == 61.8
87
- # page.scanned_methods.size.should == 1
88
- # sm = page.scanned_methods.first
89
- # sm.name.should == 'User#none'
90
- # sm.score.should == 32.8
91
- #
92
- # sm.operators.size.should == 16
93
- # sm.operators.first.score.should == 7.2
94
- # sm.operators.first.operator.should == "include"
95
- #
96
- # sm.operators.last.score.should == 0.4
97
- # sm.operators.last.operator.should == "lit_fixnum"
98
- # end
99
- #
100
- # it "should be able to parse an assignment method" do
101
- # page = Base.parse(@assignment_method)
102
- # page.should_not be_nil
103
- # page.score.should == 21.6
104
- # page.scanned_methods.size.should == 1
105
- # sm = page.scanned_methods.first
106
- # sm.name.should == 'ActivityReport#existing_measure_attributes='
107
- # sm.score.should == 8.5
108
- # end
109
- #
110
- # it "should be able to parse an alpha only method" do
111
- # page = Base.parse(@alpha_only_method)
112
- # page.should_not be_nil
113
- # page.score.should == 13.6283678106927
114
- # page.scanned_methods.size.should == 1
115
- # sm = page.scanned_methods.first
116
- # sm.name.should == 'ErrorMailer#errormail'
117
- # sm.score.should == 12.5
118
- # end
119
- #
120
- # it "should be able to parse method that has digits" do
121
- # page = Base.parse(@method_that_has_digits)
122
- # page.should_not be_nil
123
- # page.score.should == 7.08378429936994
124
- # page.scanned_methods.size.should == 1
125
- # sm = page.scanned_methods.first
126
- # sm.name.should == 'NoImmunizationReason#to_c32'
127
- # sm.score.should == 7.1
128
- # end
129
- #
130
- # it "should be able to parse bang method" do
131
- # page = Base.parse(@bang_method)
132
- # page.should_not be_nil
133
- # page.score.should == 7.08378429936994
134
- # page.scanned_methods.size.should == 1
135
- # sm = page.scanned_methods.first
136
- # sm.name.should == 'NoImmunizationReason#to_c32!'
137
- # sm.score.should == 7.1
138
- # end
139
- #
140
- # it "should return nil when parsing invalid method" do
141
- # page = Base.parse(@invalid_method)
142
- # page.should be_nil
143
- # end
144
- # end
145
- #
146
- # IM = <<-IM
147
- # Total flog = 7.08378429936994
148
- #
149
- # 3.0: code
150
- # 2.3: branch
151
- # 1.4: templateId
152
- # 1.2: act
153
- # 1.1: entryRelationship
154
- # IM
155
- # describe MetricFu::Flog do
156
- #
157
- # describe "generate_report" do
158
- # it "should generate reports" do
159
- # generator = Flog::Generator.new('other_dir')
160
- # generator.should_receive(:flog_results).and_return(['A', 'B'])
161
- # generator.should_receive(:save_output).at_least(3).times.and_return('')
162
- # 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"))
163
- # generator.generate_report
164
- # end
165
- #
166
- # it "should be able to handle InvalidFlogs" do
167
- # generator = Flog::Generator.new('other_dir')
168
- # generator.should_receive(:flog_results).and_return(['A', 'B'])
169
- # generator.should_receive(:inline_css).any_number_of_times.and_return('')
170
- # generator.should_receive(:save_output).once
171
- # generator.should_receive(:open).any_number_of_times.and_return(IM)
172
- # generator.generate_report
173
- # end
174
- # end
175
- #
176
- # describe "template_name" do
177
- # it "should return the class name in lowercase" do
178
- # flog = Flog::Generator.new('base_dir')
179
- # Flog::Generator.template_name.should == 'flog'
180
- # end
181
- # end
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
@@ -1,26 +1,26 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
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 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
- # describe "generate_output" 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_output
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
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