cdd-metric_fu 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/.document +7 -0
  2. data/.gitignore +24 -0
  3. data/HISTORY +182 -0
  4. data/MIT-LICENSE +22 -0
  5. data/Manifest.txt +25 -0
  6. data/README.rdoc +20 -0
  7. data/Rakefile +59 -0
  8. data/TODO +9 -0
  9. data/VERSION +1 -0
  10. data/cdd-metric_fu.gemspec +200 -0
  11. data/home_page/back_all.jpg +0 -0
  12. data/home_page/churn.gif +0 -0
  13. data/home_page/flay.gif +0 -0
  14. data/home_page/flog.gif +0 -0
  15. data/home_page/footer.gif +0 -0
  16. data/home_page/header.jpg +0 -0
  17. data/home_page/img09.gif +0 -0
  18. data/home_page/index.html +277 -0
  19. data/home_page/rcov.gif +0 -0
  20. data/home_page/reek.gif +0 -0
  21. data/home_page/roodi.gif +0 -0
  22. data/home_page/saikuro.gif +0 -0
  23. data/home_page/stats.gif +0 -0
  24. data/home_page/styles.css +245 -0
  25. data/home_page/title.gif +0 -0
  26. data/home_page/title_back.gif +0 -0
  27. data/lib/base/base_template.rb +145 -0
  28. data/lib/base/configuration.rb +188 -0
  29. data/lib/base/generator.rb +167 -0
  30. data/lib/base/graph.rb +47 -0
  31. data/lib/base/md5_tracker.rb +52 -0
  32. data/lib/base/report.rb +100 -0
  33. data/lib/generators/churn.rb +34 -0
  34. data/lib/generators/flay.rb +35 -0
  35. data/lib/generators/flog.rb +172 -0
  36. data/lib/generators/rcov.rb +82 -0
  37. data/lib/generators/reek.rb +64 -0
  38. data/lib/generators/roodi.rb +33 -0
  39. data/lib/generators/saikuro.rb +221 -0
  40. data/lib/generators/stats.rb +59 -0
  41. data/lib/graphs/engines/bluff.rb +101 -0
  42. data/lib/graphs/engines/gchart.rb +120 -0
  43. data/lib/graphs/flay_grapher.rb +19 -0
  44. data/lib/graphs/flog_grapher.rb +39 -0
  45. data/lib/graphs/grapher.rb +18 -0
  46. data/lib/graphs/rails_best_practices_grapher.rb +24 -0
  47. data/lib/graphs/rcov_grapher.rb +19 -0
  48. data/lib/graphs/reek_grapher.rb +31 -0
  49. data/lib/graphs/roodi_grapher.rb +19 -0
  50. data/lib/graphs/stats_grapher.rb +22 -0
  51. data/lib/metric_fu.rb +32 -0
  52. data/lib/metric_fu/railtie.rb +10 -0
  53. data/lib/tasks/metric_fu.rake +22 -0
  54. data/lib/templates/awesome/awesome_template.rb +37 -0
  55. data/lib/templates/awesome/churn.html.erb +58 -0
  56. data/lib/templates/awesome/css/buttons.css +82 -0
  57. data/lib/templates/awesome/css/default.css +91 -0
  58. data/lib/templates/awesome/css/integrity.css +335 -0
  59. data/lib/templates/awesome/css/reset.css +7 -0
  60. data/lib/templates/awesome/flay.html.erb +34 -0
  61. data/lib/templates/awesome/flog.html.erb +53 -0
  62. data/lib/templates/awesome/index.html.erb +31 -0
  63. data/lib/templates/awesome/layout.html.erb +30 -0
  64. data/lib/templates/awesome/rcov.html.erb +42 -0
  65. data/lib/templates/awesome/reek.html.erb +40 -0
  66. data/lib/templates/awesome/roodi.html.erb +27 -0
  67. data/lib/templates/awesome/saikuro.html.erb +71 -0
  68. data/lib/templates/awesome/stats.html.erb +51 -0
  69. data/lib/templates/javascripts/bluff-min.js +1 -0
  70. data/lib/templates/javascripts/excanvas.js +35 -0
  71. data/lib/templates/javascripts/js-class.js +1 -0
  72. data/lib/templates/standard/churn.html.erb +31 -0
  73. data/lib/templates/standard/default.css +64 -0
  74. data/lib/templates/standard/flay.html.erb +34 -0
  75. data/lib/templates/standard/flog.html.erb +53 -0
  76. data/lib/templates/standard/index.html.erb +38 -0
  77. data/lib/templates/standard/rcov.html.erb +43 -0
  78. data/lib/templates/standard/reek.html.erb +42 -0
  79. data/lib/templates/standard/roodi.html.erb +29 -0
  80. data/lib/templates/standard/saikuro.html.erb +84 -0
  81. data/lib/templates/standard/standard_template.rb +26 -0
  82. data/lib/templates/standard/stats.html.erb +55 -0
  83. data/spec/base/base_template_spec.rb +161 -0
  84. data/spec/base/configuration_spec.rb +274 -0
  85. data/spec/base/generator_spec.rb +244 -0
  86. data/spec/base/graph_spec.rb +32 -0
  87. data/spec/base/md5_tracker_spec.rb +57 -0
  88. data/spec/base/report_spec.rb +139 -0
  89. data/spec/generators/churn_spec.rb +43 -0
  90. data/spec/generators/flay_spec.rb +110 -0
  91. data/spec/generators/flog_spec.rb +262 -0
  92. data/spec/generators/rcov_spec.rb +159 -0
  93. data/spec/generators/reek_spec.rb +125 -0
  94. data/spec/generators/saikuro_spec.rb +58 -0
  95. data/spec/generators/stats_spec.rb +74 -0
  96. data/spec/graphs/engines/bluff_spec.rb +17 -0
  97. data/spec/graphs/engines/gchart_spec.rb +109 -0
  98. data/spec/graphs/flay_grapher_spec.rb +37 -0
  99. data/spec/graphs/flog_grapher_spec.rb +45 -0
  100. data/spec/graphs/grapher_spec.rb +29 -0
  101. data/spec/graphs/rcov_grapher_spec.rb +37 -0
  102. data/spec/graphs/reek_grapher_spec.rb +47 -0
  103. data/spec/graphs/roodi_grapher_spec.rb +37 -0
  104. data/spec/graphs/stats_grapher_spec.rb +44 -0
  105. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  106. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  107. data/spec/resources/saikuro/index_cyclo.html +155 -0
  108. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  109. data/spec/resources/yml/20090630.yml +7913 -0
  110. data/spec/spec.opts +6 -0
  111. data/spec/spec_helper.rb +7 -0
  112. metadata +285 -0
