khall-metric_fu 1.0.2.1
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.
- data/HISTORY +119 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +25 -0
- data/README +1 -0
- data/Rakefile +46 -0
- data/TODO +14 -0
- data/lib/base/base_template.rb +134 -0
- data/lib/base/configuration.rb +187 -0
- data/lib/base/generator.rb +147 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +86 -0
- data/lib/generators/flay.rb +29 -0
- data/lib/generators/flog.rb +127 -0
- data/lib/generators/rcov.rb +77 -0
- data/lib/generators/reek.rb +32 -0
- data/lib/generators/roodi.rb +24 -0
- data/lib/generators/saikuro.rb +212 -0
- data/lib/generators/stats.rb +43 -0
- data/lib/metric_fu.rb +20 -0
- data/lib/templates/standard/churn.html.erb +30 -0
- data/lib/templates/standard/default.css +64 -0
- data/lib/templates/standard/flay.html.erb +33 -0
- data/lib/templates/standard/flog.html.erb +52 -0
- data/lib/templates/standard/index.html.erb +38 -0
- data/lib/templates/standard/rcov.html.erb +42 -0
- data/lib/templates/standard/reek.html.erb +41 -0
- data/lib/templates/standard/roodi.html.erb +28 -0
- data/lib/templates/standard/saikuro.html.erb +83 -0
- data/lib/templates/standard/standard_template.rb +26 -0
- data/lib/templates/standard/stats.html.erb +54 -0
- data/spec/base/base_template_spec.rb +140 -0
- data/spec/base/configuration_spec.rb +303 -0
- data/spec/base/generator_spec.rb +159 -0
- data/spec/base/md5_tracker_spec.rb +57 -0
- data/spec/base/report_spec.rb +139 -0
- data/spec/generators/churn_spec.rb +152 -0
- data/spec/generators/flay_spec.rb +101 -0
- data/spec/generators/flog_spec.rb +200 -0
- data/spec/generators/reek_spec.rb +59 -0
- data/spec/generators/saikuro_spec.rb +53 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/spec_helper.rb +28 -0
- data/tasks/metric_fu.rake +15 -0
- data/tasks/railroad.rake +39 -0
- data/vendor/saikuro/saikuro.rb +1214 -0
- metadata +163 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
class StandardTemplate < MetricFu::Template
|
2
|
+
|
3
|
+
|
4
|
+
def write
|
5
|
+
report.each_pair do |section, contents|
|
6
|
+
if template_exists?(section)
|
7
|
+
create_instance_var(section, contents)
|
8
|
+
html = erbify(section)
|
9
|
+
fn = output_filename(section)
|
10
|
+
MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Instance variables we need should already be created from above
|
15
|
+
if template_exists?('index')
|
16
|
+
html = erbify('index')
|
17
|
+
fn = output_filename('index')
|
18
|
+
MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def this_directory
|
23
|
+
File.dirname(__FILE__)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,54 @@
|
|
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
|
+
<p>Rails rake stats results.</p>
|
12
|
+
<table>
|
13
|
+
<tr>
|
14
|
+
<th>Lines of Code</th>
|
15
|
+
<th>Lines of Test</th>
|
16
|
+
<th>Code to test ratio</th>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td><%= @stats[:codeLOC] %></td>
|
20
|
+
<td><%= @stats[:testLOC] %></td>
|
21
|
+
<td>1:<%= @stats[:code_to_test_ratio] %></td>
|
22
|
+
</tr>
|
23
|
+
</table>
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<tr>
|
27
|
+
<th>Name</th>
|
28
|
+
<th>Lines</th>
|
29
|
+
<th>LOC</th>
|
30
|
+
<th>Classes</th>
|
31
|
+
<th>Methods</th>
|
32
|
+
<th>Methods per class</th>
|
33
|
+
<th>LOC per method</th>
|
34
|
+
</tr>
|
35
|
+
<% count = 0 %>
|
36
|
+
<% @stats[:lines].each do |line| %>
|
37
|
+
<tr>
|
38
|
+
<td><%= line[:name] %></td>
|
39
|
+
<td><%= line[:lines] %></td>
|
40
|
+
<td><%= line[:loc] %></td>
|
41
|
+
<td><%= line[:classes] %></td>
|
42
|
+
<td><%= line[:methods] %></td>
|
43
|
+
<td><%= line[:methods_per_class] %></td>
|
44
|
+
<td><%= line[:loc_per_method] %></td>
|
45
|
+
</tr>
|
46
|
+
<% count += 1 %>
|
47
|
+
<% end %>
|
48
|
+
</table>
|
49
|
+
|
50
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
51
|
+
</body>
|
52
|
+
</html>
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper.rb"
|
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.should_receive(:platform).and_return('universal-darwin-9.0')
|
91
|
+
MetricFu.stub!(:configuration).and_return(config)
|
92
|
+
File.should_receive(:expand_path).and_return('filename')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return a textmate protocol link' do
|
96
|
+
name = "filename"
|
97
|
+
result = @template.send(:link_to_filename, name)
|
98
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
99
|
+
+ "filename&line='>filename:</a>")
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "when on other platforms" do
|
105
|
+
before(:each) do
|
106
|
+
config = mock("configuration")
|
107
|
+
config.should_receive(:platform).and_return('other')
|
108
|
+
MetricFu.stub!(:configuration).and_return(config)
|
109
|
+
File.should_receive(:expand_path).and_return('filename')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return a file protocol link' do
|
113
|
+
name = "filename"
|
114
|
+
result = @template.send(:link_to_filename, name)
|
115
|
+
result.should == "<a href='file://filename'>filename:</a>"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#cycle" do
|
121
|
+
it 'should return the first_value passed if iteration passed is even' do
|
122
|
+
first_val = "first"
|
123
|
+
second_val = "second"
|
124
|
+
iter = 2
|
125
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
126
|
+
result.should == first_val
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should return the second_value passed if iteration passed is odd' do
|
130
|
+
first_val = "first"
|
131
|
+
second_val = "second"
|
132
|
+
iter = 1
|
133
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
134
|
+
result.should == second_val
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper.rb"
|
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 '#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
|
+
describe "#reset" do
|
81
|
+
|
82
|
+
before(:each) { get_new_config }
|
83
|
+
|
84
|
+
describe 'when there is a CC_BUILD_ARTIFACTS environment variable' do
|
85
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'foo' }
|
86
|
+
|
87
|
+
it 'should return the CC_BUILD_ARTIFACTS environment variable' do
|
88
|
+
get_new_config
|
89
|
+
base_directory.should == ENV['CC_BUILD_ARTIFACTS']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'when there is no CC_BUILD_ARTIFACTS environment variable' do
|
94
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
|
95
|
+
|
96
|
+
it 'should return "tmp/metric_fu"' do
|
97
|
+
get_new_config
|
98
|
+
base_directory.should == "tmp/metric_fu"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should set @metric_fu_root_directory to the base of the '+
|
103
|
+
'metric_fu application' do
|
104
|
+
app_root = File.join(File.dirname(__FILE__), '..', '..')
|
105
|
+
app_root_absolute_path = File.expand_path(app_root)
|
106
|
+
metric_fu_absolute_path = File.expand_path(metric_fu_root)
|
107
|
+
metric_fu_absolute_path.should == app_root_absolute_path
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should set @template_directory to the lib/templates relative '+
|
111
|
+
'to @metric_fu_root_directory' do
|
112
|
+
template_dir = File.join(File.dirname(__FILE__),
|
113
|
+
'..', '..', 'lib','templates')
|
114
|
+
template_dir_abs_path = File.expand_path(template_dir)
|
115
|
+
calc_template_dir_abs_path = File.expand_path(template_directory)
|
116
|
+
calc_template_dir_abs_path.should == template_dir_abs_path
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should set @scratch_directory to scratch relative '+
|
120
|
+
'to @base_directory' do
|
121
|
+
scratch_dir = File.join(base_directory, 'scratch')
|
122
|
+
scratch_directory.should == scratch_dir
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should set @output_directory to output relative '+
|
126
|
+
'to @base_directory' do
|
127
|
+
output_dir = File.join(base_directory, 'output')
|
128
|
+
output_directory.should == output_dir
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should set @template_class to StandardTemplate' do
|
132
|
+
template_class.should == StandardTemplate
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
|
136
|
+
@config.instance_variable_get(:@flay).
|
137
|
+
should == {:dirs_to_flay => ['lib']}
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
|
141
|
+
@config.instance_variable_get(:@flog).
|
142
|
+
should == {:dirs_to_flog => ['lib']}
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
|
146
|
+
@config.instance_variable_get(:@reek).
|
147
|
+
should == {:dirs_to_reek => ['lib']}
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
|
151
|
+
@config.instance_variable_get(:@roodi).
|
152
|
+
should == {:dirs_to_roodi => ['lib']}
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should set @churn to {}' do
|
156
|
+
@config.instance_variable_get(:@churn).
|
157
|
+
should == {}
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should set @stats to {}' do
|
161
|
+
@config.instance_variable_get(:@stats).
|
162
|
+
should == {}
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should set @rcov to { :test_files => ["test/**/*_test.rb",
|
166
|
+
"spec/**/*_spec.rb"]
|
167
|
+
:rcov_opts => ["--sort coverage",
|
168
|
+
"--no-html",
|
169
|
+
"--text-coverage",
|
170
|
+
"--no-color",
|
171
|
+
"--profile",
|
172
|
+
"--rails",
|
173
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}' do
|
174
|
+
@config.instance_variable_get(:@rcov).
|
175
|
+
should == { :test_files => ['test/**/*_test.rb',
|
176
|
+
'spec/**/*_spec.rb'],
|
177
|
+
:rcov_opts => ["--sort coverage",
|
178
|
+
"--no-html",
|
179
|
+
"--text-coverage",
|
180
|
+
"--no-color",
|
181
|
+
"--profile",
|
182
|
+
"--rails",
|
183
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
|
187
|
+
:input_directory => @code_dirs,
|
188
|
+
:cyclo => "",
|
189
|
+
:filter_cyclo => "0",
|
190
|
+
:warn_cyclo => "5",
|
191
|
+
:error_cyclo => "7",
|
192
|
+
:formater => "text" }' do
|
193
|
+
@config.instance_variable_get(:@saikuro).
|
194
|
+
should == { :output_directory => 'tmp/metric_fu/scratch/saikuro',
|
195
|
+
:input_directory => ['lib'],
|
196
|
+
:cyclo => "",
|
197
|
+
:filter_cyclo => "0",
|
198
|
+
:warn_cyclo => "5",
|
199
|
+
:error_cyclo => "7",
|
200
|
+
:formater => "text"}
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'if #rails? is true ' do
|
204
|
+
before(:each) do
|
205
|
+
@config.stub!(:rails?).and_return(true)
|
206
|
+
end
|
207
|
+
|
208
|
+
describe '#set_metrics ' do
|
209
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS + '\
|
210
|
+
+'[:stats]' do
|
211
|
+
@config.instance_variable_get(:@metrics).
|
212
|
+
should == MetricFu::AVAILABLE_METRICS << [:stats]
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#set_code_dirs ' do
|
217
|
+
it 'should set the @code_dirs instance var to ["app", "lib"]' do
|
218
|
+
# This is hard to spec properly because the @code_dirs variable
|
219
|
+
# is set during the reset process.
|
220
|
+
#@config.instance_variable_get(:@code_dirs).
|
221
|
+
# should == ['app','lib']
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'if #rails? is false ' do
|
227
|
+
before(:each) do
|
228
|
+
@config.stub!(:rails?).and_return(false)
|
229
|
+
end
|
230
|
+
|
231
|
+
describe '#set_metrics ' do
|
232
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS' do
|
233
|
+
@config.instance_variable_get(:@metrics).
|
234
|
+
should == MetricFu::AVAILABLE_METRICS
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe '#set_code_dirs ' do
|
239
|
+
it 'should set the @code_dirs instance var to ["lib"]' do
|
240
|
+
@config.instance_variable_get(:@code_dirs).should == ['lib']
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#add_attr_accessors_to_self' do
|
247
|
+
|
248
|
+
before(:each) { get_new_config }
|
249
|
+
|
250
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
251
|
+
it "should have a reader for #{metric}" do
|
252
|
+
@config.respond_to?(metric).should be_true
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should have a writer for #{metric}=" do
|
256
|
+
@config.respond_to?((metric.to_s + '=').to_sym).should be_true
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe '#add_class_methods_to_metric_fu' do
|
262
|
+
|
263
|
+
before(:each) { get_new_config }
|
264
|
+
|
265
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
266
|
+
it "should add a #{metric} class method to the MetricFu module " do
|
267
|
+
MetricFu.respond_to?(metric).should be_true
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe '#platform' do
|
273
|
+
|
274
|
+
before(:each) { get_new_config }
|
275
|
+
|
276
|
+
it 'should return the value of the PLATFORM constant' do
|
277
|
+
this_platform = PLATFORM
|
278
|
+
@config.platform.should == this_platform
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe '#is_cruise_control_rb? ' do
|
283
|
+
|
284
|
+
before(:each) { get_new_config }
|
285
|
+
describe "when the CC_BUILD_ARTIFACTS env var is not nil" do
|
286
|
+
|
287
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'is set' }
|
288
|
+
|
289
|
+
it 'should return true' do
|
290
|
+
@config.is_cruise_control_rb?.should be_true
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "when the CC_BUILD_ARTIFACTS env var is nil" do
|
296
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
|
297
|
+
|
298
|
+
it 'should return false' do
|
299
|
+
@config.is_cruise_control_rb?.should be_false
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper.rb"
|
2
|
+
|
3
|
+
describe MetricFu::Generator do
|
4
|
+
|
5
|
+
MetricFu::Configuration.run do |config|
|
6
|
+
end
|
7
|
+
|
8
|
+
class ConcreteClass < MetricFu::Generator
|
9
|
+
def emit
|
10
|
+
end
|
11
|
+
|
12
|
+
def analyze
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@concrete_class = ConcreteClass.new
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "ConcreteClass#class_name" do
|
24
|
+
it "should be 'concreteclass'" do
|
25
|
+
ConcreteClass.class_name.should == 'concreteclass'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "ConcreteClass#metric_directory" do
|
30
|
+
it "should be 'tmp/metric_fu/scratch/concreteclass'" do
|
31
|
+
ConcreteClass.metric_directory.
|
32
|
+
should == "tmp/metric_fu/scratch/concreteclass"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#create_metric_dir_if_missing " do
|
37
|
+
describe "when the metric_dir exists " do
|
38
|
+
it 'should not call mkdir_p on FileUtils' do
|
39
|
+
File.stub!(:directory?).and_return(true)
|
40
|
+
FileUtils.should_not_receive(:mkdir_p)
|
41
|
+
@concrete_class.create_metric_dir_if_missing
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when the metric_dir does not exist " do
|
46
|
+
it 'should call mkdir_p on FileUtils' do
|
47
|
+
File.stub!(:directory?).and_return(false)
|
48
|
+
FileUtils.should_receive(:mkdir_p)
|
49
|
+
@concrete_class.create_metric_dir_if_missing
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#create_output_dir_if_missing" do
|
55
|
+
describe "when the output_dir exists " do
|
56
|
+
it 'should not call mkdir_p on FileUtils' do
|
57
|
+
File.stub!(:directory?).and_return(true)
|
58
|
+
FileUtils.should_not_receive(:mkdir_p)
|
59
|
+
@concrete_class.create_output_dir_if_missing
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when the output_dir does not exist " do
|
64
|
+
it 'should call mkdir_p on FileUtils' do
|
65
|
+
File.stub!(:directory?).and_return(false)
|
66
|
+
FileUtils.should_receive(:mkdir_p)
|
67
|
+
@concrete_class.create_output_dir_if_missing
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#metric_directory' do
|
73
|
+
it 'should return the results of ConcreteClass#metric_directory' do
|
74
|
+
ConcreteClass.stub!(:metric_directory).and_return('foo')
|
75
|
+
@concrete_class.metric_directory.should == 'foo'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'ConcreteClass#generate_report' do
|
80
|
+
it 'should create a new instance of ConcreteClass' do
|
81
|
+
ConcreteClass.should_receive(:new).and_return(@concrete_class)
|
82
|
+
@concrete_class.should_receive(:generate_report).and_return(true)
|
83
|
+
ConcreteClass.generate_report
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should call #generate_report on the new ConcreteClass' do
|
87
|
+
ConcreteClass.should_receive(:new).and_return(@concrete_class)
|
88
|
+
@concrete_class.should_receive(:generate_report).and_return(true)
|
89
|
+
ConcreteClass.generate_report
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '@concrete_class should have hook methods for '\
|
94
|
+
+'[before|after]_[emit|analyze|to_h]' do
|
95
|
+
|
96
|
+
%w[emit analyze].each do |meth|
|
97
|
+
|
98
|
+
it "should respond to #before_#{meth}" do
|
99
|
+
@concrete_class.respond_to?("before_#{meth}".to_sym).should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should respond to #after_#{meth}" do
|
103
|
+
@concrete_class.respond_to?("after_#{meth}".to_sym).should be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should respond to #before_to_h" do
|
108
|
+
@concrete_class.respond_to?("before_to_h".to_sym).should be_true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#generate_report" do
|
113
|
+
it 'should raise an error when calling #emit' do
|
114
|
+
@abstract_class = MetricFu::Generator.new
|
115
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should call #analyze' do
|
119
|
+
@abstract_class = MetricFu::Generator.new
|
120
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should call #to_h' do
|
124
|
+
@abstract_class = MetricFu::Generator.new
|
125
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#generate_report (in a concrete class)" do
|
130
|
+
|
131
|
+
%w[emit analyze].each do |meth|
|
132
|
+
it "should call #before_#{meth}" do
|
133
|
+
@concrete_class.should_receive("before_#{meth}")
|
134
|
+
@concrete_class.generate_report
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should call ##{meth}" do
|
138
|
+
@concrete_class.should_receive("#{meth}")
|
139
|
+
@concrete_class.generate_report
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should call #after_#{meth}" do
|
143
|
+
@concrete_class.should_receive("after_#{meth}")
|
144
|
+
@concrete_class.generate_report
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should call #before_to_h" do
|
149
|
+
@concrete_class.should_receive("before_to_h")
|
150
|
+
@concrete_class.generate_report
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should call #to_h" do
|
154
|
+
@concrete_class.should_receive(:to_h)
|
155
|
+
@concrete_class.generate_report
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|