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,32 @@
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
+
25
+ describe "#date_for(report)" do
26
+ it "should return the right month/day date for the given report file name" do
27
+ @graph.send(:date_for, "tmp/metric_fu/_data/20100502.yml").should == "5/2"
28
+ @graph.send(:date_for, "tmp/metric_fu/_data/20081101.yml").should == "11/1"
29
+ @graph.send(:date_for, "tmp/metric_fu/_data/20081231.yml").should == "12/31"
30
+ end
31
+ end
32
+ 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,43 @@
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
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
10
+ @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
11
+ end
12
+
13
+ it "should be empty on error" do
14
+ churn = MetricFu::Churn.new
15
+ churn.instance_variable_set(:@output, "fatal: Not a git repository")
16
+ result = churn.analyze
17
+ result.should == [:churn => {}]
18
+ end
19
+
20
+ it "should return yaml results" do
21
+ churn = MetricFu::Churn.new
22
+ 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")
23
+ result = churn.analyze
24
+ 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"]}}
25
+ end
26
+
27
+ end
28
+
29
+ describe "to_h method" do
30
+ before :each do
31
+ MetricFu::Configuration.run {}
32
+ File.stub!(:directory?).and_return(true)
33
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
34
+ end
35
+
36
+ it "should put the changes into a hash" do
37
+ churn = MetricFu::Churn.new
38
+ churn.instance_variable_set(:@churn, {:churn => 'results'})
39
+ churn.to_h[:churn].should == "results"
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Flay do
4
+ before :each do
5
+ MetricFu::Flay.stub!(:verify_dependencies!).and_return(true)
6
+ end
7
+ describe "emit method" do
8
+ it "should look at the dirs" do
9
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
10
+ File.stub!(:directory?).and_return(true)
11
+ @flay = MetricFu::Flay.new('base_dir')
12
+
13
+ Dir.should_receive(:[]).with(File.join("app", "**/*.rb")).and_return("path/to/app")
14
+ Dir.should_receive(:[]).with(File.join("lib", "**/*.rb")).and_return("path/to/lib")
15
+ @flay.should_receive(:`).with("flay path/to/app path/to/lib")
16
+ output = @flay.emit
17
+ end
18
+
19
+ it "should limit flay scores by the minimum_score" do
20
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
21
+ File.stub!(:directory?).and_return(true)
22
+ @flay = MetricFu::Flay.new('base_dir')
23
+
24
+ @flay.should_receive(:`).with("flay --mass 99 ")
25
+ output = @flay.emit
26
+ end
27
+ end
28
+
29
+ describe "analyze method" do
30
+ before :each do
31
+ lines = <<-HERE
32
+ Total score (lower is better) = 246
33
+
34
+
35
+ 1) IDENTICAL code found in :or (mass*2 = 68)
36
+ app/controllers/link_targets_controller.rb:57
37
+ app/controllers/primary_sites_controller.rb:138
38
+
39
+ 2) Similar code found in :if (mass = 64)
40
+ app/controllers/primary_sites_controller.rb:75
41
+ app/controllers/primary_sites_controller.rb:76
42
+ app/controllers/primary_sites_controller.rb:88
43
+ app/controllers/primary_sites_controller.rb:89
44
+ HERE
45
+ MetricFu::Configuration.run {}
46
+ File.stub!(:directory?).and_return(true)
47
+ @flay = MetricFu::Flay.new('base_dir')
48
+ @flay.instance_variable_set(:@output, lines)
49
+ end
50
+
51
+ it "should analyze and return matches" do
52
+ @flay.analyze.should == [ ["Total score (lower is better) = 246"],
53
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
54
+ "app/controllers/link_targets_controller.rb:57",
55
+ "app/controllers/primary_sites_controller.rb:138"],
56
+ ["2) Similar code found in :if (mass = 64)",
57
+ "app/controllers/primary_sites_controller.rb:75",
58
+ "app/controllers/primary_sites_controller.rb:76",
59
+ "app/controllers/primary_sites_controller.rb:88",
60
+ "app/controllers/primary_sites_controller.rb:89"] ]
61
+ end
62
+ end
63
+
64
+ describe "to_h method" do
65
+
66
+ before :each do
67
+ lines = [ ["Total score (lower is better) = 284"],
68
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
69
+ "app/controllers/link_targets_controller.rb:57",
70
+ "app/controllers/primary_sites_controller.rb:138"],
71
+ ["2) Similar code found in :if (mass = 64)",
72
+ "app/controllers/primary_sites_controller.rb:75",
73
+ "app/controllers/primary_sites_controller.rb:76",
74
+ "app/controllers/primary_sites_controller.rb:88",
75
+ "app/controllers/primary_sites_controller.rb:89"],
76
+ ["3) Similar code found in :defn (mass = 40)",
77
+ "app/controllers/link_targets_controller.rb:40",
78
+ "app/controllers/primary_sites_controller.rb:98"],
79
+ ["4) Similar code found in :defn (mass = 38)",
80
+ "app/controllers/link_targets_controller.rb:13",
81
+ "app/controllers/primary_sites_controller.rb:50"],
82
+ ["5) Similar code found in :defn (mass = 38)",
83
+ "app/models/primary_site.rb:104",
84
+ "app/models/primary_site.rb:109"],
85
+ ["6) Similar code found in :call (mass = 36)",
86
+ "app/controllers/bookmarklet_integration_controller.rb:6",
87
+ "app/controllers/bookmarklet_integration_controller.rb:17"]]
88
+
89
+ MetricFu::Configuration.run {}
90
+ File.stub!(:directory?).and_return(true)
91
+ flay = MetricFu::Flay.new('base_dir')
92
+ flay.instance_variable_set(:@matches, lines)
93
+ @results = flay.to_h
94
+ end
95
+
96
+ it "should find the total_score" do
97
+ @results[:flay][:total_score].should == '284'
98
+ end
99
+
100
+ it "should have 6 matches" do
101
+ @results[:flay][:matches].size.should == 6
102
+ end
103
+
104
+ it "should capture info for match" do
105
+ @results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
106
+ @results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
107
+ @results[:flay][:matches].first[:matches].first[:line].should == "57"
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,262 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ describe Flog do
3
+ before :each do
4
+ @text = <<-HERE
5
+ 157.9: flog total
6
+ 11.3: flog/method average
7
+
8
+ 34.8: UsersController#create
9
+ 9.2: branch
10
+ 6.8: current_user
11
+ 5.2: assignment
12
+ 3.4: role
13
+ 3.0: render
14
+ 3.0: ==
15
+ 2.8: flash
16
+ 1.6: after_create_page
17
+ 1.6: params
18
+ 1.5: activate!
19
+ 1.5: errors
20
+ 1.4: login
21
+ 1.4: redirect_to
22
+ 1.4: []
23
+ 1.3: empty?
24
+ 1.3: save
25
+ 1.2: new
26
+ 24.2: UsersController#authorize_user
27
+ 4.8: branch
28
+ 4.7: current_user
29
+ 3.6: params
30
+ 3.2: []
31
+ 2.6: ==
32
+ 1.5: role
33
+ 1.5: to_i
34
+ 1.5: id
35
+ 1.4: new_session_path
36
+ 1.3: include?
37
+ 1.2: assignment
38
+ 1.2: flash
39
+ 1.2: redirect_to
40
+ 16.4: UsersController#thank_you
41
+ 4.0: assignment
42
+ 3.3: params
43
+ 2.9: []
44
+ 2.7: redirect_to
45
+ 2.4: branch
46
+ 1.5: new_session_path
47
+ 1.4: flash
48
+ 1.4: activate!
49
+ 1.3: can_activate?
50
+ 1.2: find_by_id
51
+ 14.2: UsersController#update
52
+ 3.2: params
53
+ 2.8: []
54
+ 2.6: assignment
55
+ 1.4: login
56
+ 1.4: flash
57
+ 1.4: redirect_to
58
+ 1.3: render
59
+ 1.2: branch
60
+ 1.2: update_attributes
61
+ 1.2: find_by_id
62
+ 12.5: UsersController#sanitize_params
63
+ 3.9: assignment
64
+ 3.6: branch
65
+ 3.0: current_user
66
+ 1.6: params
67
+ 1.5: role
68
+ 1.4: []
69
+ 1.3: include?
70
+ 1.3: ==
71
+ 1.2: reject!
72
+ 10.6: UsersController#users_have_changed
73
+ 3.9: assignment
74
+ 2.6: branch
75
+ 1.6: params
76
+ 1.5: refresh_from_external
77
+ 1.4: find_by_id
78
+ 1.4: []
79
+ 1.2: split
80
+ 1.2: each
81
+ 1.2: head
82
+ 10.0: UsersController#after_create_page
83
+ 3.0: current_user
84
+ 2.6: id
85
+ 2.4: branch
86
+ 1.5: role
87
+ 1.3: login
88
+ 1.3: ==
89
+ 8.4: UsersController#add_primary_site
90
+ 2.4: assignment
91
+ 1.6: params
92
+ 1.4: []
93
+ 1.4: new
94
+ 1.2: find_by_id
95
+ 1.2: all
96
+ 1.2: render
97
+ 7.7: UsersController#none
98
+ 3.3: before_filter
99
+ 1.1: private
100
+ 1.1: caches_page
101
+ 1.1: after_filter
102
+ 1.1: skip_before_filter
103
+ 7.2: UsersController#destroy
104
+ 1.8: params
105
+ 1.6: []
106
+ 1.4: find_by_id
107
+ 1.2: destroy
108
+ 1.2: redirect_to
109
+ 5.9: UsersController#edit
110
+ 2.4: assignment
111
+ 1.6: params
112
+ 1.4: []
113
+ 1.2: all
114
+ 1.2: find_by_id
115
+ 2.7: UsersController#signup
116
+ 1.2: render
117
+ 1.2: assignment
118
+ 1.2: new
119
+ 1.7: UsersController#new
120
+ 1.2: assignment
121
+ 1.2: new
122
+ 1.7: UsersController#index
123
+ 1.2: assignment
124
+ 1.2: all
125
+ HERE
126
+ MetricFu::Flog.stub!(:verify_dependencies!).and_return(true)
127
+ end
128
+
129
+ describe "parse method" do
130
+ before :each do
131
+ MetricFu::Configuration.run {}
132
+ File.stub!(:directory?).and_return(true)
133
+ flog = MetricFu::Flog.new('base_dir')
134
+ @flog_page = flog.parse(@text)
135
+ end
136
+
137
+ it "should find the total score" do
138
+ @flog_page.score.should == 157.9
139
+ end
140
+
141
+ it "should find the average score" do
142
+ @flog_page.average_score.should == 11.3
143
+ end
144
+
145
+ it "should find the scanned method score" do
146
+ @flog_page.scanned_methods.first.score.should == 34.8
147
+ end
148
+
149
+ it "should find the scanned method name" do
150
+ @flog_page.scanned_methods.first.name.should == "UsersController#create"
151
+ end
152
+
153
+ it "should find the scanned method opperators names" do
154
+ @flog_page.scanned_methods.first.operators.first.operator.should == "branch"
155
+ end
156
+
157
+ it "should find the scanned method opperators scores" do
158
+ @flog_page.scanned_methods.first.operators.first.score.should == 9.2
159
+ end
160
+
161
+ it "should find the name of the method even if namespaced" do
162
+ text = <<-HERE
163
+ 157.9: flog total
164
+ 11.3: flog/method average
165
+
166
+ 34.8: SomeNamespace::UsersController#create
167
+ HERE
168
+ flog = MetricFu::Flog.new('base_dir')
169
+ flog_page = flog.parse(text)
170
+ flog_page.scanned_methods.first.name.should == "SomeNamespace::UsersController#create"
171
+ end
172
+
173
+ it "should find the line number for the method" do
174
+ text = <<-HERE
175
+ 157.9: flog total
176
+ 11.3: flog/method average
177
+
178
+ 34.8: SomeNamespace::UsersController#create lib/blah/file.rb:37
179
+ HERE
180
+ flog = MetricFu::Flog.new('base_dir')
181
+ flog_page = flog.parse(text)
182
+ flog_page.scanned_methods.first.line.should == "37"
183
+ end
184
+
185
+ it "should not add a line number, when none is found" do
186
+ text = <<-HERE
187
+ 157.9: flog total
188
+ 11.3: flog/method average
189
+
190
+ 34.8: UsersController#none lib/blah/file.rb
191
+ HERE
192
+ flog = MetricFu::Flog.new('base_dir')
193
+ flog_page = flog.parse(text)
194
+ flog_page.scanned_methods.first.line.should == nil
195
+ end
196
+
197
+ it "should parse empty flog files" do
198
+ text = ""
199
+ flog = MetricFu::Flog.new('base_dir')
200
+ flog_page = flog.parse(text)
201
+ flog_page.should be_nil
202
+ end
203
+ end
204
+
205
+ describe "to_h function with results" do
206
+ before :each do
207
+ MetricFu::Configuration.run {}
208
+ File.stub!(:directory?).and_return(true)
209
+ flog = MetricFu::Flog.new('base_dir')
210
+ flog.should_receive(:open).and_return(@text)
211
+ flog.stub!(:is_file_current?).and_return(true)
212
+ Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
213
+ flog.analyze
214
+ @flog_hash = flog.to_h
215
+ end
216
+
217
+ it "should put the total in the hash" do
218
+ @flog_hash[:flog][:total].should == 157.9
219
+ end
220
+
221
+ it "should put the average in the hash" do
222
+ @flog_hash[:flog][:average].should == 11.3
223
+ end
224
+
225
+ it "should put pages into the hash" do
226
+ @flog_hash[:flog][:pages].first[:scanned_methods].first[:score].should == 34.8
227
+ end
228
+
229
+ it "should put the filename into the hash" do
230
+ @flog_hash[:flog][:pages].first[:path].should == "/app/controllers/user_controller.rb"
231
+ end
232
+ end
233
+
234
+ describe "to_h function ignore files not current" do
235
+ before :each do
236
+ MetricFu::Configuration.run {}
237
+ File.stub!(:directory?).and_return(true)
238
+ flog = MetricFu::Flog.new('base_dir')
239
+ flog.should_receive(:open).and_return(@text)
240
+ flog.stub!(:is_file_current?).and_return(false)
241
+ Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
242
+ flog.analyze
243
+ @flog_hash = flog.to_h
244
+ end
245
+
246
+ it "should put the total in the hash" do
247
+ @flog_hash.should == {:flog=>{:total=>0, :pages=>[], :average=>0}}
248
+ end
249
+
250
+ end
251
+
252
+ describe "to_h function with zero total" do
253
+ it "should not blow up" do
254
+ MetricFu::Configuration.run {}
255
+ File.stub!(:directory?).and_return(true)
256
+ flog = MetricFu::Flog.new('base_dir')
257
+ flog.should_receive(:open).and_return("") # some sort of empty or unparsable file
258
+ Dir.should_receive(:glob).and_return(["empty_file.txt"])
259
+ flog.analyze
260
+ end
261
+ end
262
+ end