bf4-metric_fu 2.1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/HISTORY +252 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.md +49 -0
  4. data/Rakefile +22 -0
  5. data/TODO +6 -0
  6. data/lib/base/base_template.rb +182 -0
  7. data/lib/base/churn_analyzer.rb +38 -0
  8. data/lib/base/code_issue.rb +100 -0
  9. data/lib/base/configuration.rb +219 -0
  10. data/lib/base/flay_analyzer.rb +50 -0
  11. data/lib/base/flog_analyzer.rb +43 -0
  12. data/lib/base/generator.rb +166 -0
  13. data/lib/base/graph.rb +44 -0
  14. data/lib/base/grouping.rb +42 -0
  15. data/lib/base/line_numbers.rb +79 -0
  16. data/lib/base/location.rb +87 -0
  17. data/lib/base/md5_tracker.rb +52 -0
  18. data/lib/base/metric_analyzer.rb +331 -0
  19. data/lib/base/ranking.rb +34 -0
  20. data/lib/base/rcov_analyzer.rb +43 -0
  21. data/lib/base/record.rb +43 -0
  22. data/lib/base/reek_analyzer.rb +164 -0
  23. data/lib/base/report.rb +110 -0
  24. data/lib/base/roodi_analyzer.rb +37 -0
  25. data/lib/base/saikuro_analyzer.rb +48 -0
  26. data/lib/base/scoring_strategies.rb +29 -0
  27. data/lib/base/stats_analyzer.rb +37 -0
  28. data/lib/base/table.rb +108 -0
  29. data/lib/generators/churn.rb +28 -0
  30. data/lib/generators/flay.rb +31 -0
  31. data/lib/generators/flog.rb +113 -0
  32. data/lib/generators/hotspots.rb +52 -0
  33. data/lib/generators/rails_best_practices.rb +53 -0
  34. data/lib/generators/rcov.rb +124 -0
  35. data/lib/generators/reek.rb +81 -0
  36. data/lib/generators/roodi.rb +35 -0
  37. data/lib/generators/saikuro.rb +259 -0
  38. data/lib/generators/stats.rb +58 -0
  39. data/lib/graphs/engines/bluff.rb +113 -0
  40. data/lib/graphs/engines/gchart.rb +157 -0
  41. data/lib/graphs/flay_grapher.rb +18 -0
  42. data/lib/graphs/flog_grapher.rb +57 -0
  43. data/lib/graphs/grapher.rb +11 -0
  44. data/lib/graphs/rails_best_practices_grapher.rb +19 -0
  45. data/lib/graphs/rcov_grapher.rb +18 -0
  46. data/lib/graphs/reek_grapher.rb +30 -0
  47. data/lib/graphs/roodi_grapher.rb +18 -0
  48. data/lib/graphs/stats_grapher.rb +20 -0
  49. data/lib/metric_fu.rb +80 -0
  50. data/lib/tasks/metric_fu.rake +36 -0
  51. data/lib/templates/awesome/awesome_template.rb +92 -0
  52. data/lib/templates/awesome/churn.html.erb +58 -0
  53. data/lib/templates/awesome/css/buttons.css +82 -0
  54. data/lib/templates/awesome/css/default.css +91 -0
  55. data/lib/templates/awesome/css/integrity.css +334 -0
  56. data/lib/templates/awesome/css/reset.css +7 -0
  57. data/lib/templates/awesome/css/syntax.css +19 -0
  58. data/lib/templates/awesome/flay.html.erb +34 -0
  59. data/lib/templates/awesome/flog.html.erb +55 -0
  60. data/lib/templates/awesome/hotspots.html.erb +62 -0
  61. data/lib/templates/awesome/index.html.erb +34 -0
  62. data/lib/templates/awesome/layout.html.erb +30 -0
  63. data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
  64. data/lib/templates/awesome/rcov.html.erb +42 -0
  65. data/lib/templates/awesome/reek.html.erb +40 -0
  66. data/lib/templates/awesome/roodi.html.erb +27 -0
  67. data/lib/templates/awesome/saikuro.html.erb +71 -0
  68. data/lib/templates/awesome/stats.html.erb +51 -0
  69. data/lib/templates/javascripts/bluff-min.js +1 -0
  70. data/lib/templates/javascripts/excanvas.js +35 -0
  71. data/lib/templates/javascripts/js-class.js +1 -0
  72. data/lib/templates/standard/churn.html.erb +31 -0
  73. data/lib/templates/standard/default.css +64 -0
  74. data/lib/templates/standard/flay.html.erb +34 -0
  75. data/lib/templates/standard/flog.html.erb +57 -0
  76. data/lib/templates/standard/hotspots.html.erb +54 -0
  77. data/lib/templates/standard/index.html.erb +41 -0
  78. data/lib/templates/standard/rails_best_practices.html.erb +29 -0
  79. data/lib/templates/standard/rcov.html.erb +43 -0
  80. data/lib/templates/standard/reek.html.erb +42 -0
  81. data/lib/templates/standard/roodi.html.erb +29 -0
  82. data/lib/templates/standard/saikuro.html.erb +84 -0
  83. data/lib/templates/standard/standard_template.rb +27 -0
  84. data/lib/templates/standard/stats.html.erb +55 -0
  85. data/spec/base/base_template_spec.rb +194 -0
  86. data/spec/base/configuration_spec.rb +277 -0
  87. data/spec/base/generator_spec.rb +223 -0
  88. data/spec/base/graph_spec.rb +61 -0
  89. data/spec/base/line_numbers_spec.rb +62 -0
  90. data/spec/base/location_spec.rb +127 -0
  91. data/spec/base/md5_tracker_spec.rb +57 -0
  92. data/spec/base/metric_analyzer_spec.rb +452 -0
  93. data/spec/base/ranking_spec.rb +42 -0
  94. data/spec/base/report_spec.rb +146 -0
  95. data/spec/base/table_spec.rb +36 -0
  96. data/spec/generators/churn_spec.rb +41 -0
  97. data/spec/generators/flay_spec.rb +105 -0
  98. data/spec/generators/flog_spec.rb +70 -0
  99. data/spec/generators/hotspots_spec.rb +88 -0
  100. data/spec/generators/rails_best_practices_spec.rb +52 -0
  101. data/spec/generators/rcov_spec.rb +180 -0
  102. data/spec/generators/reek_spec.rb +134 -0
  103. data/spec/generators/roodi_spec.rb +24 -0
  104. data/spec/generators/saikuro_spec.rb +74 -0
  105. data/spec/generators/stats_spec.rb +74 -0
  106. data/spec/graphs/engines/bluff_spec.rb +19 -0
  107. data/spec/graphs/engines/gchart_spec.rb +156 -0
  108. data/spec/graphs/flay_grapher_spec.rb +56 -0
  109. data/spec/graphs/flog_grapher_spec.rb +108 -0
  110. data/spec/graphs/rails_best_practices_grapher_spec.rb +61 -0
  111. data/spec/graphs/rcov_grapher_spec.rb +56 -0
  112. data/spec/graphs/reek_grapher_spec.rb +65 -0
  113. data/spec/graphs/roodi_grapher_spec.rb +56 -0
  114. data/spec/graphs/stats_grapher_spec.rb +68 -0
  115. data/spec/resources/line_numbers/foo.rb +33 -0
  116. data/spec/resources/line_numbers/module.rb +11 -0
  117. data/spec/resources/line_numbers/module_surrounds_class.rb +15 -0
  118. data/spec/resources/line_numbers/two_classes.rb +11 -0
  119. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  120. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  121. data/spec/resources/saikuro/index_cyclo.html +155 -0
  122. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  123. data/spec/resources/yml/20090630.yml +7922 -0
  124. data/spec/resources/yml/metric_missing.yml +1 -0
  125. data/spec/spec.opts +6 -0
  126. data/spec/spec_helper.rb +7 -0
  127. metadata +560 -0
