goldstar-metric_fu 1.5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +208 -0
- data/MIT-LICENSE +22 -0
- data/README +28 -0
- data/Rakefile +16 -0
- data/TODO +9 -0
- data/lib/base/base_template.rb +151 -0
- data/lib/base/configuration.rb +190 -0
- data/lib/base/generator.rb +162 -0
- data/lib/base/graph.rb +39 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +28 -0
- data/lib/generators/flay.rb +31 -0
- data/lib/generators/flog.rb +98 -0
- data/lib/generators/rails_best_practices.rb +25 -0
- data/lib/generators/rcov.rb +85 -0
- data/lib/generators/reek.rb +60 -0
- data/lib/generators/roodi.rb +27 -0
- data/lib/generators/saikuro.rb +224 -0
- data/lib/generators/stats.rb +59 -0
- data/lib/graphs/engines/bluff.rb +113 -0
- data/lib/graphs/engines/gchart.rb +157 -0
- data/lib/graphs/flay_grapher.rb +18 -0
- data/lib/graphs/flog_grapher.rb +57 -0
- data/lib/graphs/grapher.rb +11 -0
- data/lib/graphs/rails_best_practices_grapher.rb +19 -0
- data/lib/graphs/rcov_grapher.rb +18 -0
- data/lib/graphs/reek_grapher.rb +30 -0
- data/lib/graphs/roodi_grapher.rb +18 -0
- data/lib/graphs/stats_grapher.rb +20 -0
- data/lib/metric_fu.rb +37 -0
- data/lib/templates/awesome/awesome_template.rb +37 -0
- data/lib/templates/awesome/churn.html.erb +58 -0
- data/lib/templates/awesome/css/buttons.css +82 -0
- data/lib/templates/awesome/css/default.css +91 -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 +34 -0
- data/lib/templates/awesome/flog.html.erb +55 -0
- data/lib/templates/awesome/index.html.erb +31 -0
- data/lib/templates/awesome/layout.html.erb +30 -0
- data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
- data/lib/templates/awesome/rcov.html.erb +42 -0
- data/lib/templates/awesome/reek.html.erb +40 -0
- data/lib/templates/awesome/roodi.html.erb +27 -0
- data/lib/templates/awesome/saikuro.html.erb +71 -0
- data/lib/templates/awesome/stats.html.erb +51 -0
- data/lib/templates/javascripts/bluff-min.js +1 -0
- data/lib/templates/javascripts/excanvas.js +35 -0
- data/lib/templates/javascripts/js-class.js +1 -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 +57 -0
- data/lib/templates/standard/index.html.erb +41 -0
- data/lib/templates/standard/rails_best_practices.html.erb +29 -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 +276 -0
- data/spec/base/generator_spec.rb +223 -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 +41 -0
- data/spec/generators/flay_spec.rb +105 -0
- data/spec/generators/flog_spec.rb +70 -0
- data/spec/generators/reek_spec.rb +134 -0
- data/spec/generators/saikuro_spec.rb +58 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/graphs/engines/bluff_spec.rb +19 -0
- data/spec/graphs/engines/gchart_spec.rb +156 -0
- data/spec/graphs/flay_grapher_spec.rb +56 -0
- data/spec/graphs/flog_grapher_spec.rb +108 -0
- data/spec/graphs/rcov_grapher_spec.rb +56 -0
- data/spec/graphs/reek_grapher_spec.rb +65 -0
- data/spec/graphs/roodi_grapher_spec.rb +56 -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 +7922 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +7 -0
- data/tasks/metric_fu.rake +22 -0
- metadata +396 -0
@@ -0,0 +1,223 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe MetricFu::Generator do
|
4
|
+
|
5
|
+
include Construct::Helpers
|
6
|
+
|
7
|
+
MetricFu::Configuration.run do |config|
|
8
|
+
end
|
9
|
+
|
10
|
+
class ConcreteClass < MetricFu::Generator
|
11
|
+
def emit
|
12
|
+
end
|
13
|
+
|
14
|
+
def analyze
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@concrete_class = ConcreteClass.new
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "ConcreteClass#class_name" do
|
26
|
+
it "should be 'concreteclass'" do
|
27
|
+
ConcreteClass.class_name.should == 'concreteclass'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "ConcreteClass#metric_directory" do
|
32
|
+
it "should be 'tmp/metric_fu/scratch/concreteclass'" do
|
33
|
+
ConcreteClass.metric_directory.
|
34
|
+
should == "tmp/metric_fu/scratch/concreteclass"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#create_metric_dir_if_missing " do
|
39
|
+
describe "when the metric_dir exists " do
|
40
|
+
it 'should not call mkdir_p on FileUtils' do
|
41
|
+
File.stub!(:directory?).and_return(true)
|
42
|
+
FileUtils.should_not_receive(:mkdir_p)
|
43
|
+
@concrete_class.create_metric_dir_if_missing
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when the metric_dir does not exist " do
|
48
|
+
it 'should call mkdir_p on FileUtils' do
|
49
|
+
File.stub!(:directory?).and_return(false)
|
50
|
+
FileUtils.should_receive(:mkdir_p)
|
51
|
+
@concrete_class.create_metric_dir_if_missing
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#create_output_dir_if_missing" do
|
57
|
+
describe "when the output_dir exists " do
|
58
|
+
it 'should not call mkdir_p on FileUtils' do
|
59
|
+
File.stub!(:directory?).and_return(true)
|
60
|
+
FileUtils.should_not_receive(:mkdir_p)
|
61
|
+
@concrete_class.create_output_dir_if_missing
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when the output_dir does not exist " do
|
66
|
+
it 'should call mkdir_p on FileUtils' do
|
67
|
+
File.stub!(:directory?).and_return(false)
|
68
|
+
FileUtils.should_receive(:mkdir_p)
|
69
|
+
@concrete_class.create_output_dir_if_missing
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#metric_directory' do
|
75
|
+
it 'should return the results of ConcreteClass#metric_directory' do
|
76
|
+
ConcreteClass.stub!(:metric_directory).and_return('foo')
|
77
|
+
@concrete_class.metric_directory.should == 'foo'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'ConcreteClass#generate_report' do
|
82
|
+
it 'should create a new instance of ConcreteClass' do
|
83
|
+
ConcreteClass.should_receive(:new).and_return(@concrete_class)
|
84
|
+
@concrete_class.should_receive(:generate_report).and_return(true)
|
85
|
+
ConcreteClass.generate_report
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should call #generate_report on the new ConcreteClass' do
|
89
|
+
ConcreteClass.should_receive(:new).and_return(@concrete_class)
|
90
|
+
@concrete_class.should_receive(:generate_report).and_return(true)
|
91
|
+
ConcreteClass.generate_report
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '@concrete_class should have hook methods for '\
|
96
|
+
+'[before|after]_[emit|analyze|to_h]' do
|
97
|
+
|
98
|
+
%w[emit analyze].each do |meth|
|
99
|
+
|
100
|
+
it "should respond to #before_#{meth}" do
|
101
|
+
@concrete_class.respond_to?("before_#{meth}".to_sym).should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should respond to #after_#{meth}" do
|
105
|
+
@concrete_class.respond_to?("after_#{meth}".to_sym).should be_true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should respond to #before_to_h" do
|
110
|
+
@concrete_class.respond_to?("before_to_h".to_sym).should be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#generate_report" do
|
115
|
+
it 'should raise an error when calling #emit' do
|
116
|
+
@abstract_class = MetricFu::Generator.new
|
117
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should call #analyze' do
|
121
|
+
@abstract_class = MetricFu::Generator.new
|
122
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should call #to_h' do
|
126
|
+
@abstract_class = MetricFu::Generator.new
|
127
|
+
lambda { @abstract_class.generate_report }.should raise_error
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#generate_report (in a concrete class)" do
|
132
|
+
|
133
|
+
%w[emit analyze].each do |meth|
|
134
|
+
it "should call #before_#{meth}" do
|
135
|
+
@concrete_class.should_receive("before_#{meth}")
|
136
|
+
@concrete_class.generate_report
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should call ##{meth}" do
|
140
|
+
@concrete_class.should_receive("#{meth}")
|
141
|
+
@concrete_class.generate_report
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should call #after_#{meth}" do
|
145
|
+
@concrete_class.should_receive("after_#{meth}")
|
146
|
+
@concrete_class.generate_report
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should call #before_to_h" do
|
151
|
+
@concrete_class.should_receive("before_to_h")
|
152
|
+
@concrete_class.generate_report
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should call #to_h" do
|
156
|
+
@concrete_class.should_receive(:to_h)
|
157
|
+
@concrete_class.generate_report
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "path filter" do
|
163
|
+
|
164
|
+
context "given a list of paths" do
|
165
|
+
|
166
|
+
before do
|
167
|
+
@paths = %w(lib/fake/fake.rb
|
168
|
+
lib/this/dan_file.rb
|
169
|
+
lib/this/ben_file.rb
|
170
|
+
lib/this/avdi_file.rb
|
171
|
+
basic.rb
|
172
|
+
lib/bad/one.rb
|
173
|
+
lib/bad/two.rb
|
174
|
+
lib/bad/three.rb
|
175
|
+
lib/worse/four.rb)
|
176
|
+
@container = create_construct
|
177
|
+
@paths.each do |path|
|
178
|
+
@container.file(path)
|
179
|
+
end
|
180
|
+
@old_dir = Dir.pwd
|
181
|
+
Dir.chdir(@container)
|
182
|
+
end
|
183
|
+
|
184
|
+
after do
|
185
|
+
Dir.chdir(@old_dir)
|
186
|
+
@container.destroy!
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should return entire pathlist given no exclude pattens" do
|
190
|
+
files = @concrete_class.remove_excluded_files(@paths)
|
191
|
+
files.should be == @paths
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should filter filename at root level" do
|
195
|
+
files = @concrete_class.remove_excluded_files(@paths, ['basic.rb'])
|
196
|
+
files.should_not include('basic.rb')
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should remove files that are two levels deep" do
|
200
|
+
files = @concrete_class.remove_excluded_files(@paths, ['**/fake.rb'])
|
201
|
+
files.should_not include('lib/fake/fake.rb')
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should remove files from an excluded directory" do
|
205
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/bad/**'])
|
206
|
+
files.should_not include('lib/bad/one.rb')
|
207
|
+
files.should_not include('lib/bad/two.rb')
|
208
|
+
files.should_not include('lib/bad/three.rb')
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should support shell alternation globs" do
|
212
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/this/{ben,dan}_file.rb'])
|
213
|
+
files.should_not include('lib/this/dan_file.rb')
|
214
|
+
files.should_not include('lib/this/ben_file.rb')
|
215
|
+
files.should include('lib/this/avdi_file.rb')
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
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 with gchart enabled" do
|
19
|
+
it 'should instantiate a grapher and push it to clazz' do
|
20
|
+
@graph.clazz.should_receive(:push).with(an_instance_of(RcovGchartGrapher))
|
21
|
+
@graph.add("rcov", 'gchart')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe MetricFu::MD5Tracker do
|
4
|
+
before do
|
5
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
6
|
+
FileUtils.mkdir_p(@tmp_dir, :verbose => false) unless File.directory?(@tmp_dir)
|
7
|
+
@file1 = File.new(File.join(@tmp_dir, 'file1.txt'), 'w')
|
8
|
+
@file2 = File.new(File.join(@tmp_dir, 'file2.txt'), 'w')
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
FileUtils.rm_rf(@tmp_dir, :verbose => false)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "identical files should match" do
|
16
|
+
@file1.puts("Hello World")
|
17
|
+
@file1.close
|
18
|
+
file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)
|
19
|
+
|
20
|
+
@file2.puts("Hello World")
|
21
|
+
@file2.close
|
22
|
+
file2_md5 = MD5Tracker.track(@file2.path, @tmp_dir)
|
23
|
+
|
24
|
+
file2_md5.should == file1_md5
|
25
|
+
end
|
26
|
+
|
27
|
+
it "different files should not match" do
|
28
|
+
@file1.puts("Hello World")
|
29
|
+
@file1.close
|
30
|
+
file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)
|
31
|
+
|
32
|
+
@file2.puts("Goodbye World")
|
33
|
+
@file2.close
|
34
|
+
file2_md5 = MD5Tracker.track(@file2.path, @tmp_dir)
|
35
|
+
|
36
|
+
file2_md5.should_not == file1_md5
|
37
|
+
end
|
38
|
+
|
39
|
+
it "file_changed? should detect a change" do
|
40
|
+
@file2.close
|
41
|
+
|
42
|
+
@file1.puts("Hello World")
|
43
|
+
@file1.close
|
44
|
+
file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)
|
45
|
+
|
46
|
+
@file1 = File.new(File.join(@tmp_dir, 'file1.txt'), 'w')
|
47
|
+
@file1.puts("Goodbye World")
|
48
|
+
@file1.close
|
49
|
+
MD5Tracker.file_changed?(@file1.path, @tmp_dir).should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should detect a new file" do
|
53
|
+
@file2.close
|
54
|
+
MD5Tracker.file_changed?(@file1.path, @tmp_dir).should be_true
|
55
|
+
File.exist?(MD5Tracker.md5_file(@file1.path, @tmp_dir)).should be_true
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe MetricFu do
|
4
|
+
|
5
|
+
describe "#report" do
|
6
|
+
it 'should return an instance of Report' do
|
7
|
+
MetricFu.report.instance_of?(Report).should be(true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe MetricFu::Report do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@report = MetricFu::Report.new
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#to_yaml" do
|
19
|
+
it 'should call #report_hash' do
|
20
|
+
report_hash = mock('report_hash')
|
21
|
+
report_hash.should_receive(:to_yaml)
|
22
|
+
@report.should_receive(:report_hash).and_return(report_hash)
|
23
|
+
@report.to_yaml
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#report_hash" do
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#save_templatized_report" do
|
31
|
+
it 'should create a new template class assign a report_hash '\
|
32
|
+
'to the template class, and ask it to write itself out' do
|
33
|
+
template_class = mock('template_class')
|
34
|
+
template_class.should_receive(:new).and_return(template_class)
|
35
|
+
MetricFu.should_receive(:template_class).and_return(template_class)
|
36
|
+
template_class.should_receive(:report=)
|
37
|
+
template_class.should_receive(:write)
|
38
|
+
@report.save_templatized_report
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#add" do
|
43
|
+
it 'should add a passed hash to the report_hash instance variable' do
|
44
|
+
report_type = mock('report_type')
|
45
|
+
report_type.should_receive(:to_s).and_return('type')
|
46
|
+
report_type.should_receive(:generate_report).and_return({:a => 'b'})
|
47
|
+
MetricFu.should_receive(:const_get).
|
48
|
+
with('Type').and_return(report_type)
|
49
|
+
report_hash = mock('report_hash')
|
50
|
+
report_hash.should_receive(:merge!).with({:a => 'b'})
|
51
|
+
@report.should_receive(:report_hash).and_return(report_hash)
|
52
|
+
@report.add(report_type)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#save_output" do
|
57
|
+
it 'should write the passed content to dir/index.html' do
|
58
|
+
f = mock('file')
|
59
|
+
content = 'content'
|
60
|
+
@report.should_receive(:open).with('dir/file', 'w').and_yield(f)
|
61
|
+
f.should_receive(:puts).with(content)
|
62
|
+
@report.save_output(content, 'dir', 'file')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#open_in_browser? ' do
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
@config = mock('configuration')
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'when the platform is os x ' do
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
@config.should_receive(:platform).and_return('darwin')
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'and we are in cruise control ' do
|
79
|
+
|
80
|
+
before(:each) do
|
81
|
+
@config.should_receive(:is_cruise_control_rb?).and_return(true)
|
82
|
+
MetricFu.stub!(:configuration).and_return(@config)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should return false' do
|
86
|
+
@report.open_in_browser?.should be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'and we are not in cruise control' do
|
91
|
+
|
92
|
+
before(:each) do
|
93
|
+
@config.should_receive(:is_cruise_control_rb?).and_return(false)
|
94
|
+
MetricFu.stub!(:configuration).and_return(@config)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return true' do
|
98
|
+
@report.open_in_browser?.should be_true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'when the platform is not os x ' do
|
104
|
+
before(:each) do
|
105
|
+
@config.should_receive(:platform).and_return('other')
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'and we are in cruise control' do
|
109
|
+
before(:each) do
|
110
|
+
MetricFu.stub!(:configuration).and_return(@config)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should return false' do
|
114
|
+
@report.open_in_browser?.should be_false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'and we are not in cruise control' do
|
119
|
+
before(:each) do
|
120
|
+
MetricFu.stub!(:configuration).and_return(@config)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should return false' do
|
124
|
+
@report.open_in_browser?.should be_false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
describe '#show_in_browser' do
|
132
|
+
it 'should call open with the passed directory' do
|
133
|
+
@report.should_receive(:open_in_browser?).and_return(true)
|
134
|
+
@report.should_receive(:system).with("open my_dir/index.html")
|
135
|
+
@report.show_in_browser('my_dir')
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Churn do
|
4
|
+
|
5
|
+
describe "analyze method" do
|
6
|
+
before :each do
|
7
|
+
MetricFu::Configuration.run {}
|
8
|
+
File.stub!(:directory?).and_return(true)
|
9
|
+
@changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be empty on error" do
|
13
|
+
churn = MetricFu::Churn.new
|
14
|
+
churn.instance_variable_set(:@output, "fatal: Not a git repository")
|
15
|
+
result = churn.analyze
|
16
|
+
result.should == [:churn => {}]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return yaml results" do
|
20
|
+
churn = MetricFu::Churn.new
|
21
|
+
churn.instance_variable_set(:@output, "--- \n:churn: \n :changed_files: \n - spec/graphs/flog_grapher_spec.rb\n - spec/base/graph_spec.rb\n - lib/templates/awesome/layout.html.erb\n - lib/graphs/rcov_grapher.rb\n - lib/base/base_template.rb\n - spec/graphs/grapher_spec.rb\n - lib/templates/awesome/flog.html.erb\n - lib/templates/awesome/flay.html.erb\n - lib/graphs/roodi_grapher.rb\n - lib/graphs/reek_grapher.rb\n - HISTORY\n - spec/graphs/roodi_grapher_spec.rb\n - lib/generators/rcov.rb\n - spec/graphs/engines/gchart_spec.rb\n - spec/graphs/rcov_grapher_spec.rb\n - lib/templates/javascripts/excanvas.js\n - lib/templates/javascripts/bluff-min.js\n - spec/graphs/reek_grapher_spec.rb\n")
|
22
|
+
result = churn.analyze
|
23
|
+
result.should == {:churn=>{:changed_files=>["spec/graphs/flog_grapher_spec.rb", "spec/base/graph_spec.rb", "lib/templates/awesome/layout.html.erb", "lib/graphs/rcov_grapher.rb", "lib/base/base_template.rb", "spec/graphs/grapher_spec.rb", "lib/templates/awesome/flog.html.erb", "lib/templates/awesome/flay.html.erb", "lib/graphs/roodi_grapher.rb", "lib/graphs/reek_grapher.rb", "HISTORY", "spec/graphs/roodi_grapher_spec.rb", "lib/generators/rcov.rb", "spec/graphs/engines/gchart_spec.rb", "spec/graphs/rcov_grapher_spec.rb", "lib/templates/javascripts/excanvas.js", "lib/templates/javascripts/bluff-min.js", "spec/graphs/reek_grapher_spec.rb"]}}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "to_h method" do
|
29
|
+
before :each do
|
30
|
+
MetricFu::Configuration.run {}
|
31
|
+
File.stub!(:directory?).and_return(true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should put the changes into a hash" do
|
35
|
+
churn = MetricFu::Churn.new
|
36
|
+
churn.instance_variable_set(:@churn, {:churn => 'results'})
|
37
|
+
churn.to_h[:churn].should == "results"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Flay do
|
4
|
+
describe "emit method" do
|
5
|
+
it "should look at the dirs" do
|
6
|
+
MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'], :filetypes => ['rb'] } }
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
@flay = MetricFu::Flay.new('base_dir')
|
9
|
+
|
10
|
+
@flay.should_receive(:`).with("flay app lib")
|
11
|
+
output = @flay.emit
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should limit flay scores by the minimum_score" do
|
15
|
+
MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
|
16
|
+
File.stub!(:directory?).and_return(true)
|
17
|
+
@flay = MetricFu::Flay.new('base_dir')
|
18
|
+
|
19
|
+
@flay.should_receive(:`).with("flay --mass 99 ")
|
20
|
+
output = @flay.emit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "analyze method" do
|
25
|
+
before :each do
|
26
|
+
lines = <<-HERE
|
27
|
+
Total score (lower is better) = 246
|
28
|
+
|
29
|
+
|
30
|
+
1) IDENTICAL code found in :or (mass*2 = 68)
|
31
|
+
app/controllers/link_targets_controller.rb:57
|
32
|
+
app/controllers/primary_sites_controller.rb:138
|
33
|
+
|
34
|
+
2) Similar code found in :if (mass = 64)
|
35
|
+
app/controllers/primary_sites_controller.rb:75
|
36
|
+
app/controllers/primary_sites_controller.rb:76
|
37
|
+
app/controllers/primary_sites_controller.rb:88
|
38
|
+
app/controllers/primary_sites_controller.rb:89
|
39
|
+
HERE
|
40
|
+
MetricFu::Configuration.run {}
|
41
|
+
File.stub!(:directory?).and_return(true)
|
42
|
+
@flay = MetricFu::Flay.new('base_dir')
|
43
|
+
@flay.instance_variable_set(:@output, lines)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should analyze and return matches" do
|
47
|
+
@flay.analyze.should == [ ["Total score (lower is better) = 246"],
|
48
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
49
|
+
"app/controllers/link_targets_controller.rb:57",
|
50
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
51
|
+
["2) Similar code found in :if (mass = 64)",
|
52
|
+
"app/controllers/primary_sites_controller.rb:75",
|
53
|
+
"app/controllers/primary_sites_controller.rb:76",
|
54
|
+
"app/controllers/primary_sites_controller.rb:88",
|
55
|
+
"app/controllers/primary_sites_controller.rb:89"] ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "to_h method" do
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
lines = [ ["Total score (lower is better) = 284"],
|
63
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
64
|
+
"app/controllers/link_targets_controller.rb:57",
|
65
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
66
|
+
["2) Similar code found in :if (mass = 64)",
|
67
|
+
"app/controllers/primary_sites_controller.rb:75",
|
68
|
+
"app/controllers/primary_sites_controller.rb:76",
|
69
|
+
"app/controllers/primary_sites_controller.rb:88",
|
70
|
+
"app/controllers/primary_sites_controller.rb:89"],
|
71
|
+
["3) Similar code found in :defn (mass = 40)",
|
72
|
+
"app/controllers/link_targets_controller.rb:40",
|
73
|
+
"app/controllers/primary_sites_controller.rb:98"],
|
74
|
+
["4) Similar code found in :defn (mass = 38)",
|
75
|
+
"app/controllers/link_targets_controller.rb:13",
|
76
|
+
"app/controllers/primary_sites_controller.rb:50"],
|
77
|
+
["5) Similar code found in :defn (mass = 38)",
|
78
|
+
"app/models/primary_site.rb:104",
|
79
|
+
"app/models/primary_site.rb:109"],
|
80
|
+
["6) Similar code found in :call (mass = 36)",
|
81
|
+
"app/controllers/bookmarklet_integration_controller.rb:6",
|
82
|
+
"app/controllers/bookmarklet_integration_controller.rb:17"]]
|
83
|
+
|
84
|
+
MetricFu::Configuration.run {}
|
85
|
+
File.stub!(:directory?).and_return(true)
|
86
|
+
flay = MetricFu::Flay.new('base_dir')
|
87
|
+
flay.instance_variable_set(:@matches, lines)
|
88
|
+
@results = flay.to_h
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should find the total_score" do
|
92
|
+
@results[:flay][:total_score].should == '284'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should have 6 matches" do
|
96
|
+
@results[:flay][:matches].size.should == 6
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should capture info for match" do
|
100
|
+
@results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
|
101
|
+
@results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
|
102
|
+
@results[:flay][:matches].first[:matches].first[:line].should == "57"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
describe Flog do
|
3
|
+
before :each do
|
4
|
+
MetricFu::Configuration.run {}
|
5
|
+
File.stub!(:directory?).and_return(true)
|
6
|
+
@flog = MetricFu::Flog.new('base_dir')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "emit method" do
|
10
|
+
it "should look for files and flog them" do
|
11
|
+
Dir.should_receive(:glob).with("lib/**/*.rb").and_return(["found/file.rb"])
|
12
|
+
::Flog.should_receive(:parse_options).with(["--all", "--details"]).and_return("options")
|
13
|
+
::Flog.should_receive(:new).with("options").and_return(flogger = mock('flogger'))
|
14
|
+
flogger.should_receive(:flog).with(["found/file.rb"])
|
15
|
+
@flog.emit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "analyze method" do
|
20
|
+
it "should harvest the flog information and put it into method_containers" do
|
21
|
+
first_full_method_name = "ClassName#first_method_name"
|
22
|
+
second_full_method_name = "ClassName#second_method_name"
|
23
|
+
|
24
|
+
flogger = mock('flogger', :calls => {first_full_method_name => {:branch => 11.1, :puts => 1.1},
|
25
|
+
second_full_method_name => {:branch => 22.2, :puts => 2.2}},
|
26
|
+
:method_locations => {first_full_method_name => '/file/location.rb:11',
|
27
|
+
second_full_method_name => '/file/location.rb:22'},
|
28
|
+
:totals => {first_full_method_name => 11.11,
|
29
|
+
second_full_method_name => 22.22})
|
30
|
+
@flog.instance_variable_set(:@flogger, flogger)
|
31
|
+
@flog.analyze
|
32
|
+
method_containers = @flog.instance_variable_get(:@method_containers)
|
33
|
+
method_containers.size.should == 1
|
34
|
+
|
35
|
+
expected={:methods=>{"ClassName#first_method_name" => { :path=>"/file/location.rb:11",
|
36
|
+
:score=>11.11,
|
37
|
+
:operators=>{ :branch=>11.1,
|
38
|
+
:puts=>1.1}},
|
39
|
+
"ClassName#second_method_name" => {:path=>"/file/location.rb:22",
|
40
|
+
:score=>22.22,
|
41
|
+
:operators=>{ :branch=>22.2,
|
42
|
+
:puts=>2.2}}},
|
43
|
+
:path=>"/file/location.rb",
|
44
|
+
:average_score=>((11.11 + 22.22) / 2.0),
|
45
|
+
:total_score=>33.33,
|
46
|
+
:highest_score=>22.22,
|
47
|
+
:name=>"ClassName"}
|
48
|
+
|
49
|
+
method_containers["ClassName"].to_h.should == expected
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "to_h method" do
|
54
|
+
it "should make-a nice hash" do
|
55
|
+
flogger = mock('flogger', :total => 111.1, :average => 7.3)
|
56
|
+
@flog.instance_variable_set(:@flogger, flogger)
|
57
|
+
method_containers = {:ignore_me_1 => mock('container_1', :highest_score => 11.1, :to_h => 'container_1'),
|
58
|
+
:ignore_me_2 => mock('container_2', :highest_score => 33.3, :to_h => 'container_2'),
|
59
|
+
:ignore_me_3 => mock('container_3', :highest_score => 22.2, :to_h => 'container_3')}
|
60
|
+
@flog.instance_variable_set(:@method_containers, method_containers)
|
61
|
+
|
62
|
+
expected = {:flog => { :total => 111.1,
|
63
|
+
:average => 7.3,
|
64
|
+
:method_containers => ['container_2', 'container_3', 'container_1']}}
|
65
|
+
|
66
|
+
@flog.to_h.should == expected
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|