pjstadig-metric_fu 1.1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +155 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +25 -0
- data/README +1 -0
- data/Rakefile +18 -0
- data/TODO +9 -0
- data/lib/base/base_template.rb +146 -0
- data/lib/base/configuration.rb +187 -0
- data/lib/base/generator.rb +160 -0
- data/lib/base/graph.rb +38 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +90 -0
- data/lib/generators/flay.rb +33 -0
- data/lib/generators/flog.rb +140 -0
- data/lib/generators/rcov.rb +91 -0
- data/lib/generators/reek.rb +37 -0
- data/lib/generators/roodi.rb +31 -0
- data/lib/generators/saikuro.rb +208 -0
- data/lib/generators/stats.rb +43 -0
- data/lib/graphs/flay_grapher.rb +35 -0
- data/lib/graphs/flog_grapher.rb +51 -0
- data/lib/graphs/grapher.rb +19 -0
- data/lib/graphs/rcov_grapher.rb +34 -0
- data/lib/graphs/reek_grapher.rb +44 -0
- data/lib/graphs/roodi_grapher.rb +34 -0
- data/lib/metric_fu.rb +30 -0
- data/lib/templates/awesome/awesome_template.rb +30 -0
- data/lib/templates/awesome/churn.html.erb +19 -0
- data/lib/templates/awesome/css/buttons.css +82 -0
- data/lib/templates/awesome/css/default.css +75 -0
- data/lib/templates/awesome/css/integrity.css +335 -0
- data/lib/templates/awesome/css/reset.css +7 -0
- data/lib/templates/awesome/flay.html.erb +27 -0
- data/lib/templates/awesome/flog.html.erb +47 -0
- data/lib/templates/awesome/index.html.erb +28 -0
- data/lib/templates/awesome/layout.html.erb +27 -0
- data/lib/templates/awesome/rcov.html.erb +36 -0
- data/lib/templates/awesome/reek.html.erb +34 -0
- data/lib/templates/awesome/roodi.html.erb +21 -0
- data/lib/templates/awesome/saikuro.html.erb +71 -0
- data/lib/templates/awesome/stats.html.erb +41 -0
- data/lib/templates/standard/churn.html.erb +31 -0
- data/lib/templates/standard/default.css +64 -0
- data/lib/templates/standard/flay.html.erb +34 -0
- data/lib/templates/standard/flog.html.erb +53 -0
- data/lib/templates/standard/index.html.erb +38 -0
- data/lib/templates/standard/rcov.html.erb +43 -0
- data/lib/templates/standard/reek.html.erb +42 -0
- data/lib/templates/standard/roodi.html.erb +29 -0
- data/lib/templates/standard/saikuro.html.erb +84 -0
- data/lib/templates/standard/standard_template.rb +26 -0
- data/lib/templates/standard/stats.html.erb +55 -0
- data/spec/base/base_template_spec.rb +161 -0
- data/spec/base/configuration_spec.rb +300 -0
- data/spec/base/generator_spec.rb +181 -0
- data/spec/base/graph_spec.rb +24 -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 +104 -0
- data/spec/generators/flog_spec.rb +219 -0
- data/spec/generators/reek_spec.rb +60 -0
- data/spec/generators/saikuro_spec.rb +58 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/graphs/flay_grapher_spec.rb +44 -0
- data/spec/graphs/flog_grapher_spec.rb +61 -0
- data/spec/graphs/grapher_spec.rb +9 -0
- data/spec/graphs/rcov_grapher_spec.rb +44 -0
- data/spec/graphs/reek_grapher_spec.rb +53 -0
- data/spec/graphs/roodi_grapher_spec.rb +44 -0
- data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/resources/saikuro/index_cyclo.html +155 -0
- data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/resources/yml/20090630.yml +7844 -0
- data/spec/spec.opts +8 -0
- data/spec/spec_helper.rb +6 -0
- data/tasks/metric_fu.rake +22 -0
- data/vendor/_fonts/monaco.ttf +0 -0
- data/vendor/saikuro/saikuro.rb +1219 -0
- metadata +180 -0
@@ -0,0 +1,300 @@
|
|
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']}
|
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 == {: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 == {: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 @rcov to { :test_files => ["test/**/*_test.rb",
|
119
|
+
"spec/**/*_spec.rb"]
|
120
|
+
:rcov_opts => ["--sort coverage",
|
121
|
+
"--no-html",
|
122
|
+
"--text-coverage",
|
123
|
+
"--no-color",
|
124
|
+
"--profile",
|
125
|
+
"--rails",
|
126
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}' do
|
127
|
+
@config.instance_variable_get(:@rcov).
|
128
|
+
should == { :test_files => ['test/**/*_test.rb',
|
129
|
+
'spec/**/*_spec.rb'],
|
130
|
+
:rcov_opts => ["--sort coverage",
|
131
|
+
"--no-html",
|
132
|
+
"--text-coverage",
|
133
|
+
"--no-color",
|
134
|
+
"--profile",
|
135
|
+
"--rails",
|
136
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
|
140
|
+
:input_directory => @code_dirs,
|
141
|
+
:cyclo => "",
|
142
|
+
:filter_cyclo => "0",
|
143
|
+
:warn_cyclo => "5",
|
144
|
+
:error_cyclo => "7",
|
145
|
+
:formater => "text" }' do
|
146
|
+
@config.instance_variable_get(:@saikuro).
|
147
|
+
should == { :output_directory => "#{scratch_directory}/saikuro",
|
148
|
+
:input_directory => ['lib'],
|
149
|
+
:cyclo => "",
|
150
|
+
:filter_cyclo => "0",
|
151
|
+
:warn_cyclo => "5",
|
152
|
+
:error_cyclo => "7",
|
153
|
+
:formater => "text"}
|
154
|
+
end
|
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
|
+
|
187
|
+
describe 'if #rails? is true ' do
|
188
|
+
before(:each) do
|
189
|
+
@config.stub!(:rails?).and_return(true)
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#set_metrics ' do
|
193
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS + '\
|
194
|
+
+'[:stats]' do
|
195
|
+
@config.instance_variable_get(:@metrics).
|
196
|
+
should == MetricFu::AVAILABLE_METRICS << [:stats]
|
197
|
+
end
|
198
|
+
end
|
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
|
+
|
207
|
+
describe '#set_code_dirs ' do
|
208
|
+
it 'should set the @code_dirs instance var to ["app", "lib"]' do
|
209
|
+
# This is hard to spec properly because the @code_dirs variable
|
210
|
+
# is set during the reset process.
|
211
|
+
#@config.instance_variable_get(:@code_dirs).
|
212
|
+
# should == ['app','lib']
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'if #rails? is false ' do
|
218
|
+
before(:each) do
|
219
|
+
@config.stub!(:rails?).and_return(false)
|
220
|
+
end
|
221
|
+
|
222
|
+
describe '#set_metrics ' do
|
223
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS' do
|
224
|
+
@config.instance_variable_get(:@metrics).
|
225
|
+
should == MetricFu::AVAILABLE_METRICS
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe '#set_code_dirs ' do
|
230
|
+
it 'should set the @code_dirs instance var to ["lib"]' do
|
231
|
+
@config.instance_variable_get(:@code_dirs).should == ['lib']
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe '#add_attr_accessors_to_self' do
|
238
|
+
|
239
|
+
before(:each) { get_new_config }
|
240
|
+
|
241
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
242
|
+
it "should have a reader for #{metric}" do
|
243
|
+
@config.respond_to?(metric).should be_true
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should have a writer for #{metric}=" do
|
247
|
+
@config.respond_to?((metric.to_s + '=').to_sym).should be_true
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe '#add_class_methods_to_metric_fu' do
|
253
|
+
|
254
|
+
before(:each) { get_new_config }
|
255
|
+
|
256
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
257
|
+
it "should add a #{metric} class method to the MetricFu module " do
|
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)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#platform' do
|
270
|
+
|
271
|
+
before(:each) { get_new_config }
|
272
|
+
|
273
|
+
it 'should return the value of the PLATFORM constant' do
|
274
|
+
this_platform = RUBY_PLATFORM
|
275
|
+
@config.platform.should == this_platform
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe '#is_cruise_control_rb? ' do
|
280
|
+
|
281
|
+
before(:each) { get_new_config }
|
282
|
+
describe "when the CC_BUILD_ARTIFACTS env var is not nil" do
|
283
|
+
|
284
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'is set' }
|
285
|
+
|
286
|
+
it 'should return true' do
|
287
|
+
@config.is_cruise_control_rb?.should be_true
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "when the CC_BUILD_ARTIFACTS env var is nil" do
|
293
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
|
294
|
+
|
295
|
+
it 'should return false' do
|
296
|
+
@config.is_cruise_control_rb?.should be_false
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
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
|
+
it "should raise error if the concrete class is missing a required dependency" do
|
159
|
+
concrete_class_with_missing_gem = Class.new(MetricFu::Generator) do
|
160
|
+
def self.verify_dependencies!
|
161
|
+
raise 'gem install something # if you want these tasks'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
lambda { concrete_class_with_missing_gem.generate_report }.should raise_error("gem install something # if you want these tasks")
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "instantiation" do
|
170
|
+
it "should fail is dependencies not verified" do
|
171
|
+
ConcreteClass.should_receive(:verify_dependencies!).and_raise("Missing a required gem. Please 'gem install something'")
|
172
|
+
lambda { ConcreteClass.new() }.should raise_error("Missing a required gem. Please 'gem install something'")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should succeed when dependencies verified" do
|
176
|
+
ConcreteClass.should_receive(:verify_dependencies!).and_return(true)
|
177
|
+
ConcreteClass.new()
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|