mwilden-metric_fu 1.1.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ /*
2
+ Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
+ Code licensed under the BSD License:
4
+ http://developer.yahoo.net/yui/license.txt
5
+ version: 2.5.2
6
+ */
7
+ html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;font-variant:normal;}sup {vertical-align:text-top;}sub {vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
@@ -29,6 +29,7 @@
29
29
  <h2 id="<%= page[:path].gsub(/[^a-z]+/, '_') %>"><%= link_to_filename page[:path] %></h2>
30
30
  <% page[:scanned_methods].each do |sm| %>
31
31
  <p><%= sm[:name] %></p>
32
+ <p>Total Score: <%=sm[:score]%></p>
32
33
  <table>
33
34
  <tr>
34
35
  <th>Score</th>
@@ -4,11 +4,11 @@
4
4
  <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
5
5
  <meta content='en' http-equiv='Content-Language' />
6
6
  <title>metrics</title>
7
- <link href='/reset.css' rel='stylesheet' type='text/css' />
8
- <link href='/buttons.css' rel='stylesheet' type='text/css' />
9
- <link href='/integrity.css' rel='stylesheet' type='text/css' />
10
7
  <style>
11
- <%= inline_css("default.css") %>
8
+ <%= inline_css("css/reset.css") %>
9
+ <%= inline_css("css/buttons.css") %>
10
+ <%= inline_css("css/integrity.css") %>
11
+ <%= inline_css("css/default.css") %>
12
12
  </style>
13
13
  <link REL="SHORTCUT ICON" HREF="/favicon.ico">
14
14
  </head>
@@ -30,53 +30,6 @@ describe MetricFu::Configuration do
30
30
  @config.instance_variable_get(:@metric_fu_root_directory)
31
31
  end
32
32
 
33
- describe '#warn_about_deprecated_config_options' do
34
-
35
- def get_new_config_and_raise_runtime_error
36
- lambda { get_new_config }.should raise_error
37
- end
38
-
39
- describe 'when ::MetricFu::CHURN_OPTIONS is present' do
40
- before(:each) { ::MetricFu::CHURN_OPTIONS = 'option' }
41
- after(:each) { ::MetricFu.send(:remove_const, 'CHURN_OPTIONS') }
42
-
43
- it 'should raise a RuntimeError with "Use config.churn '+
44
- 'instead of MetricFu::CHURN_OPTIONS"' do
45
- get_new_config_and_raise_runtime_error
46
- end
47
- end
48
-
49
- describe 'when ::MetricFu::DIRECTORIES_TO_FLOG is present' do
50
- before(:each) { ::MetricFu::DIRECTORIES_TO_FLOG = 'option' }
51
- after(:each) { ::MetricFu.send(:remove_const,'DIRECTORIES_TO_FLOG')}
52
-
53
- it 'should raise a RuntimeError with "Use config.flog '+
54
- '[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG' do
55
- get_new_config_and_raise_runtime_error
56
- end
57
- end
58
-
59
- describe 'when ::MetricFu::SAIKURO_OPTIONS is present' do
60
- before(:each) { ::MetricFu::SAIKURO_OPTIONS = 'option' }
61
- after(:each) { ::MetricFu.send(:remove_const,'SAIKURO_OPTIONS')}
62
-
63
- it 'should raise a RuntimeError with "Use config.saikuro '+
64
- 'instead of MetricFu::SAIKURO_OPTIONS' do
65
- get_new_config_and_raise_runtime_error
66
- end
67
- end
68
-
69
- describe 'when SAIKURO_OPTIONS is present' do
70
- before(:each) { SAIKURO_OPTIONS = 'option' }
71
- after(:each) { Object.send(:remove_const,'SAIKURO_OPTIONS')}
72
-
73
- it 'should raise a RuntimeError with "Use config.saikuro '+
74
- 'instead of SAIKURO_OPTIONS' do
75
- get_new_config_and_raise_runtime_error
76
- end
77
- end
78
- end
79
-
80
33
  describe "#reset" do
81
34
 
82
35
  before(:each) { get_new_config }
@@ -128,7 +81,7 @@ describe MetricFu::Configuration do
128
81
  output_directory.should == output_dir
129
82
  end
130
83
 
131
- it 'should set @template_class to StandardTemplate' do
84
+ it 'should set @template_class to AwesomeTemplate' do
132
85
  template_class.should == AwesomeTemplate
133
86
  end
134
87
 
@@ -191,7 +144,7 @@ describe MetricFu::Configuration do
191
144
  :error_cyclo => "7",
192
145
  :formater => "text" }' do
