cdd-metric_fu 1.3.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/.document +7 -0
- data/.gitignore +24 -0
- data/HISTORY +182 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +25 -0
- data/README.rdoc +20 -0
- data/Rakefile +59 -0
- data/TODO +9 -0
- data/VERSION +1 -0
- data/cdd-metric_fu.gemspec +200 -0
- data/home_page/back_all.jpg +0 -0
- data/home_page/churn.gif +0 -0
- data/home_page/flay.gif +0 -0
- data/home_page/flog.gif +0 -0
- data/home_page/footer.gif +0 -0
- data/home_page/header.jpg +0 -0
- data/home_page/img09.gif +0 -0
- data/home_page/index.html +277 -0
- data/home_page/rcov.gif +0 -0
- data/home_page/reek.gif +0 -0
- data/home_page/roodi.gif +0 -0
- data/home_page/saikuro.gif +0 -0
- data/home_page/stats.gif +0 -0
- data/home_page/styles.css +245 -0
- data/home_page/title.gif +0 -0
- data/home_page/title_back.gif +0 -0
- data/lib/base/base_template.rb +145 -0
- data/lib/base/configuration.rb +188 -0
- data/lib/base/generator.rb +167 -0
- data/lib/base/graph.rb +47 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +34 -0
- data/lib/generators/flay.rb +35 -0
- data/lib/generators/flog.rb +172 -0
- data/lib/generators/rcov.rb +82 -0
- data/lib/generators/reek.rb +64 -0
- data/lib/generators/roodi.rb +33 -0
- data/lib/generators/saikuro.rb +221 -0
- data/lib/generators/stats.rb +59 -0
- data/lib/graphs/engines/bluff.rb +101 -0
- data/lib/graphs/engines/gchart.rb +120 -0
- data/lib/graphs/flay_grapher.rb +19 -0
- data/lib/graphs/flog_grapher.rb +39 -0
- data/lib/graphs/grapher.rb +18 -0
- data/lib/graphs/rails_best_practices_grapher.rb +24 -0
- data/lib/graphs/rcov_grapher.rb +19 -0
- data/lib/graphs/reek_grapher.rb +31 -0
- data/lib/graphs/roodi_grapher.rb +19 -0
- data/lib/graphs/stats_grapher.rb +22 -0
- data/lib/metric_fu.rb +32 -0
- data/lib/metric_fu/railtie.rb +10 -0
- data/lib/tasks/metric_fu.rake +22 -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 +53 -0
- data/lib/templates/awesome/index.html.erb +31 -0
- data/lib/templates/awesome/layout.html.erb +30 -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 +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 +274 -0
- data/spec/base/generator_spec.rb +244 -0
- data/spec/base/graph_spec.rb +32 -0
- data/spec/base/md5_tracker_spec.rb +57 -0
- data/spec/base/report_spec.rb +139 -0
- data/spec/generators/churn_spec.rb +43 -0
- data/spec/generators/flay_spec.rb +110 -0
- data/spec/generators/flog_spec.rb +262 -0
- data/spec/generators/rcov_spec.rb +159 -0
- data/spec/generators/reek_spec.rb +125 -0
- data/spec/generators/saikuro_spec.rb +58 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/graphs/engines/bluff_spec.rb +17 -0
- data/spec/graphs/engines/gchart_spec.rb +109 -0
- data/spec/graphs/flay_grapher_spec.rb +37 -0
- data/spec/graphs/flog_grapher_spec.rb +45 -0
- data/spec/graphs/grapher_spec.rb +29 -0
- data/spec/graphs/rcov_grapher_spec.rb +37 -0
- data/spec/graphs/reek_grapher_spec.rb +47 -0
- data/spec/graphs/roodi_grapher_spec.rb +37 -0
- data/spec/graphs/stats_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 +7913 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +7 -0
- metadata +285 -0
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
MetricFu.stub!(:configuration).and_return(config)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should return a textmate protocol link' do
|
|
95
|
+
File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
|
|
96
|
+
result = @template.send(:link_to_filename, 'filename')
|
|
97
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
|
98
|
+
+ "/expanded/filename'>filename</a>")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should do the right thing with a filename that starts with a slash" do
|
|
102
|
+
File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
|
|
103
|
+
result = @template.send(:link_to_filename, '/filename')
|
|
104
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
|
105
|
+
+ "/expanded/filename'>/filename</a>")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should include a line number" do
|
|
109
|
+
File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
|
|
110
|
+
result = @template.send(:link_to_filename, 'filename', 6)
|
|
111
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
|
112
|
+
+ "/expanded/filename&line=6'>filename:6</a>")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe "and given link text" do
|
|
116
|
+
it "should use the submitted link text" do
|
|
117
|
+
File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
|
|
118
|
+
result = @template.send(:link_to_filename, 'filename', 6, 'link content')
|
|
119
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
|
120
|
+
+ "/expanded/filename&line=6'>link content</a>")
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "when on other platforms" do
|
|
126
|
+
before(:each) do
|
|
127
|
+
config = mock("configuration")
|
|
128
|
+
config.should_receive(:platform).and_return('other')
|
|
129
|
+
MetricFu.stub!(:configuration).and_return(config)
|
|
130
|
+
File.should_receive(:expand_path).and_return('filename')
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'should return a file protocol link' do
|
|
134
|
+
name = "filename"
|
|
135
|
+
result = @template.send(:link_to_filename, name)
|
|
136
|
+
result.should == "<a href='file://filename'>filename</a>"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe "#cycle" do
|
|
142
|
+
it 'should return the first_value passed if iteration passed is even' do
|
|
143
|
+
first_val = "first"
|
|
144
|
+
second_val = "second"
|
|
145
|
+
iter = 2
|
|
146
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
|
147
|
+
result.should == first_val
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'should return the second_value passed if iteration passed is odd' do
|
|
151
|
+
first_val = "first"
|
|
152
|
+
second_val = "second"
|
|
153
|
+
iter = 1
|
|
154
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
|
155
|
+
result.should == second_val
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
|
|
@@ -0,0 +1,274 @@
|
|
|
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 #graph_period to 30" do
|
|
89
|
+
@config.instance_variable_get(:@graph_period).should == 30
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
|
|
93
|
+
@config.instance_variable_get(:@flay).
|
|
94
|
+
should == {:dirs_to_flay => ['lib'], :minimum_score => 100}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
|
|
98
|
+
@config.instance_variable_get(:@flog).
|
|
99
|
+
should == {:dirs_to_flog => ['lib']}
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
|
|
103
|
+
@config.instance_variable_get(:@reek).
|
|
104
|
+
should == {:dirs_to_reek => ['lib']}
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
|
|
108
|
+
@config.instance_variable_get(:@roodi).
|
|
109
|
+
should == {:dirs_to_roodi => ['lib']}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should set @churn to {}' do
|
|
113
|
+
@config.instance_variable_get(:@churn).
|
|
114
|
+
should == {}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'should set @stats to {}' do
|
|
118
|
+
@config.instance_variable_get(:@stats).
|
|
119
|
+
should == {}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'should set @rcov to { :test_files => ["test/**/*_test.rb",
|
|
123
|
+
"spec/**/*_spec.rb"]
|
|
124
|
+
:rcov_opts => ["--sort coverage",
|
|
125
|
+
"--no-html",
|
|
126
|
+
"--text-coverage",
|
|
127
|
+
"--no-color",
|
|
128
|
+
"--profile",
|
|
129
|
+
"--rails",
|
|
130
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}' do
|
|
131
|
+
@config.instance_variable_get(:@rcov).
|
|
132
|
+
should == { :environment => 'test',
|
|
133
|
+
:test_files => ['test/**/*_test.rb',
|
|
134
|
+
'spec/**/*_spec.rb'],
|
|
135
|
+
:rcov_opts => ["--sort coverage",
|
|
136
|
+
"--no-html",
|
|
137
|
+
"--text-coverage",
|
|
138
|
+
"--no-color",
|
|
139
|
+
"--profile",
|
|
140
|
+
"--rails",
|
|
141
|
+
"--exclude /gems/,/Library/,/usr/,spec"]}
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
|
|
145
|
+
:input_directory => @code_dirs,
|
|
146
|
+
:cyclo => "",
|
|
147
|
+
:filter_cyclo => "0",
|
|
148
|
+
:warn_cyclo => "5",
|
|
149
|
+
:error_cyclo => "7",
|
|
150
|
+
:formater => "text" }' do
|
|
151
|
+
@config.instance_variable_get(:@saikuro).
|
|
152
|
+
should == { :output_directory => "#{scratch_directory}/saikuro",
|
|
153
|
+
:input_directory => ['lib'],
|
|
154
|
+
:cyclo => "",
|
|
155
|
+
:filter_cyclo => "0",
|
|
156
|
+
:warn_cyclo => "5",
|
|
157
|
+
:error_cyclo => "7",
|
|
158
|
+
:formater => "text"}
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe 'if #rails? is true ' do
|
|
162
|
+
before(:each) do
|
|
163
|
+
@config.stub!(:rails?).and_return(true)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
describe '#set_metrics ' do
|
|
167
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS + '\
|
|
168
|
+
+'[:stats]' do
|
|
169
|
+
@config.instance_variable_get(:@metrics).
|
|
170
|
+
should == MetricFu::AVAILABLE_METRICS << [:stats]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe '#set_graphs ' do
|
|
175
|
+
it 'should set the @graphs instance var to AVAILABLE_GRAPHS' do
|
|
176
|
+
@config.instance_variable_get(:@graphs).
|
|
177
|
+
should == MetricFu::AVAILABLE_GRAPHS
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe '#set_code_dirs ' do
|
|
182
|
+
it 'should set the @code_dirs instance var to ["app", "lib"]' do
|
|
183
|
+
# This is hard to spec properly because the @code_dirs variable
|
|
184
|
+
# is set during the reset process.
|
|
185
|
+
#@config.instance_variable_get(:@code_dirs).
|
|
186
|
+
# should == ['app','lib']
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe 'if #rails? is false ' do
|
|
192
|
+
before(:each) do
|
|
193
|
+
@config.stub!(:rails?).and_return(false)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe '#set_metrics ' do
|
|
197
|
+
it 'should set the @metrics instance var to AVAILABLE_METRICS' do
|
|
198
|
+
@config.instance_variable_get(:@metrics).
|
|
199
|
+
should == MetricFu::AVAILABLE_METRICS
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe '#set_code_dirs ' do
|
|
204
|
+
it 'should set the @code_dirs instance var to ["lib"]' do
|
|
205
|
+
@config.instance_variable_get(:@code_dirs).should == ['lib']
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
describe '#add_attr_accessors_to_self' do
|
|
212
|
+
|
|
213
|
+
before(:each) { get_new_config }
|
|
214
|
+
|
|
215
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
|
216
|
+
it "should have a reader for #{metric}" do
|
|
217
|
+
@config.respond_to?(metric).should be_true
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should have a writer for #{metric}=" do
|
|
221
|
+
@config.respond_to?((metric.to_s + '=').to_sym).should be_true
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
describe '#add_class_methods_to_metric_fu' do
|
|
227
|
+
|
|
228
|
+
before(:each) { get_new_config }
|
|
229
|
+
|
|
230
|
+
MetricFu::AVAILABLE_METRICS.each do |metric|
|
|
231
|
+
it "should add a #{metric} class method to the MetricFu module " do
|
|
232
|
+
MetricFu.should respond_to(metric)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
MetricFu::AVAILABLE_GRAPHS.each do |graph|
|
|
237
|
+
it "should add a #{graph} class metrhod to the MetricFu module" do
|
|
238
|
+
MetricFu.should respond_to(graph)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
describe '#platform' do
|
|
244
|
+
|
|
245
|
+
before(:each) { get_new_config }
|
|
246
|
+
|
|
247
|
+
it 'should return the value of the PLATFORM constant' do
|
|
248
|
+
this_platform = RUBY_PLATFORM
|
|
249
|
+
@config.platform.should == this_platform
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
describe '#is_cruise_control_rb? ' do
|
|
254
|
+
|
|
255
|
+
before(:each) { get_new_config }
|
|
256
|
+
describe "when the CC_BUILD_ARTIFACTS env var is not nil" do
|
|
257
|
+
|
|
258
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'is set' }
|
|
259
|
+
|
|
260
|
+
it 'should return true' do
|
|
261
|
+
@config.is_cruise_control_rb?.should be_true
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
describe "when the CC_BUILD_ARTIFACTS env var is nil" do
|
|
267
|
+
before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
|
|
268
|
+
|
|
269
|
+
it 'should return false' do
|
|
270
|
+
@config.is_cruise_control_rb?.should be_false
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
it "should raise error if the concrete class is missing a required dependency" do
|
|
161
|
+
concrete_class_with_missing_gem = Class.new(MetricFu::Generator) do
|
|
162
|
+
def self.verify_dependencies!
|
|
163
|
+
raise 'gem install something # if you want these tasks'
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
lambda { concrete_class_with_missing_gem.generate_report }.should raise_error("gem install something # if you want these tasks")
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe "instantiation" do
|
|
172
|
+
it "should fail is dependencies not verified" do
|
|
173
|
+
ConcreteClass.should_receive(:verify_dependencies!).and_raise("Missing a required gem. Please 'gem install something'")
|
|
174
|
+
lambda { ConcreteClass.new() }.should raise_error("Missing a required gem. Please 'gem install something'")
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should succeed when dependencies verified" do
|
|
178
|
+
ConcreteClass.should_receive(:verify_dependencies!).and_return(true)
|
|
179
|
+
ConcreteClass.new()
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
describe "path filter" do
|
|
184
|
+
|
|
185
|
+
context "given a list of paths" do
|
|
186
|
+
|
|
187
|
+
before do
|
|
188
|
+
@paths = %w(lib/fake/fake.rb
|
|
189
|
+
lib/this/dan_file.rb
|
|
190
|
+
lib/this/ben_file.rb
|
|
191
|
+
lib/this/avdi_file.rb
|
|
192
|
+
basic.rb
|
|
193
|
+
lib/bad/one.rb
|
|
194
|
+
lib/bad/two.rb
|
|
195
|
+
lib/bad/three.rb
|
|
196
|
+
lib/worse/four.rb)
|
|
197
|
+
@container = create_construct
|
|
198
|
+
@paths.each do |path|
|
|
199
|
+
@container.file(path)
|
|
200
|
+
end
|
|
201
|
+
@old_dir = Dir.pwd
|
|
202
|
+
Dir.chdir(@container)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
after do
|
|
206
|
+
Dir.chdir(@old_dir)
|
|
207
|
+
@container.destroy!
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it "should return entire pathlist given no exclude pattens" do
|
|
211
|
+
files = @concrete_class.remove_excluded_files(@paths)
|
|
212
|
+
files.should be == @paths
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "should filter filename at root level" do
|
|
216
|
+
files = @concrete_class.remove_excluded_files(@paths, ['basic.rb'])
|
|
217
|
+
files.should_not include('basic.rb')
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should remove files that are two levels deep" do
|
|
221
|
+
files = @concrete_class.remove_excluded_files(@paths, ['**/fake.rb'])
|
|
222
|
+
files.should_not include('lib/fake/fake.rb')
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "should remove files from an excluded directory" do
|
|
226
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/bad/**'])
|
|
227
|
+
files.should_not include('lib/bad/one.rb')
|
|
228
|
+
files.should_not include('lib/bad/two.rb')
|
|
229
|
+
files.should_not include('lib/bad/three.rb')
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "should support shell alternation globs" do
|
|
233
|
+
files = @concrete_class.remove_excluded_files(@paths, ['lib/this/{ben,dan}_file.rb'])
|
|
234
|
+
files.should_not include('lib/this/dan_file.rb')
|
|
235
|
+
files.should_not include('lib/this/ben_file.rb')
|
|
236
|
+
files.should include('lib/this/avdi_file.rb')
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
end
|