@@ -0,0 +1,159 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe MetricFu::Rcov do
4
+
5
+ before :each do
6
+ MetricFu::Configuration.run {}
7
+ File.stub!(:directory?).and_return(true)
8
+ @rcov = MetricFu::Rcov.new('base_dir')
9
+ end
10
+
11
+ describe "emit" do
12
+ before :each do
13
+ @rcov.stub!(:puts)
14
+ end
15
+
16
+ it "should clear out previous output and make output folder" do
17
+ @rcov.stub!(:`)
18
+ FileUtils.should_receive(:rm_rf).with(MetricFu::Rcov.metric_directory, :verbose => false)
19
+ Dir.should_receive(:mkdir).with(MetricFu::Rcov.metric_directory)
20
+ @rcov.emit
21
+ end
22
+
23
+ it "should set the RAILS_ENV" do
24
+ FileUtils.stub!(:rm_rf)
25
+ Dir.stub!(:mkdir)
26
+ MetricFu.rcov[:environment] = "metrics"
27
+ @rcov.should_receive(:`).with(/RAILS_ENV=metrics/)
28
+ @rcov.emit
29
+ end
30
+ end
31
+
32
+ describe "with RCOV_OUTPUT fed into" do
33
+ before :each do
34
+ File.should_receive(:open).
35
+ with(MetricFu::Rcov.metric_directory + '/rcov.txt').
36
+ and_return(mock("io", :read => RCOV_OUTPUT))
37
+ @files = @rcov.analyze
38
+ end
39
+
40
+ describe "analyze" do
41
+ it "should compute percent of lines run" do
42
+ @files["lib/templates/awesome/awesome_template.rb"][:percent_run].should == 13
43
+ @files["lib/templates/standard/standard_template.rb"][:percent_run].should == 14
44
+ end
45
+
46
+ it "should know which lines were run" do
47
+ @files["lib/templates/awesome/awesome_template.rb"][:lines].
48
+ should include({:content=>" require 'fileutils'", :was_run=>true})
49
+ end
50
+
51
+ it "should know which lines NOT were run" do
52
+ @files["lib/templates/awesome/awesome_template.rb"][:lines].
53
+ should include({:content=>" if template_exists?(section)", :was_run=>false})
54
+ end
55
+ end
56
+
57
+ describe "to_h" do
58
+ it "should calculate total percentage for all files" do
59
+ @rcov.to_h[:rcov][:global_percent_run].should == 13.7
60
+ end
61
+ end
62
+ end
63
+
64
+
65
+ RCOV_OUTPUT = <<-HERE
66
+ Profiling enabled.
67
+ .............................................................................................................................................................................................
68
+
69
+
70
+ Top 10 slowest examples:
71
+ 0.2707830 MetricFu::RoodiGrapher responding to #get_metrics should push 13 to roodi_count
72
+ 0.1994550 MetricFu::RcovGrapher responding to #get_metrics should update labels with the date
73
+ 0.1985800 MetricFu::ReekGrapher responding to #get_metrics should set a hash of code smells to reek_count
74
+ 0.1919860 MetricFu::ReekGrapher responding to #get_metrics should update labels with the date
75
+ 0.1907400 MetricFu::RoodiGrapher responding to #get_metrics should update labels with the date
76
+ 0.1883000 MetricFu::FlogGrapher responding to #get_metrics should update labels with the date
77
+ 0.1882650 MetricFu::FlayGrapher responding to #get_metrics should push 476 to flay_score
78
+ 0.1868780 MetricFu::FlogGrapher responding to #get_metrics should push to top_five_percent_average
79
+ 0.1847730 MetricFu::FlogGrapher responding to #get_metrics should push 9.9 to flog_average
80
+ 0.1844090 MetricFu::FlayGrapher responding to #get_metrics should update labels with the date
81
+
82
+ Finished in 2.517686 seconds
83
+
84
+ 189 examples, 0 failures
85
+ ================================================================================
86
+ lib/templates/awesome/awesome_template.rb
87
+ ================================================================================
88
+ require 'fileutils'
89
+
90
+ class AwesomeTemplate < MetricFu::Template
91
+
92
+ def write
93
+ !! # Getting rid of the crap before and after the project name from integrity
94
+ !! @name = File.basename(Dir.pwd).gsub(/^\w+-|-\w+$/, "")
95
+ !!
96
+ !! # Copy Bluff javascripts to output directory
97
+ !! Dir[File.join(this_directory, '..', 'javascripts', '*')].each do |f|
98
+ !! FileUtils.copy(f, File.join(MetricFu.output_directory, File.basename(f)))
99
+ !! end
100
+ !!
101
+ !! report.each_pair do |section, contents|
102
+ !! if template_exists?(section)
103
+ !! create_instance_var(section, contents)
104
+ !! @html = erbify(section)
105
+ !! html = erbify('layout')
106
+ !! fn = output_filename(section)
107
+ !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
108
+ !! end
109
+ !! end
110
+ !!
111
+ !! # Instance variables we need should already be created from above
112
+ !! if template_exists?('index')
113
+ !! @html = erbify('index')
114
+ !! html = erbify('layout')
115
+ !! fn = output_filename('index')
116
+ !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
117
+ !! end
118
+ !! end
119
+
120
+ def this_directory
121
+ !! File.dirname(__FILE__)
122
+ !! end
123
+ !! end
124
+
125
+ ================================================================================
126
+ lib/templates/standard/standard_template.rb
127
+ ================================================================================
128
+ class StandardTemplate < MetricFu::Template
129
+
130
+
131
+ def write
132
+ !! report.each_pair do |section, contents|
133
+ !! if template_exists?(section)
134
+ !! create_instance_var(section, contents)
135
+ !! html = erbify(section)
136
+ !! fn = output_filename(section)
137
+ !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
138
+ !! end
139
+ !! end
140
+ !!
141
+ !! # Instance variables we need should already be created from above
142
+ !! if template_exists?('index')
143
+ !! html = erbify('index')
144
+ !! fn = output_filename('index')
145
+ !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
146
+ !! end
147
+ !! end
148
+
149
+ def this_directory
150
+ !! File.dirname(__FILE__)
151
+ !! end
152
+ !! end
153
+
154
+ HERE
155
+
156
+ end
157
+
158
+
159
+
@@ -0,0 +1,125 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Reek do
4
+ describe "analyze method" do
5
+ before :each do
6
+ MetricFu::Reek.stub!(:verify_dependencies!).and_return(true)
7
+ @lines = <<-HERE
8
+ "app/controllers/activity_reports_controller.rb" -- 4 warnings:
9
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
10
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
11
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
12
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
13
+
14
+ "app/controllers/application.rb" -- 1 warnings:
15
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
16
+
17
+ "app/controllers/link_targets_controller.rb" -- 1 warnings:
18
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
19
+
20
+ "app/controllers/newline_controller.rb" -- 1 warnings:
21
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
22
+ HERE
23
+ MetricFu::Configuration.run {}
24
+ File.stub!(:directory?).and_return(true)
25
+ reek = MetricFu::Reek.new
26
+ reek.instance_variable_set(:@output, @lines)
27
+ @matches = reek.analyze
28
+ end
29
+
30
+ it "should find the code smell's method name" do
31
+ smell = @matches.first[:code_smells].first
32
+ smell[:method].should == "ActivityReportsController#authorize_user"
33
+ end
34
+
35
+ it "should find the code smell's type" do
36
+ smell = @matches[1][:code_smells].first
37
+ smell[:type].should == "Nested Iterators"
38
+ end
39
+
40
+ it "should find the code smell's message" do
41
+ smell = @matches[1][:code_smells].first
42
+ smell[:message].should == "is nested"
43
+ end
44
+
45
+ it "should find the code smell's type" do
46
+ smell = @matches.first
47
+ smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
48
+ end
49
+
50
+ it "should NOT insert nil smells into the array when there's a newline in the method call" do
51
+ @matches.last[:code_smells].should == @matches.last[:code_smells].compact
52
+ @matches.last.should == {:file_path=>"app/controllers/newline_controller.rb",
53
+ :code_smells=>[{:type=>"Duplication",
54
+ :method=>"\"",
55
+ :message=>"multiple times"}]}
56
+ # Note: hopefully a temporary solution until I figure out how to deal with newlines in the method call more effectively -Jake 5/11/2009
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ describe Reek do
63
+ before :each do
64
+ MetricFu::Reek.stub!(:verify_dependencies!).and_return(true)
65
+ MetricFu::Configuration.run {}
66
+ @reek = MetricFu::Reek.new
67
+ @lines11 = <<-HERE
68
+ "app/controllers/activity_reports_controller.rb" -- 4 warnings:
69
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
70
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
71
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
72
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
73
+
74
+ "app/controllers/application.rb" -- 1 warnings:
75
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
76
+
77
+ "app/controllers/link_targets_controller.rb" -- 1 warnings:
78
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
79
+
80
+ "app/controllers/newline_controller.rb" -- 1 warnings:
81
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
82
+ HERE
83
+ @lines12 = <<-HERE
84
+ app/controllers/activity_reports_controller.rb -- 4 warnings (+3 masked):
85
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
86
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
87
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
88
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
89
+ app/controllers/application.rb -- 1 warnings:
90
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
91
+ app/controllers/link_targets_controller.rb -- 1 warnings (+1 masked):
92
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
93
+ app/controllers/newline_controller.rb -- 1 warnings:
94
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
95
+ HERE
96
+ end
97
+
98
+ context 'with Reek 1.1 output format' do
99
+ it 'reports 1.1 style when the output is empty' do
100
+ @reek.instance_variable_set(:@output, "")
101
+ @reek.should_not be_reek_12
102
+ end
103
+ it 'detects 1.1 format output' do
104
+ @reek.instance_variable_set(:@output, @lines11)
105
+ @reek.should_not be_reek_12
106
+ end
107
+
108
+ it 'massages empty output to be unchanged' do
109
+ @reek.instance_variable_set(:@output, "")
110
+ @reek.massage_for_reek_12.should be_empty
111
+ end
112
+ end
113
+
114
+ context 'with Reek 1.2 output format' do
115
+ it 'detects 1.2 format output' do
116
+ @reek.instance_variable_set(:@output, @lines12)
117
+ @reek.should be_reek_12
118
+ end
119
+
120
+ it 'correctly massages 1.2 output' do
121
+ @reek.instance_variable_set(:@output, @lines12)
122
+ @reek.massage_for_reek_12.should == @lines11
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Saikuro do
4
+ describe "to_h method" do
5
+ before :all do
6
+ MetricFu::Configuration.run {}
7
+ File.stub!(:directory?).and_return(true)
8
+ saikuro = MetricFu::Saikuro.new
9
+ saikuro.stub!(:metric_directory).and_return(File.join(File.dirname(__FILE__), "..", "resources", "saikuro"))
10
+ saikuro.analyze
11
+ @output = saikuro.to_h
12
+ end
13
+
14
+ it "should find the filename of a file" do
15
+ @output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
16
+ end
17
+
18
+ it "should find the name of the classes" do
19
+ @output[:saikuro][:classes].first[:name].should == "UsersController"
20
+ @output[:saikuro][:classes][1][:name].should == "SessionsController"
21
+ end
22
+
23
+ it "should put the most complex method first" do
24
+ @output[:saikuro][:methods].first[:name].should == "UsersController#create"
25
+ @output[:saikuro][:methods].first[:complexity].should == 4
26
+ end
27
+
28
+ it "should find the complexity of a method" do
29
+ @output[:saikuro][:methods].first[:complexity].should == 4
30
+ end
31
+
32
+ it "should find the lines of a method" do
33
+ @output[:saikuro][:methods].first[:lines].should == 15
34
+ end
35
+ end
36
+
37
+ describe "format_directories method" do
38
+ it "should format the directories" do
39
+ MetricFu::Configuration.run {}
40
+ File.stub!(:directory?).and_return(true)
41
+ saikuro = MetricFu::Saikuro.new
42
+
43
+ MetricFu.saikuro[:input_directory] = ["app", "lib"]
44
+
45
+ saikuro.format_directories.should == "\"app | lib\""
46
+ end
47
+ end
48
+
49
+ describe Saikuro::SFile do
50
+ describe "getting elements from a Saikuro result file" do
51
+ it "should parse nested START/END sections" do
52
+ path = File.join(File.dirname(__FILE__), "..", "resources", "saikuro_sfiles", "thing.rb_cyclo.html")
53
+ sfile = Saikuro::SFile.new path
54
+ sfile.elements.map { |e| e.complexity }.sort.should eql(["0","0","2"])
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Stats do
4
+ describe "emit method" do
5
+ it "should gather the raw data" do
6
+ MetricFu::Configuration.run {}
7
+ File.stub!(:directory?).and_return(true)
8
+ stats = MetricFu::Stats.new
9
+ stats.should_receive(:`).with("rake stats > tmp/metric_fu/scratch/stats/stats.txt")
10
+ stats.emit
11
+ end
12
+ end
13
+
14
+ describe "analyze method" do
15
+ before :each do
16
+ @lines = <<-HERE.gsub(/^\s*/, "")
17
+ +----------------------+-------+-------+---------+---------+-----+-------+
18
+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
19
+ +----------------------+-------+-------+---------+---------+-----+-------+
20
+ | Controllers | 470 | 382 | 7 | 53 | 7 | 5 |
21
+ | Helpers | 128 | 65 | 0 | 6 | 0 | 8 |
22
+ | Models | 351 | 285 | 9 | 31 | 3 | 7 |
23
+ | Libraries | 305 | 183 | 2 | 30 | 15 | 4 |
24
+ | Model specs | 860 | 719 | 0 | 2 | 0 | 357 |
25
+ | View specs | 0 | 0 | 0 | 0 | 0 | 0 |
26
+ | Controller specs | 1570 | 1308 | 1 | 10 | 10 | 128 |
27
+ | Helper specs | 191 | 172 | 0 | 0 | 0 | 0 |
28
+ | Library specs | 31 | 27 | 0 | 0 | 0 | 0 |
29
+ +----------------------+-------+-------+---------+---------+-----+-------+
30
+ | Total | 3906 | 3141 | 19 | 132 | 6 | 21 |
31
+ +----------------------+-------+-------+---------+---------+-----+-------+
32
+ Code LOC: 915 Test LOC: 2226 Code to Test Ratio: 1:2.4
33
+
34
+ HERE
35
+ MetricFu::Configuration.run {}
36
+ File.stub!(:directory?).and_return(true)
37
+ stats = MetricFu::Stats.new
38
+ File.should_receive(:open).and_return(mock("file", :read => @lines))
39
+ @results = stats.analyze
40
+ end
41
+
42
+ it "should get code Lines Of Code" do
43
+ @results[:codeLOC].should == 915
44
+ end
45
+
46
+ it "should get test Lines Of Code" do
47
+ @results[:testLOC].should == 2226
48
+ end
49
+
50
+ it "should get code to test ratio" do
51
+ @results[:code_to_test_ratio].should == 2.4
52
+ end
53
+
54
+ it "should get data on models" do
55
+ model_data = @results[:lines].find {|line| line[:name] == "Models"}
56
+ model_data[:classes].should == 9
57
+ model_data[:methods].should == 31
58
+ model_data[:loc].should == 285
59
+ model_data[:lines].should == 351
60
+ model_data[:methods_per_class].should == 3
61
+ model_data[:loc_per_method].should == 7
62
+ end
63
+ end
64
+
65
+ describe "to_h method" do
66
+ it "should put things into a hash" do
67
+ MetricFu::Configuration.run {}
68
+ File.stub!(:directory?).and_return(true)
69
+ stats = MetricFu::Stats.new
70
+ stats.instance_variable_set(:@stats, "the_stats")
71
+ stats.to_h[:stats].should == "the_stats"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe "Bluff graphers responding to #graph!" do
4
+ it "should write chart file" do
5
+ MetricFu.configuration
6
+ graphs = {}
7
+ available_graphs = MetricFu::AVAILABLE_GRAPHS + [:stats]
8
+ available_graphs.each do |graph|
9
+ graphs[graph] = MetricFu.const_get("#{graph.to_s.capitalize}BluffGrapher").new
10
+ end
11
+ graphs.each do |key, val|
12
+ val.graph!
13
+ output_dir = File.expand_path(File.join(MetricFu.output_directory))
14
+ lambda{ File.open(File.join(output_dir, "#{key.to_s.downcase}.js")) }.should_not raise_error
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,109 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+ describe MetricFu::GchartGrapher do
3
+ describe "determine_y_axis_scale" do
4
+ it "should set defaults when empty array" do
5
+ grapher = Object.new.extend(MetricFu::GchartGrapher)
6
+ grapher.determine_y_axis_scale([])
7
+ grapher.instance_variable_get(:@max_value).should == 10
8
+ grapher.instance_variable_get(:@yaxis).should == [0, 2, 4, 6, 8, 10]
9
+ end
10
+
11
+ it "should set max value of the graph above largest value" do
12
+ grapher = Object.new.extend(MetricFu::GchartGrapher)
13
+ grapher.determine_y_axis_scale([19])
14
+ grapher.instance_variable_get(:@max_value).should == 20
15
+
16
+ grapher.determine_y_axis_scale([20])
17
+ grapher.instance_variable_get(:@max_value).should == 25
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "Gchart graphers" do
23
+ before :each do
24
+ MetricFu.configuration
25
+ end
26
+
27
+ describe "FlayGchartGrapher graph! method" do
28
+ it "should set static values for graph" do
29
+ grapher = FlayGchartGrapher.new
30
+ expected = {
31
+ :size => MetricFu::GchartGrapher::GCHART_GRAPH_SIZE,
32
+ :title => URI.escape("Flay: duplication"),
33
+ :axis_with_labels => 'x,y',
34
+ :format => 'file',
35
+ :filename => File.join(MetricFu.output_directory, 'flay.png'),
36
+ }
37
+ Gchart.should_receive(:line).with(hash_including(expected))
38
+ grapher.graph!
39
+ end
40
+ end
41
+
42
+ describe "FlogGchartGrapher graph! method" do
43
+ it "should set static values for graph" do
44
+ grapher = FlogGchartGrapher.new
45
+ expected = {
46
+ :size => MetricFu::GchartGrapher::GCHART_GRAPH_SIZE,
47
+ :title => URI.escape("Flog: code complexity"),
48
+ :stacked => false,
49
+ :bar_colors => MetricFu::GchartGrapher::COLORS[0..1],
50
+ :legend => ['average', 'top 5% average'],
51
+ :custom => "chdlp=t",
52
+ :axis_with_labels => 'x,y',
53
+ :format => 'file',
54
+ :filename => File.join(MetricFu.output_directory, 'flog.png'),
55
+ }
56
+ Gchart.should_receive(:line).with(hash_including(expected))
57
+ grapher.graph!
58
+ end
59
+ end
60
+
61
+ describe "RcovGchartGrapher graph! method" do
62
+ it "should set static values for graph" do
63
+ grapher = RcovGchartGrapher.new
64
+ expected = {
65
+ :size => MetricFu::GchartGrapher::GCHART_GRAPH_SIZE,
66
+ :title => URI.escape("Rcov: code coverage"),
67
+ :max_value => 101,
68
+ :axis_with_labels => 'x,y',
69
+ :axis_labels => [grapher.labels.values, [0,20,40,60,80,100]],
70
+ :format => 'file',
71
+ :filename => File.join(MetricFu.output_directory, 'rcov.png'),
72
+ }
73
+ Gchart.should_receive(:line).with(hash_including(expected))
74
+ grapher.graph!
75
+ end
76
+ end
77
+
78
+ describe "ReekGchartGrapher graph! method" do
79
+ it "should set static values for graph" do
80
+ grapher = ReekGchartGrapher.new
81
+ expected = {
82
+ :size => MetricFu::GchartGrapher::GCHART_GRAPH_SIZE,
83
+ :title => URI.escape("Reek: code smells"),
84
+ :stacked => false,
85
+ :bar_colors => MetricFu::GchartGrapher::COLORS,
86
+ :axis_with_labels => 'x,y',
87
+ :format => 'file',
88
+ :filename => File.join(MetricFu.output_directory, 'reek.png'),
89
+ }
90
+ Gchart.should_receive(:line).with(hash_including(expected))
91
+ grapher.graph!
92
+ end
93
+ end
94
+
95
+ describe "RoodiGchartGrapher graph! method" do
96
+ it "should set static values for graph" do
97
+ grapher = RoodiGchartGrapher.new
98
+ expected = {
99
+ :size => MetricFu::GchartGrapher::GCHART_GRAPH_SIZE,
100
+ :title => URI.escape("Roodi: potential design problems"),
101
+ :axis_with_labels => 'x,y',
102
+ :format => 'file',
103
+ :filename => File.join(MetricFu.output_directory, 'roodi.png'),
104
+ }
105
+ Gchart.should_receive(:line).with(hash_including(expected))
106
+ grapher.graph!
107
+ end
108
+ end
109
+ end