193
146
  @config.instance_variable_get(:@saikuro).
194
- should == { :output_directory => 'tmp/metric_fu/scratch/saikuro',
147
+ should == { :output_directory => "#{scratch_directory}/saikuro",
195
148
  :input_directory => ['lib'],
196
149
  :cyclo => "",
197
150
  :filter_cyclo => "0",
@@ -199,7 +152,38 @@ describe MetricFu::Configuration do
199
152
  :error_cyclo => "7",
200
153
  :formater => "text"}
201
154
  end
202
-
155
+
156
+ it 'should set @graph_theme to {
157
+ :colors => %w(orange purple green white red blue pink yellow),
158
+ :marker_color => "blue",
159
+ :background_colors => %w(white white)}' do
160
+ @config.instance_variable_get(:@graph_theme).
161
+ should == { :colors => %w(orange purple green white red blue pink yellow),
162
+ :marker_color => "blue",
163
+ :background_colors => %w(white white) }
164
+ end
165
+
166
+ it 'should set @graph_font to the path to the font directory' do
167
+ @config.instance_variable_get(:@graph_font).
168
+ should include(File.join('vendor', '_fonts', 'monaco.ttf'))
169
+ end
170
+
171
+ it 'should set @graph_title_font_size to 12' do
172
+ @config.instance_variable_get(:@graph_title_font_size).should eql(12)
173
+ end
174
+
175
+ it 'should set @graph_legend_box_size to 12' do
176
+ @config.instance_variable_get(:@graph_legend_box_size).should eql(12)
177
+ end
178
+
179
+ it 'should set @graph_legend_box_size to 10' do
180
+ @config.instance_variable_get(:@graph_legend_font_size).should eql(10)
181
+ end
182
+
183
+ it 'should set @graph_marker_font_size to 10' do
184
+ @config.instance_variable_get(:@graph_marker_font_size).should eql(10)
185
+ end
186
+
203
187
  describe 'if #rails? is true ' do
204
188
  before(:each) do
205
189
  @config.stub!(:rails?).and_return(true)
@@ -213,6 +197,13 @@ describe MetricFu::Configuration do
213
197
  end
214
198
  end
215
199
 
200
+ describe '#set_graphs ' do
201
+ it 'should set the @graphs instance var to AVAILABLE_GRAPHS' do
202
+ @config.instance_variable_get(:@graphs).
203
+ should == MetricFu::AVAILABLE_GRAPHS
204
+ end
205
+ end
206
+
216
207
  describe '#set_code_dirs ' do
217
208
  it 'should set the @code_dirs instance var to ["app", "lib"]' do
218
209
  # This is hard to spec properly because the @code_dirs variable
@@ -264,7 +255,13 @@ describe MetricFu::Configuration do
264
255
 
265
256
  MetricFu::AVAILABLE_METRICS.each do |metric|
266
257
  it "should add a #{metric} class method to the MetricFu module " do
267
- MetricFu.respond_to?(metric).should be_true
258
+ MetricFu.should respond_to(metric)
259
+ end
260
+ end
261
+
262
+ MetricFu::AVAILABLE_GRAPHS.each do |graph|
263
+ it "should add a #{graph} class metrhod to the MetricFu module" do
264
+ MetricFu.should respond_to(graph)
268
265
  end
269
266
  end
270
267
  end
@@ -274,7 +271,7 @@ describe MetricFu::Configuration do
274
271
  before(:each) { get_new_config }
275
272
 
276
273
  it 'should return the value of the PLATFORM constant' do
277
- this_platform = PLATFORM
274
+ this_platform = RUBY_PLATFORM
278
275
  @config.platform.should == this_platform
279
276
  end
280
277
  end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe MetricFu do