@@ -0,0 +1,42 @@
1
+ <html>
2
+ <head>
3
+ <title>Reek Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Reek Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p><a href="http://reek.rubyforge.org/">Reek</a> detects common code smells in ruby code.</p>
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Method</th>
17
+ <th>Description</th>
18
+ <th>Type</th>
19
+ </tr>
20
+ <% count = 0 %>
21
+ <% @reek[:matches].each do |match| %>
22
+ <% match[:code_smells].each do |smell| %>
23
+ <tr class='<%= cycle("light", "dark", count) %>'>
24
+ <td><%= match[:file_path] %></td>
25
+ <td>
26
+ <%= smell[:method] %>
27
+ </td>
28
+ <td>
29
+ <%= smell[:message] %>
30
+ </td>
31
+ <td>
32
+ <%= smell[:type] %>
33
+ </td>
34
+ </tr>
35
+ <% count += 1 %>
36
+ <% end %>
37
+ <% end %>
38
+
39
+ </table>
40
+ <p>Generated on <%= Time.now.localtime %></p>
41
+ </body>
42
+ </html>
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title>Roodi Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Roodi Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p><a href="http://roodi.rubyforge.org/">Roodi</a> parses your Ruby code and warns you about design issues you have based on the checks that is has configured.</p>
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Warning</th>
17
+ </tr>
18
+ <% count = 0 %>
19
+ <% @roodi[:problems].each do |problem| %>
20
+ <tr class='<%= cycle("light", "dark", count) %>'>
21
+ <td><%= problem[:file] %>:<%= problem[:line] %></td>
22
+ <td><%= problem[:problem] %></td>
23
+ </tr>
24
+ <% count += 1 %>
25
+ <% end %>
26
+ </table>
27
+ <p>Generated on <%= Time.now.localtime %></p>
28
+ </body>
29
+ </html>
@@ -0,0 +1,84 @@
1
+ <html>
2
+ <head>
3
+ <title>Saikuro Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Saikuro Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p><a href='http://saikuro.rubyforge.org/'>Saikuro</a> analyzes ruby code for cyclomatic complexity.</p>
13
+
14
+ <h2>Analyzed Methods</h2>
15
+ <table>
16
+ <tr>
17
+ <th>Method Name</th>
18
+ <th>Complexity</th>
19
+ <th># Lines</th>
20
+ </tr>
21
+ <% @saikuro[:methods].each do |method| %>
22
+ <tr>
23
+ <td><%= method[:name] %></td>
24
+ <td><%= method[:complexity] %></td>
25
+ <td><%= method[:lines] %></td>
26
+ </tr>
27
+ <% end %>
28
+ </table>
29
+
30
+
31
+
32
+ <h2>Analyzed Classes</h2>
33
+ <table>
34
+ <tr>
35
+ <th>Class Name</th>
36
+ <th>Complexity</th>
37
+ <th># Lines</th>
38
+ </tr>
39
+ <% @saikuro[:classes].each do |klass| %>
40
+ <tr>
41
+ <td><%= klass[:name] %></td>
42
+ <td><%= klass[:complexity] %></td>
43
+ <td><%= klass[:lines] %></td>
44
+ </tr>
45
+ <% end %>
46
+ </table>
47
+
48
+
49
+ <h2>Analyzed Files</h2>
50
+ <% @saikuro[:files].each do |file| %>
51
+ <% file[:classes].each do |klass| %>
52
+ <% if !klass[:methods].empty? %>
53
+ <h3><%= file[:filename] %></h3>
54
+ <h4>Class : <%= klass[:class_name] %></h4>
55
+ <h5>Total complexity : <%= klass[:complexity] %></h5>
56
+ <h5>Total lines : <%= klass[:lines] %></h5>
57
+ <table>
58
+ <tr>
59
+ <th>Method</th>
60
+ <th>Complexity</th>
61
+ <th># Lines</th>
62
+ </tr>
63
+ <% klass[:methods].each do |method| %>
64
+ <tr>
65
+ <td>
66
+ <%= method[:name] %>
67
+ </td>
68
+ <td>
69
+ <%= method[:complexity] %>
70
+ </td>
71
+ <td>
72
+ <%= method[:lines] %>
73
+ </td>
74
+ </tr>
75
+ <% end %>
76
+ </table>
77
+ <% end %>
78
+ <% end %>
79
+ <% end %>
80
+
81
+ <p>Generated on <%= Time.now.localtime %></p>
82
+ </body>
83
+ </html>
84
+
@@ -0,0 +1,27 @@
1
+ class StandardTemplate < MetricFu::Template
2
+
3
+
4
+ def write
5
+ report.each_pair do |section, contents|
6
+ mf_debug section
7
+ if template_exists?(section)
8
+ create_instance_var(section, contents)
9
+ html = erbify(section)
10
+ fn = output_filename(section)
11
+ MetricFu.report.save_output(html, MetricFu.output_directory, fn)
12
+ end
13
+ end
14
+
15
+ # Instance variables we need should already be created from above
16
+ if template_exists?('index')
17
+ html = erbify('index')
18
+ fn = output_filename('index')
19
+ MetricFu.report.save_output(html, MetricFu.output_directory, fn)
20
+ end
21
+ end
22
+
23
+ def this_directory
24
+ File.dirname(__FILE__)
25
+ end
26
+ end
27
+
@@ -0,0 +1,55 @@
1
+ <html>
2
+ <head>
3
+ <title>Rake Stats Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Rake Stats Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p>Rails rake stats results.</p>
13
+ <table>
14
+ <tr>
15
+ <th>Lines of Code</th>
16
+ <th>Lines of Test</th>
17
+ <th>Code to test ratio</th>
18
+ </tr>
19
+ <tr>
20
+ <td><%= @stats[:codeLOC] %></td>
21
+ <td><%= @stats[:testLOC] %></td>
22
+ <td>1:<%= @stats[:code_to_test_ratio] %></td>
23
+ </tr>
24
+ </table>
25
+
26
+ <table>
27
+ <tr>
28
+ <th>Name</th>
29
+ <th>Lines</th>
30
+ <th>LOC</th>
31
+ <th>Classes</th>
32
+ <th>Methods</th>
33
+ <th>Methods per class</th>
34
+ <th>LOC per method</th>
35
+ </tr>
36
+ <% count = 0 %>
37
+ <% @stats[:lines].each do |line| %>
38
+ <tr>
39
+ <td><%= line[:name] %></td>
40
+ <td><%= line[:lines] %></td>
41
+ <td><%= line[:loc] %></td>
42
+ <td><%= line[:classes] %></td>
43
+ <td><%= line[:methods] %></td>
44
+ <td><%= line[:methods_per_class] %></td>
45
+ <td><%= line[:loc_per_method] %></td>
46
+ </tr>
47
+ <% count += 1 %>
48
+ <% end %>
49
+ </table>
50
+
51
+ <p>Generated on <%= Time.now.localtime %></p>
52
+ </body>
53
+ </html>
54
+
55
+
@@ -0,0 +1,194 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require 'erb'
3
+
4
+ describe MetricFu::Template do
5
+
6
+ before(:each) do
7
+ @template = Template.new
8
+ end
9
+
10
+ describe "#erbify" do
11
+ it 'should evaluate a erb doc' do
12
+ section = 'section'
13
+ File.stub!(:read).and_return('foo')
14
+ erb = mock('erb')
15
+ erb.should_receive(:result)
16
+ ERB.should_receive(:new).with('foo').and_return(erb)
17
+ @template.should_receive(:template).and_return('foo')
18
+ @template.send(:erbify, section)
19
+ end
20
+ end
21
+
22
+ describe "#template_exists? " do
23
+
24
+ before(:each) do
25
+ @section = mock('section')
26
+ @template.should_receive(:template).
27
+ with(@section).and_return(@section)
28
+ end
29
+
30
+ describe 'if the template exists' do
31
+ it 'should return true' do
32
+ File.should_receive(:exist?).with(@section).and_return(true)
33
+ result = @template.send(:template_exists?, @section)
34
+ result.should be_true
35
+ end
36
+ end
37
+
38
+ describe 'if the template does not exist' do
39
+ it 'should return false' do
40
+ File.should_receive(:exist?).with(@section).and_return(false)
41
+ result = @template.send(:template_exists?, @section)
42
+ result.should be_false
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#create_instance_var" do
48
+ it 'should set an instance variable with the passed contents' do
49
+ section = 'section'
50
+ contents = 'contents'
51
+ @template.send(:create_instance_var, section, contents)
52
+ @template.instance_variable_get(:@section).should == contents
53
+ end
54
+ end
55
+
56
+ describe "#template" do
57
+ it 'should generate the filename of the template file' do
58
+ section = mock('section')
59
+ section.should_receive(:to_s).and_return('section')
60
+ @template.should_receive(:this_directory).and_return('dir')
61
+ result = @template.send(:template, section)
62
+ result.should == "dir/section.html.erb"
63
+ end
64
+ end
65
+
66
+ describe "#output_filename" do
67
+ it 'should generate the filename of the output file' do
68
+ section = mock('section')
69
+ section.should_receive(:to_s).and_return('section')
70
+ result = @template.send(:output_filename, section)
71
+ result.should == "section.html"
72
+ end
73
+ end
74
+
75
+ describe "#inline_css" do
76
+ it 'should return the contents of a css file' do
77
+ css = 'mycss.css'
78
+ @template.should_receive(:this_directory).and_return('dir')
79
+ io = mock('io', :read => "css contents")
80
+ @template.should_receive(:open).and_yield(io)
81
+ result = @template.send(:inline_css, css)
82
+ result.should == 'css contents'
83
+ end
84
+ end
85
+
86
+ describe "#link_to_filename " do
87
+ describe "when on OS X" do
88
+ before(:each) do
89
+ config = mock("configuration")
90
+ config.stub!(:platform).and_return('universal-darwin-9.0')
91
+ config.stub!(:darwin_txmt_protocol_no_thanks).and_return(false)
92
+ config.stub!(:link_prefix).and_return(nil)
93
+ MetricFu.stub!(:configuration).and_return(config)
94
+ end
95
+
96
+ it 'should return a textmate protocol link' do
97
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
98
+ result = @template.send(:link_to_filename, 'filename')
99
+ result.should eql("<a href='txmt://open/?url=file://" \
100
+ + "/expanded/filename'>filename</a>")
101
+ end
102
+
103
+ it "should do the right thing with a filename that starts with a slash" do
104
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
105
+ result = @template.send(:link_to_filename, '/filename')
106
+ result.should eql("<a href='txmt://open/?url=file://" \
107
+ + "/expanded/filename'>/filename</a>")
108
+ end
109
+
110
+ it "should include a line number" do
111
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
112
+ result = @template.send(:link_to_filename, 'filename', 6)
113
+ result.should eql("<a href='txmt://open/?url=file://" \
114
+ + "/expanded/filename&line=6'>filename:6</a>")
115
+ end
116
+
117
+ describe "but no thanks for txtmt" do
118
+ before(:each) do
119
+ config = mock("configuration")
120
+ config.stub!(:platform).and_return('universal-darwin-9.0')
121
+ config.stub!(:darwin_txmt_protocol_no_thanks).and_return(true)
122
+ config.stub!(:link_prefix).and_return(nil)
123
+ MetricFu.stub!(:configuration).and_return(config)
124
+ File.should_receive(:expand_path).and_return('filename')
125
+ end
126
+
127
+ it "should return a file protocol link" do
128
+ name = "filename"
129
+ result = @template.send(:link_to_filename, name)
130
+ result.should == "<a href='file://filename'>filename</a>"
131
+ end
132
+ end
133
+
134
+ describe "and given link text" do
135
+ it "should use the submitted link text" do
136
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
137
+ result = @template.send(:link_to_filename, 'filename', 6, 'link content')
138
+ result.should eql("<a href='txmt://open/?url=file://" \
139
+ + "/expanded/filename&line=6'>link content</a>")
140
+ end
141
+ end
142
+ end
143
+
144
+ describe "when on other platforms" do
145
+ before(:each) do
146
+ config = mock("configuration")
147
+ config.should_receive(:platform).and_return('other')
148
+ config.stub!(:link_prefix).and_return(nil)
149
+ config.stub!(:darwin_txmt_protocol_no_thanks).and_return(false)
150
+ MetricFu.stub!(:configuration).and_return(config)
151
+ File.should_receive(:expand_path).and_return('filename')
152
+ end
153
+
154
+ it 'should return a file protocol link' do
155
+ name = "filename"
156
+ result = @template.send(:link_to_filename, name)
157
+ result.should == "<a href='file://filename'>filename</a>"
158
+ end
159
+ end
160
+ describe "when configured with a link_prefix" do
161
+ before(:each) do
162
+ config = mock("configuration")
163
+ config.should_receive(:link_prefix).and_return('http://example.org/files')
164
+ MetricFu.stub!(:configuration).and_return(config)
165
+ File.should_receive(:expand_path).and_return('filename')
166
+ end
167
+
168
+ it 'should return a http protocol link' do
169
+ name = "filename"
170
+ result = @template.send(:link_to_filename, name)
171
+ result.should == "<a href='http://example.org/files/filename'>filename</a>"
172
+ end
173
+ end
174
+ end
175
+
176
+ describe "#cycle" do
177
+ it 'should return the first_value passed if iteration passed is even' do
178
+ first_val = "first"
179
+ second_val = "second"
180
+ iter = 2
181
+ result = @template.send(:cycle, first_val, second_val, iter)
182
+ result.should == first_val
183
+ end
184
+
185
+ it 'should return the second_value passed if iteration passed is odd' do
186
+ first_val = "first"
187
+ second_val = "second"
188
+ iter = 1
189
+ result = @template.send(:cycle, first_val, second_val, iter)
190
+ result.should == second_val
191
+ end
192
+ end
193
+
194
+ end
@@ -0,0 +1,277 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe MetricFu::Configuration do
4
+
5
+ def get_new_config
6
+ @config = Configuration.new
7
+ end
8
+
9
+ def base_directory
10
+ @config.instance_variable_get(:@base_directory)
11
+ end
12
+
13
+ def output_directory
14
+ @config.instance_variable_get(:@output_directory)
15
+ end
16
+
17
+ def scratch_directory
18
+ @config.instance_variable_get(:@scratch_directory)
19
+ end
20
+
21
+ def template_directory
22
+ @config.instance_variable_get(:@template_directory)
23
+ end
24
+
25
+ def template_class
26
+ @config.instance_variable_get(:@template_class)
27
+ end
28
+
29
+ def metric_fu_root
30
+ @config.instance_variable_get(:@metric_fu_root_directory)
31
+ end
32
+
33
+ describe "#reset" do
34
+
35
+ before(:each) { get_new_config }
36
+
37
+ describe 'when there is a CC_BUILD_ARTIFACTS environment variable' do
38
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'foo' }
39
+
40
+ it 'should return the CC_BUILD_ARTIFACTS environment variable' do
41
+ get_new_config
42
+ base_directory.should == ENV['CC_BUILD_ARTIFACTS']
43
+ end
44
+ end
45
+
46
+ describe 'when there is no CC_BUILD_ARTIFACTS environment variable' do
47
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
48
+
49
+ it 'should return "tmp/metric_fu"' do
50
+ get_new_config
51
+ base_directory.should == "tmp/metric_fu"
52
+ end
53
+ end
54
+
55
+ it 'should set @metric_fu_root_directory to the base of the '+
56
+ 'metric_fu application' do
57
+ app_root = File.join(File.dirname(__FILE__), '..', '..')
58
+ app_root_absolute_path = File.expand_path(app_root)
59
+ metric_fu_absolute_path = File.expand_path(metric_fu_root)
60
+ metric_fu_absolute_path.should == app_root_absolute_path
61
+ end
62
+
63
+ it 'should set @template_directory to the lib/templates relative '+
64
+ 'to @metric_fu_root_directory' do
65
+ template_dir = File.join(File.dirname(__FILE__),
66
+ '..', '..', 'lib','templates')
67
+ template_dir_abs_path = File.expand_path(template_dir)
68
+ calc_template_dir_abs_path = File.expand_path(template_directory)
69
+ calc_template_dir_abs_path.should == template_dir_abs_path
70
+ end
71
+
72
+ it 'should set @scratch_directory to scratch relative '+
73
+ 'to @base_directory' do
74
+ scratch_dir = File.join(base_directory, 'scratch')
75
+ scratch_directory.should == scratch_dir
76
+ end
77
+
78
+ it 'should set @output_directory to output relative '+
79
+ 'to @base_directory' do
80
+ output_dir = File.join(base_directory, 'output')
81
+ output_directory.should == output_dir
82
+ end
83
+
84
+ it 'should set @template_class to AwesomeTemplate' do
85
+ template_class.should == AwesomeTemplate
86
+ end
87
+
88
+ it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
89
+ @config.instance_variable_get(:@flay).
90
+ should == {:dirs_to_flay => ['lib'], :filetypes=>["rb"], :minimum_score => 100}
91
+ end
92
+
93
+ it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
94
+ @config.instance_variable_get(:@flog).
95
+ should == {:dirs_to_flog => ['lib']}
96
+ end
97
+
98
+ it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
99
+ @config.instance_variable_get(:@reek).
100
+ should == {:config_file_pattern=>nil, :dirs_to_reek => ['lib']}
101
+ end
102
+
103
+ it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
104
+ @config.instance_variable_get(:@roodi).
105
+ should == {:roodi_config=>nil, :dirs_to_roodi => ['lib']}
106
+ end
107
+
108
+ it 'should set @churn to {}' do
109
+ @config.instance_variable_get(:@churn).
110
+ should == {}
111
+ end
112
+
113
+ it 'should set @stats to {}' do
114
+ @config.instance_variable_get(:@stats).
115
+ should == {}
116
+ end
117
+
118
+ it 'should set @rails_best_practices to {}' do
119
+ @config.instance_variable_get(:@rails_best_practices).
120
+ should == {}
121
+ end
122
+
123
+ it 'should set @rcov to { :test_files => ["test/**/*_test.rb",
124
+ "spec/**/*_spec.rb"]
125
+ :rcov_opts => ["--sort coverage",
126
+ "--no-html",
127
+ "--text-coverage",
128
+ "--no-color",
129
+ "--profile",
130
+ "--rails",
131
+ "--exclude /gems/,/Library/,/usr/,spec"]}' do
132
+ @config.instance_variable_get(:@rcov).
133
+ should == { :environment => 'test',
134
+ :test_files => ['test/**/*_test.rb',
135
+ 'spec/spec_helper.rb',
136
+ 'spec/**/*_spec.rb'],
137
+ :rcov_opts => ["--sort coverage",
138
+ "--no-html",
139
+ "--text-coverage",
140
+ "--no-color",
141
+ "--profile",
142
+ "--rails",
143
+ "--exclude /gems/,/Library/,/usr/,spec"],
144
+ :external => nil}
145
+ end
146
+
147
+ it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
148
+ :input_directory => @code_dirs,
149
+ :cyclo => "",
150
+ :filter_cyclo => "0",
151
+ :warn_cyclo => "5",
152
+ :error_cyclo => "7",
153
+ :formater => "text" }' do
154
+ @config.instance_variable_get(:@saikuro).
155
+ should == { :output_directory => "#{scratch_directory}/saikuro",
156
+ :input_directory => ['lib'],
157
+ :cyclo => "",
158
+ :filter_cyclo => "0",
159
+ :warn_cyclo => "5",
160
+ :error_cyclo => "7",
161
+ :formater => "text"}
162
+ end
163
+
164
+ describe 'if #rails? is true ' do
165
+ before(:each) do
166
+ @config.stub!(:rails?).and_return(true)
167
+ end
168
+
169
+ describe '#set_metrics ' do
170
+ it 'should set the @metrics instance var to AVAILABLE_METRICS + '\
171
+ +'[:stats]' do
172
+ @config.instance_variable_get(:@metrics).
173
+ should == MetricFu::AVAILABLE_METRICS << [:stats]
174
+ end
175
+ end
176
+
177
+ describe '#set_graphs ' do
178
+ it 'should set the @graphs instance var to AVAILABLE_GRAPHS' do
179
+ @config.instance_variable_get(:@graphs).
180
+ should == MetricFu::AVAILABLE_GRAPHS
181
+ end
182
+ end
183
+
184
+ describe '#set_code_dirs ' do
185
+ it 'should set the @code_dirs instance var to ["app", "lib"]' do
186
+ # This is hard to spec properly because the @code_dirs variable
187
+ # is set during the reset process.
188
+ #@config.instance_variable_get(:@code_dirs).
189
+ # should == ['app','lib']
190
+ end
191
+ end
192
+ end
193
+
194
+ describe 'if #rails? is false ' do
195
+ before(:each) do
196
+ @config.stub!(:rails?).and_return(false)
197
+ end
198
+
199
+ describe '#set_metrics ' do
200
+ it 'should set the @metrics instance var to AVAILABLE_METRICS' do
201
+ @config.instance_variable_get(:@metrics).
202
+ should == MetricFu::AVAILABLE_METRICS
203
+ end
204
+ end
205
+
206
+ describe '#set_code_dirs ' do
207
+ it 'should set the @code_dirs instance var to ["lib"]' do
208
+ @config.instance_variable_get(:@code_dirs).should == ['lib']
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ describe '#add_attr_accessors_to_self' do
215
+
216
+ before(:each) { get_new_config }
217
+
218
+ MetricFu::AVAILABLE_METRICS.each do |metric|
219
+ it "should have a reader for #{metric}" do
220
+ @config.respond_to?(metric).should be_true
221
+ end
222
+
223
+ it "should have a writer for #{metric}=" do
224
+ @config.respond_to?((metric.to_s + '=').to_sym).should be_true
225
+ end
226
+ end
227
+ end
228
+
229
+ describe '#add_class_methods_to_metric_fu' do
230
+
231
+ before(:each) { get_new_config }
232
+
233
+ MetricFu::AVAILABLE_METRICS.each do |metric|
234
+ it "should add a #{metric} class method to the MetricFu module " do
235
+ MetricFu.should respond_to(metric)
236
+ end
237
+ end
238
+
239
+ MetricFu::AVAILABLE_GRAPHS.each do |graph|
240
+ it "should add a #{graph} class metrhod to the MetricFu module" do
241
+ MetricFu.should respond_to(graph)
242
+ end
243
+ end
244
+ end
245
+
246
+ describe '#platform' do
247
+
248
+ before(:each) { get_new_config }
249
+
250
+ it 'should return the value of the PLATFORM constant' do
251
+ this_platform = RUBY_PLATFORM
252
+ @config.platform.should == this_platform
253
+ end
254
+ end
255
+
256
+ describe '#is_cruise_control_rb? ' do
257
+
258
+ before(:each) { get_new_config }
259
+ describe "when the CC_BUILD_ARTIFACTS env var is not nil" do
260
+
261
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'is set' }
262
+
263
+ it 'should return true' do
264
+ @config.is_cruise_control_rb?.should be_true
265
+ end
266
+
267
+ end
268
+
269
+ describe "when the CC_BUILD_ARTIFACTS env var is nil" do
270
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
271
+
272
+ it 'should return false' do
273
+ @config.is_cruise_control_rb?.should be_false
274
+ end
275
+ end
276
+ end
277
+ end