khall-metric_fu 1.0.2.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.
Files changed (47) hide show
  1. data/HISTORY +119 -0
  2. data/MIT-LICENSE +22 -0
  3. data/Manifest.txt +25 -0
  4. data/README +1 -0
  5. data/Rakefile +46 -0
  6. data/TODO +14 -0
  7. data/lib/base/base_template.rb +134 -0
  8. data/lib/base/configuration.rb +187 -0
  9. data/lib/base/generator.rb +147 -0
  10. data/lib/base/md5_tracker.rb +52 -0
  11. data/lib/base/report.rb +100 -0
  12. data/lib/generators/churn.rb +86 -0
  13. data/lib/generators/flay.rb +29 -0
  14. data/lib/generators/flog.rb +127 -0
  15. data/lib/generators/rcov.rb +77 -0
  16. data/lib/generators/reek.rb +32 -0
  17. data/lib/generators/roodi.rb +24 -0
  18. data/lib/generators/saikuro.rb +212 -0
  19. data/lib/generators/stats.rb +43 -0
  20. data/lib/metric_fu.rb +20 -0
  21. data/lib/templates/standard/churn.html.erb +30 -0
  22. data/lib/templates/standard/default.css +64 -0
  23. data/lib/templates/standard/flay.html.erb +33 -0
  24. data/lib/templates/standard/flog.html.erb +52 -0
  25. data/lib/templates/standard/index.html.erb +38 -0
  26. data/lib/templates/standard/rcov.html.erb +42 -0
  27. data/lib/templates/standard/reek.html.erb +41 -0
  28. data/lib/templates/standard/roodi.html.erb +28 -0
  29. data/lib/templates/standard/saikuro.html.erb +83 -0
  30. data/lib/templates/standard/standard_template.rb +26 -0
  31. data/lib/templates/standard/stats.html.erb +54 -0
  32. data/spec/base/base_template_spec.rb +140 -0
  33. data/spec/base/configuration_spec.rb +303 -0
  34. data/spec/base/generator_spec.rb +159 -0
  35. data/spec/base/md5_tracker_spec.rb +57 -0
  36. data/spec/base/report_spec.rb +139 -0
  37. data/spec/generators/churn_spec.rb +152 -0
  38. data/spec/generators/flay_spec.rb +101 -0
  39. data/spec/generators/flog_spec.rb +200 -0
  40. data/spec/generators/reek_spec.rb +59 -0
  41. data/spec/generators/saikuro_spec.rb +53 -0
  42. data/spec/generators/stats_spec.rb +74 -0
  43. data/spec/spec_helper.rb +28 -0
  44. data/tasks/metric_fu.rake +15 -0
  45. data/tasks/railroad.rake +39 -0
  46. data/vendor/saikuro/saikuro.rb +1214 -0
  47. metadata +163 -0
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
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.dirname(__FILE__) + "/../spec_helper.rb"
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,152 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Churn do
4
+ describe "initialize" do
5
+ before :each do
6
+ MetricFu::Configuration.run {}
7
+ File.stub!(:directory?).and_return(true)
8
+ end
9
+
10
+ it "should setup git if .git exits" do
11
+ File.should_receive(:exist?).with(".git").and_return(true)
12
+ Churn::Git.should_receive(:new)
13
+ MetricFu::Churn.new
14
+ end
15
+
16
+ it "should setup git if .svn exits" do
17
+ File.should_receive(:exist?).with(".git").and_return(false)
18
+ File.should_receive(:exist?).with(".svn").and_return(true)
19
+ Churn::Svn.should_receive(:new)
20
+ MetricFu::Churn.new()
21
+ end
22
+
23
+ it "should raise an error if not .svn or .git" do
24
+ File.stub!(:exist?).and_return(false)
25
+ lambda{MetricFu::Churn.new()}.should raise_error(Exception)
26
+ end
27
+ end
28
+
29
+ describe "emit method with git" do
30
+ before :each do
31
+ MetricFu::Configuration.run {|config| config.churn = {:minimum_churn_count => 2} }
32
+ File.stub!(:directory?).and_return(true)
33
+ File.should_receive(:exist?).with(".git").and_return(true)
34
+ @git = Churn::Git.new
35
+ Churn::Git.should_receive(:new).and_return(@git)
36
+ @lines = <<-HERE.gsub(/^\s*/, "")
37
+
38
+ lib/generators/flog.rb
39
+ spec/generators/flog_spec.rb
40
+
41
+
42
+ lib/generators/flog.rb
43
+ spec/generators/flay_spec.rb
44
+
45
+
46
+ lib/metric_fu.rb
47
+
48
+
49
+ lib/generators/saikuro.rb
50
+ lib/metric_fu.rb
51
+ tasks/metric_fu.rake
52
+
53
+
54
+ spec/churn_spec.rb
55
+ spec/config_spec.rb
56
+ spec/flay_spec.rb
57
+ spec/flog_spec.rb
58
+ lib/metric_fu.rb
59
+ spec/reek_spec.rb
60
+ HERE
61
+ end
62
+
63
+ it "should read the logs" do
64
+ churn = MetricFu::Churn.new
65
+ @git.should_receive(:`).with("git log --name-only --pretty=format:").and_return(@lines)
66
+ changes = churn.emit
67
+ changes["lib/generators/flog.rb"].should == 2
68
+ changes["lib/metric_fu.rb"].should == 3
69
+ end
70
+ end
71
+
72
+ describe "emit method with svn" do
73
+ before :each do
74
+ MetricFu::Configuration.run{|config| config.churn = {:minimum_churn_count => 2} }
75
+ File.stub!(:directory?).and_return(true)
76
+ File.should_receive(:exist?).with(".git").and_return(false)
77
+ File.should_receive(:exist?).with(".svn").and_return(true)
78
+ @svn = Churn::Svn.new
79
+ Churn::Svn.should_receive(:new).and_return(@svn)
80
+ @lines = <<-HERE.gsub(/^\s*/, "")
81
+ ------------------------------------------------------------------------
82
+ r3183 | dave | 2009-04-28 07:23:37 -0500 (Tue, 28 Apr 2009) | 1 line
83
+ Changed paths:
84
+ M /trunk/app/views/promotions/index.erb
85
+ M /trunk/app/models/email_personalizer.rb
86
+
87
+ making custom macros case-insensitive
88
+ ------------------------------------------------------------------------
89
+ r3182 | marc | 2009-04-28 03:59:32 -0500 (Tue, 28 Apr 2009) | 1 line
90
+ Changed paths:
91
+ M /trunk/app/models/file_extraction.rb
92
+ M /trunk/app/views/promotions/index.erb
93
+ M /trunk/config/environment.rb
94
+
95
+ Demo of the drop out effect for uploading promotions.
96
+ ------------------------------------------------------------------------
97
+ r3181 | dave | 2009-04-27 21:40:04 -0500 (Mon, 27 Apr 2009) | 1 line
98
+ Changed paths:
99
+ M /trunk/app/views/promotions/index.erb
100
+ A /trunk/app/models/file_extraction.rb
101
+ A /trunk/app/models/url_file_extraction.rb
102
+ M /trunk/app/models/zip_file_extraction.rb
103
+ M /trunk/test/data/zip_test.zip
104
+ M /trunk/test/unit/zip_file_extraction_test.rb
105
+
106
+ URL imports
107
+ HERE
108
+ end
109
+
110
+ it "should read the logs" do
111
+ churn = MetricFu::Churn.new
112
+ @svn.should_receive(:`).with("svn log --verbose").and_return(@lines)
113
+ changes = churn.emit
114
+ changes["/trunk/app/views/promotions/index.erb"].should == 3
115
+ changes["/trunk/app/models/file_extraction.rb"].should == 2
116
+ end
117
+ end
118
+
119
+ describe "analyze method" do
120
+ before :each do
121
+ MetricFu::Configuration.run {}
122
+ File.stub!(:directory?).and_return(true)
123
+ File.should_receive(:exist?).with(".git").and_return(true)
124
+ @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
125
+ end
126
+
127
+ it "should organize and format" do
128
+ churn = MetricFu::Churn.new
129
+ churn.instance_variable_set(:@changes, @changes)
130
+ changes = churn.analyze
131
+ changes.first[:file_path].should == "lib/metric_fu.rb"
132
+ changes.first[:times_changed].should == 3
133
+ changes[1][:file_path].should == "lib/generators/flog.rb"
134
+ changes[1][:times_changed].should == 2
135
+ end
136
+ end
137
+
138
+ describe "to_h method" do
139
+ before :each do
140
+ MetricFu::Configuration.run {}
141
+ File.stub!(:directory?).and_return(true)
142
+ File.should_receive(:exist?).with(".git").and_return(true)
143
+ end
144
+
145
+ it "should put the changes into a hash" do
146
+ churn = MetricFu::Churn.new
147
+ churn.instance_variable_set(:@changes, "churn_info")
148
+ churn.to_h[:churn][:changes].should == "churn_info"
149
+ end
150
+ end
151
+ end
152
+
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe Flay do
4
+ describe "emit method" do
5
+ before :each do
6
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
7
+ File.stub!(:directory?).and_return(true)
8
+ @flay = MetricFu::Flay.new('base_dir')
9
+
10
+ end
11
+
12
+ it "should look at the dirs" do
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
+ end
19
+
20
+ describe "analyze method" do
21
+ before :each do
22
+ lines = <<-HERE
23
+ Total score (lower is better) = 246
24
+
25
+
26
+ 1) IDENTICAL code found in :or (mass*2 = 68)
27
+ app/controllers/link_targets_controller.rb:57
28
+ app/controllers/primary_sites_controller.rb:138
29
+
30
+ 2) Similar code found in :if (mass = 64)
31
+ app/controllers/primary_sites_controller.rb:75
32
+ app/controllers/primary_sites_controller.rb:76
33
+ app/controllers/primary_sites_controller.rb:88
34
+ app/controllers/primary_sites_controller.rb:89
35
+ HERE
36
+ MetricFu::Configuration.run {}
37
+ File.stub!(:directory?).and_return(true)
38
+ @flay = MetricFu::Flay.new('base_dir')
39
+ @flay.instance_variable_set(:@output, lines)
40
+ end
41
+
42
+ it "should analyze and return matches" do
43
+ @flay.analyze.should == [ ["Total score (lower is better) = 246"],
44
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
45
+ "app/controllers/link_targets_controller.rb:57",
46
+ "app/controllers/primary_sites_controller.rb:138"],
47
+ ["2) Similar code found in :if (mass = 64)",
48
+ "app/controllers/primary_sites_controller.rb:75",
49
+ "app/controllers/primary_sites_controller.rb:76",
50
+ "app/controllers/primary_sites_controller.rb:88",
51
+ "app/controllers/primary_sites_controller.rb:89"] ]
52
+ end
53
+ end
54
+
55
+ describe "to_h method" do
56
+
57
+ before :each do
58
+ lines = [ ["Total score (lower is better) = 284"],
59
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
60
+ "app/controllers/link_targets_controller.rb:57",
61
+ "app/controllers/primary_sites_controller.rb:138"],
62
+ ["2) Similar code found in :if (mass = 64)",
63
+ "app/controllers/primary_sites_controller.rb:75",
64
+ "app/controllers/primary_sites_controller.rb:76",
65
+ "app/controllers/primary_sites_controller.rb:88",
66
+ "app/controllers/primary_sites_controller.rb:89"],
67
+ ["3) Similar code found in :defn (mass = 40)",
68
+ "app/controllers/link_targets_controller.rb:40",
69
+ "app/controllers/primary_sites_controller.rb:98"],
70
+ ["4) Similar code found in :defn (mass = 38)",
71
+ "app/controllers/link_targets_controller.rb:13",
72
+ "app/controllers/primary_sites_controller.rb:50"],
73
+ ["5) Similar code found in :defn (mass = 38)",
74
+ "app/models/primary_site.rb:104",
75
+ "app/models/primary_site.rb:109"],
76
+ ["6) Similar code found in :call (mass = 36)",
77
+ "app/controllers/bookmarklet_integration_controller.rb:6",
78
+ "app/controllers/bookmarklet_integration_controller.rb:17"]]
79
+
80
+ MetricFu::Configuration.run {}
81
+ File.stub!(:directory?).and_return(true)
82
+ flay = MetricFu::Flay.new('base_dir')
83
+ flay.instance_variable_set(:@matches, lines)
84
+ @results = flay.to_h
85
+ end
86
+
87
+ it "should find the total_score" do
88
+ @results[:flay][:total_score].should == '284'
89
+ end
90
+
91
+ it "should have 6 matches" do
92
+ @results[:flay][:matches].size.should == 6
93
+ end
94
+
95
+ it "should capture info for match" do
96
+ @results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
97
+ @results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
98
+ @results[:flay][:matches].first[:matches].first[:line].should == "57"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,200 @@
1
+ require 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
+ end
127
+
128
+ describe "parse method" do
129
+ before :each do
130
+ MetricFu::Configuration.run {}
131
+ File.stub!(:directory?).and_return(true)
132
+ flog = MetricFu::Flog.new('base_dir')
133
+ @flog_page = flog.parse(@text)
134
+ end
135
+
136
+ it "should find the total score" do
137
+ @flog_page.score.should == 157.9
138
+ end
139
+
140
+ it "should find the average score" do
141
+ @flog_page.average_score.should == 11.3
142
+ end
143
+
144
+ it "should find the scanned method score" do
145
+ @flog_page.scanned_methods.first.score.should == 34.8
146
+ end
147
+
148
+ it "should find the scanned method name" do
149
+ @flog_page.scanned_methods.first.name.should == "UsersController#create"
150
+ end
151
+
152
+ it "should find the scanned method opperators names" do
153
+ @flog_page.scanned_methods.first.operators.first.operator.should == "branch"
154
+ end
155
+
156
+ it "should find the scanned method opperators scores" do
157
+ @flog_page.scanned_methods.first.operators.first.score.should == 9.2
158
+ end
159
+
160
+ it "should find the name of the method even if namespaced" do
161
+ text = <<-HERE
162
+ 157.9: flog total
163
+ 11.3: flog/method average
164
+
165
+ 34.8: SomeNamespace::UsersController#create
166
+ HERE
167
+ flog = MetricFu::Flog.new('base_dir')
168
+ flog_page = flog.parse(text)
169
+ flog_page.scanned_methods.first.name.should == "SomeNamespace::UsersController#create"
170
+ end
171
+ end
172
+
173
+ describe "to_h function" do
174
+ before :each do
175
+ MetricFu::Configuration.run {}
176
+ File.stub!(:directory?).and_return(true)
177
+ flog = MetricFu::Flog.new('base_dir')
178
+ flog.should_receive(:open).and_return(@text)
179
+ Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
180
+ flog.analyze
181
+ @flog_hash = flog.to_h
182
+ end
183
+
184
+ it "should put the total in the hash" do
185
+ @flog_hash[:flog][:total].should == 157.9
186
+ end
187
+
188
+ it "should put the average in the hash" do
189
+ @flog_hash[:flog][:average].should == 11.3
190
+ end
191
+
192
+ it "should put pages into the hash" do
193
+ @flog_hash[:flog][:pages].first[:scanned_methods].first[:score].should == 34.8
194
+ end
195
+
196
+ it "should put the filename into the hash" do
197
+ @flog_hash[:flog][:pages].first[:path].should == "/app/controllers/user_controller.rb"
198
+ end
199
+ end
200
+ end