4
+
5
+ describe "responding to #graph" do
6
+ it "should return an instance of Graph" do
7
+ MetricFu.graph.should be_a(Graph)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe MetricFu::Graph do
13
+
14
+ before(:each) do
15
+ @graph = MetricFu::Graph.new
16
+ end
17
+
18
+ describe "responding to #add" do
19
+ it 'should instantiate a grapher and push it to clazz' do
20
+ @graph.clazz.should_receive(:push).with(an_instance_of(RcovGrapher))
21
+ @graph.add("rcov")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe FlayGrapher do
4
+ before :each do
5
+ @flay_grapher = MetricFu::FlayGrapher.new
6
+ MetricFu.configuration
7
+ end
8
+
9
+ it "should respond to flay_score and labels" do
10
+ @flay_grapher.should respond_to(:flay_score)
11
+ @flay_grapher.should respond_to(:labels)
12
+ end
13
+
14
+ describe "responding to #initialize" do
15
+ it "should initialise flay_score and labels" do
16
+ @flay_grapher.flay_score.should == []
17
+ @flay_grapher.labels.should == {}
18
+ end
19
+ end
20
+
21
+ describe "responding to #get_metrics" do
22
+ before(:each) do
23
+ @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
24
+ @date = "01022003"
25
+ end
26
+
27
+ it "should push 476 to flay_score" do
28
+ @flay_grapher.flay_score.should_receive(:push).with(476)
29
+ @flay_grapher.get_metrics(@metrics, @date)
30
+ end
31
+
32
+ it "should update labels with the date" do
33
+ @flay_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
34
+ @flay_grapher.get_metrics(@metrics, @date)
35
+ end
36
+ end
37
+
38
+ describe "responding to #graph!" do
39
+ it "should write flay.png" do
40
+ @flay_grapher.graph!
41
+ lambda{ File.open(File.join(MetricFu.output_directory, 'flay.png')) }.should_not raise_error
42
+ end
43
+ end
44
+ end
@@ -1,15 +1,61 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
2
3
  describe MetricFu::FlogGrapher do
3
- it "should not fall over when given empty results" do
4
- MetricFu::Configuration.run {}
4
+ before :each do
5
+ @flog_grapher = MetricFu::FlogGrapher.new
6
+ MetricFu.configuration
7
+ end
8
+
9
+ it "should respond to flog_total, flog_average and labels" do
10
+ @flog_grapher.should respond_to(:flog_average)
11
+ @flog_grapher.should respond_to(:labels)
12
+ @flog_grapher.should respond_to(:top_five_percent_average)
13
+ end
14
+
15
+ describe "responding to #initialize" do
16
+ it "should initialize top_five_percent_average, flog_average and labels" do
17
+ @flog_grapher.flog_average.should == []
18
+ @flog_grapher.labels.should == {}
19
+ @flog_grapher.top_five_percent_average.should == []
20
+ end
21
+ end
22
+
23
+ describe "responding to #get_metrics" do
24
+ before(:each) do
25
+ @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
26
+ @date = "01022003"
27
+ end
28
+
29
+ it "should push to top_five_percent_average" do
30
+ average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
31
+ @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
32
+ @flog_grapher.get_metrics(@metrics, @date)
33
+ end
5
34
 
6
- gruff_line = Gruff::Line.new(MetricFu.graph_size)
7
- gruff_line.stub!(:write)
8
- Gruff::Line.stub!(:new).and_return(gruff_line)
35
+ it "should push 9.9 to flog_average" do
36
+ @flog_grapher.flog_average.should_receive(:push).with(9.9)
37
+ @flog_grapher.get_metrics(@metrics, @date)
38
+ end
9
39
 
10
- grapher = FlogGrapher.new()
11
- metrics_hash = {:flog => {:average => 0, :pages => [], :total => 0}}
12
- grapher.get_metrics(metrics_hash ,"20090629")
13
- grapher.graph!
40
+ it "should update labels with the date" do
41
+ @flog_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
42
+ @flog_grapher.get_metrics(@metrics, @date)
43
+ end
14
44
  end
15
- end
45
+
46
+ describe "responding to #graph!" do
47
+ it "should write flog.png" do
48
+ @flog_grapher.graph!
49
+ lambda{ File.open(File.join(MetricFu.output_directory, 'flog.png')) }.should_not raise_error
50
+ end
51
+
52
+ it "should not fall over when given empty results" do
53
+ gruff_line = Gruff::Line.new(MetricFu.graph_size)
54
+ gruff_line.stub!(:write)
55
+ Gruff::Line.stub!(:new).and_return(gruff_line)
56
+ metrics_hash = { :flog => {:average => 0, :pages => [], :total => 0} }
57
+ @flog_grapher.get_metrics(metrics_hash ,"20090629")
58
+ @flog_grapher.graph!
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Grapher do
4
+ it "should blow up if gruff is not availible" do
5
+ Grapher.should_receive(:require).and_raise(LoadError)
6
+ Grapher.should_receive(:puts).with(/config\.graphs/)
7
+ lambda {Grapher.new}.should raise_error(LoadError)
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe RcovGrapher do
4
+ before :each do
5
+ @rcov_grapher = MetricFu::RcovGrapher.new
6
+ MetricFu.configuration
7
+ end
8
+
9
+ it "should respond to rcov_percent and labels" do
10
+ @rcov_grapher.should respond_to(:rcov_percent)
11
+ @rcov_grapher.should respond_to(:labels)
12
+ end
13
+
14
+ describe "responding to #initialize" do
15
+ it "should initialise rcov_percent and labels" do
16
+ @rcov_grapher.rcov_percent.should == []
17
+ @rcov_grapher.labels.should == {}
18
+ end
19
+ end
20
+
21
+ describe "responding to #get_metrics" do
22
+ before(:each) do
23
+ @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
24
+ @date = "01022003"
25
+ end
26
+
27
+ it "should push 49.6 to rcov_percent" do
28
+ @rcov_grapher.rcov_percent.should_receive(:push).with(49.6)
29
+ @rcov_grapher.get_metrics(@metrics, @date)
30
+ end
31
+
32
+ it "should update labels with the date" do
33
+ @rcov_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
34
+ @rcov_grapher.get_metrics(@metrics, @date)
35
+ end
36
+ end
37
+
38
+ describe "responding to #graph!" do
39
+ it "should write rcov.png" do
40
+ @rcov_grapher.graph!
41
+ lambda{ File.open(File.join(MetricFu.output_directory, 'rcov.png')) }.should_not raise_error
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe ReekGrapher do
4
+ before :each do
5
+ @reek_grapher = MetricFu::ReekGrapher.new
6
+ MetricFu.configuration
7
+ end
8
+
9
+ it "should respond to reek_count and labels" do
10
+ @reek_grapher.should respond_to(:reek_count)
11
+ @reek_grapher.should respond_to(:labels)
12
+ end
13
+
14
+ describe "responding to #initialize" do
15
+ it "should initialise reek_count and labels" do
16
+ @reek_grapher.reek_count.should == {}
17
+ @reek_grapher.labels.should == {}
18
+ end
19
+ end
20
+
21
+ describe "responding to #get_metrics" do
22
+ before(:each) do
23
+ @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
24
+ @date = "01022003"
25
+ end
26
+
27
+ it "should set a hash of code smells to reek_count" do
28
+ @reek_grapher.get_metrics(@metrics, @date)
29
+ @reek_grapher.reek_count.should == {
30
+ "Uncommunicative Name" => [27],
31
+ "Feature Envy" => [20],
32
+ "Utility Function" => [15],
33
+ "Long Method" => [26],
34
+ "Nested Iterators" => [12],
35
+ "Control Couple" => [4],
36
+ "Duplication" => [48],
37
+ "Large Class" => [1]
38
+ }
39
+ end
40
+
41
+ it "should update labels with the date" do
42
+ @reek_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
43
+ @reek_grapher.get_metrics(@metrics, @date)
44
+ end
45
+ end
46
+
47
+ describe "responding to #graph!" do
48
+ it "should write reek.png" do
49
+ @reek_grapher.graph!
50
+ lambda{ File.open(File.join(MetricFu.output_directory, 'reek.png')) }.should_not raise_error
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe RoodiGrapher do
4
+ before :each do
5
+ @roodi_grapher = MetricFu::RoodiGrapher.new
6
+ MetricFu.configuration
7
+ end
8
+
9
+ it "should respond to roodi_count and labels" do
10
+ @roodi_grapher.should respond_to(:roodi_count)
11
+ @roodi_grapher.should respond_to(:labels)
12
+ end
13
+
14
+ describe "responding to #initialize" do
15
+ it "should initialise roodi_count and labels" do
16
+ @roodi_grapher.roodi_count.should == []
17
+ @roodi_grapher.labels.should == {}
18
+ end
19
+ end
20
+
21
+ describe "responding to #get_metrics" do
22
+ before(:each) do
23
+ @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
24
+ @date = "01022003"
25
+ end
26
+
27
+ it "should push 13 to roodi_count" do
28
+ @roodi_grapher.roodi_count.should_receive(:push).with(13)
29
+ @roodi_grapher.get_metrics(@metrics, @date)
30
+ end
31
+
32
+ it "should update labels with the date" do
33
+ @roodi_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
34
+ @roodi_grapher.get_metrics(@metrics, @date)
35
+ end
36
+ end
37
+
38
+ describe "responding to #graph!" do
39
+ it "should write rcov.png" do
40
+ @roodi_grapher.graph!
41
+ lambda{ File.open(File.join(MetricFu.output_directory, 'roodi.png')) }.should_not raise_error
42
+ end
43
+ end
44
+ end