metric_fu 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/HISTORY +13 -5
  2. data/README +2 -2
  3. data/Rakefile +1 -1
  4. data/TODO +3 -1
  5. data/lib/base/base_template.rb +16 -16
  6. data/lib/base/churn_analyzer.rb +3 -3
  7. data/lib/base/code_issue.rb +8 -8
  8. data/lib/base/configuration.rb +24 -22
  9. data/lib/base/flay_analyzer.rb +2 -2
  10. data/lib/base/flog_analyzer.rb +4 -4
  11. data/lib/base/generator.rb +21 -21
  12. data/lib/base/graph.rb +15 -10
  13. data/lib/base/line_numbers.rb +56 -55
  14. data/lib/base/location.rb +68 -66
  15. data/lib/base/metric_analyzer.rb +21 -21
  16. data/lib/base/ranking.rb +23 -22
  17. data/lib/base/rcov_analyzer.rb +3 -3
  18. data/lib/base/reek_analyzer.rb +12 -10
  19. data/lib/base/report.rb +9 -9
  20. data/lib/base/roodi_analyzer.rb +2 -2
  21. data/lib/base/saikuro_analyzer.rb +4 -4
  22. data/lib/base/scoring_strategies.rb +5 -5
  23. data/lib/base/stats_analyzer.rb +2 -2
  24. data/lib/base/table.rb +4 -4
  25. data/lib/generators/churn.rb +1 -1
  26. data/lib/generators/flay.rb +1 -1
  27. data/lib/generators/hotspots.rb +4 -4
  28. data/lib/generators/rails_best_practices.rb +1 -1
  29. data/lib/generators/rcov.rb +17 -17
  30. data/lib/generators/reek.rb +2 -2
  31. data/lib/generators/saikuro.rb +42 -42
  32. data/lib/generators/stats.rb +6 -6
  33. data/lib/graphs/engines/bluff.rb +1 -1
  34. data/lib/graphs/engines/gchart.rb +7 -7
  35. data/lib/graphs/flog_grapher.rb +3 -3
  36. data/lib/graphs/grapher.rb +1 -1
  37. data/lib/metric_fu.rb +2 -2
  38. data/lib/templates/awesome/churn.html.erb +1 -1
  39. data/lib/templates/awesome/css/integrity.css +0 -1
  40. data/lib/templates/awesome/flay.html.erb +2 -2
  41. data/lib/templates/awesome/flog.html.erb +2 -2
  42. data/lib/templates/awesome/hotspots.html.erb +4 -4
  43. data/lib/templates/awesome/index.html.erb +2 -2
  44. data/lib/templates/awesome/rails_best_practices.html.erb +1 -1
  45. data/lib/templates/awesome/rcov.html.erb +1 -1
  46. data/lib/templates/awesome/roodi.html.erb +1 -1
  47. data/lib/templates/awesome/saikuro.html.erb +3 -3
  48. data/lib/templates/awesome/stats.html.erb +1 -1
  49. data/lib/templates/standard/churn.html.erb +2 -2
  50. data/lib/templates/standard/default.css +4 -4
  51. data/lib/templates/standard/flay.html.erb +4 -4
  52. data/lib/templates/standard/flog.html.erb +1 -1
  53. data/lib/templates/standard/hotspots.html.erb +4 -4
  54. data/lib/templates/standard/index.html.erb +2 -2
  55. data/lib/templates/standard/rails_best_practices.html.erb +2 -2
  56. data/lib/templates/standard/rcov.html.erb +2 -2
  57. data/lib/templates/standard/reek.html.erb +1 -1
  58. data/lib/templates/standard/roodi.html.erb +2 -2
  59. data/lib/templates/standard/saikuro.html.erb +4 -4
  60. data/lib/templates/standard/stats.html.erb +2 -2
  61. data/spec/base/base_template_spec.rb +1 -1
  62. data/spec/base/configuration_spec.rb +36 -36
  63. data/spec/base/generator_spec.rb +10 -10
  64. data/spec/base/graph_spec.rb +41 -4
  65. data/spec/base/line_numbers_spec.rb +22 -22
  66. data/spec/base/report_spec.rb +9 -9
  67. data/spec/generators/churn_spec.rb +4 -4
  68. data/spec/generators/flay_spec.rb +31 -31
  69. data/spec/generators/flog_spec.rb +18 -18
  70. data/spec/generators/rails_best_practices_spec.rb +6 -6
  71. data/spec/generators/rcov_spec.rb +18 -18
  72. data/spec/generators/reek_spec.rb +10 -10
  73. data/spec/generators/roodi_spec.rb +2 -2
  74. data/spec/generators/saikuro_spec.rb +7 -7
  75. data/spec/generators/stats_spec.rb +6 -6
  76. data/spec/graphs/engines/gchart_spec.rb +8 -8
  77. data/spec/graphs/flog_grapher_spec.rb +8 -8
  78. data/spec/resources/line_numbers/foo.rb +7 -7
  79. data/spec/resources/line_numbers/module.rb +2 -2
  80. data/spec/resources/line_numbers/module_surrounds_class.rb +6 -6
  81. data/spec/resources/saikuro/index_cyclo.html +2 -2
  82. data/spec/resources/yml/20090630.yml +349 -349
  83. data/spec/resources/yml/metric_missing.yml +1 -1
  84. data/tasks/metric_fu.rake +4 -4
  85. metadata +4 -4
@@ -19,7 +19,7 @@ describe MetricFu::Generator do
19
19
  end
20
20
 
21
21
  before(:each) do
22
- @concrete_class = ConcreteClass.new
22
+ @concrete_class = ConcreteClass.new
23
23
  end
24
24
 
25
25
  describe "ConcreteClass#class_name" do
@@ -91,7 +91,7 @@ describe MetricFu::Generator do
91
91
  ConcreteClass.generate_report
92
92
  end
93
93
  end
94
-
94
+
95
95
  describe '@concrete_class should have hook methods for '\
96
96
  +'[before|after]_[emit|analyze|to_h]' do
97
97
 
@@ -105,7 +105,7 @@ describe MetricFu::Generator do
105
105
  @concrete_class.respond_to?("after_#{meth}".to_sym).should be_true
106
106
  end
107
107
  end
108
-
108
+
109
109
  it "should respond to #before_to_h" do
110
110
  @concrete_class.respond_to?("before_to_h".to_sym).should be_true
111
111
  end
@@ -129,7 +129,7 @@ describe MetricFu::Generator do
129
129
  end
130
130
 
131
131
  describe "#generate_report (in a concrete class)" do
132
-
132
+
133
133
  %w[emit analyze].each do |meth|
134
134
  it "should call #before_#{meth}" do
135
135
  @concrete_class.should_receive("before_#{meth}")
@@ -146,12 +146,12 @@ describe MetricFu::Generator do
146
146
  @concrete_class.generate_report
147
147
  end
148
148
  end
149
-
149
+
150
150
  it "should call #before_to_h" do
151
151
  @concrete_class.should_receive("before_to_h")
152
152
  @concrete_class.generate_report
153
153
  end
154
-
154
+
155
155
  it "should call #to_h" do
156
156
  @concrete_class.should_receive(:to_h)
157
157
  @concrete_class.generate_report
@@ -160,7 +160,7 @@ describe MetricFu::Generator do
160
160
  end
161
161
 
162
162
  describe "path filter" do
163
-
163
+
164
164
  context "given a list of paths" do
165
165
 
166
166
  before do
@@ -173,14 +173,14 @@ describe MetricFu::Generator do
173
173
  lib/bad/two.rb
174
174
  lib/bad/three.rb
175
175
  lib/worse/four.rb)
176
- @container = create_construct
176
+ @container = create_construct
177
177
  @paths.each do |path|
178
178
  @container.file(path)
179
179
  end
180
180
  @old_dir = Dir.pwd
181
181
  Dir.chdir(@container)
182
182
  end
183
-
183
+
184
184
  after do
185
185
  Dir.chdir(@old_dir)
186
186
  @container.destroy!
@@ -219,5 +219,5 @@ describe MetricFu::Generator do
219
219
 
220
220
 
221
221
  end
222
-
222
+
223
223
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu do
4
-
4
+
5
5
  describe "responding to #graph" do
6
6
  it "should return an instance of Graph" do
7
7
  MetricFu.graph.should be_a(Graph)
@@ -10,15 +10,52 @@ describe MetricFu do
10
10
  end
11
11
 
12
12
  describe MetricFu::Graph do
13
-
13
+
14
14
  before(:each) do
15
15
  @graph = MetricFu::Graph.new
16
16
  end
17
-
17
+
18
18
  describe "responding to #add with gchart enabled" do
19
19
  it 'should instantiate a grapher and push it to clazz' do
20
20
  @graph.clazz.should_receive(:push).with(an_instance_of(RcovGchartGrapher))
21
21
  @graph.add("rcov", 'gchart')
22
22
  end
23
- end
23
+ end
24
+
25
+ describe "responding to #add with gchart enabled" do
26
+ it 'should instantiate a grapher and push it to clazz' do
27
+ @graph.clazz.should_receive(:push).with(an_instance_of(RcovGchartGrapher))
28
+ @graph.add("rcov", 'gchart')
29
+ end
30
+ end
31
+
32
+ describe "setting the date on the graph" do
33
+ before(:each) do
34
+ @graph.stub!(:puts)
35
+ end
36
+
37
+ it "should set the date once for one data point" do
38
+ Dir.should_receive(:[]).and_return(["metric_fu/tmp/_data/20101105.yml"])
39
+ File.should_receive(:join)
40
+ File.should_receive(:open).and_return("Metrics")
41
+ mock_grapher = stub
42
+ mock_grapher.should_receive(:get_metrics).with("Metrics", "11/5")
43
+ mock_grapher.should_receive(:graph!)
44
+
45
+ @graph.clazz = [mock_grapher]
46
+ @graph.generate
47
+ end
48
+
49
+ it "should set the date when the data directory isn't in the default place" do
50
+ Dir.should_receive(:[]).and_return(["/some/kind/of/weird/directory/somebody/configured/_data/20101105.yml"])
51
+ File.should_receive(:join)
52
+ File.should_receive(:open).and_return("Metrics")
53
+ mock_grapher = stub
54
+ mock_grapher.should_receive(:get_metrics).with("Metrics", "11/5")
55
+ mock_grapher.should_receive(:graph!)
56
+
57
+ @graph.clazz = [mock_grapher]
58
+ @graph.generate
59
+ end
60
+ end
24
61
  end
@@ -1,62 +1,62 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- describe LineNumbers do
4
-
3
+ describe MetricFu::LineNumbers do
4
+
5
5
  describe "in_method?" do
6
6
  it "should know if a line is NOT in a method" do
7
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
7
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
8
8
  ln.in_method?(2).should == false
9
9
  end
10
-
10
+
11
11
  it "should know if a line is in an instance method" do
12
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
12
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
13
13
  ln.in_method?(8).should == true
14
14
  end
15
-
15
+
16
16
  it "should know if a line is in an class method" do
17
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
17
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
18
18
  ln.in_method?(3).should == true
19
19
  end
20
20
  end
21
-
21
+
22
22
  describe "method_at_line" do
23
23
  it "should know the name of an instance method at a particular line" do
24
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
24
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
25
25
  ln.method_at_line(8).should == "Foo#what"
26
26
  end
27
-
27
+
28
28
  it "should know the name of a class method at a particular line" do
29
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
29
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
30
30
  ln.method_at_line(3).should == "Foo::awesome"
31
31
  end
32
-
32
+
33
33
  it "should know the name of a private method at a particular line" do
34
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
34
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
35
35
  ln.method_at_line(28).should == "Foo#whoop"
36
36
  end
37
-
37
+
38
38
  it "should know the name of a class method defined in a 'class << self block at a particular line" do
39
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
39
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/foo.rb"))
40
40
  ln.method_at_line(23).should == "Foo::neat"
41
41
  end
42
-
42
+
43
43
  it "should know the name of an instance method at a particular line in a file with two classes" do
44
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/two_classes.rb"))
44
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/two_classes.rb"))
45
45
  ln.method_at_line(3).should == "Foo#stuff"
46
46
  ln.method_at_line(9).should == "Bar#stuff"
47
47
  end
48
-
48
+
49
49
  it "should work with modules" do
50
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/module.rb"))
50
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/module.rb"))
51
51
  ln.method_at_line(4).should == 'KickAss#get_beat_up?'
52
52
  end
53
-
53
+
54
54
  it "should work with module surrounding class" do
55
- ln = LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/module_surrounds_class.rb"))
55
+ ln = MetricFu::LineNumbers.new(File.read(File.dirname(__FILE__) + "/../resources/line_numbers/module_surrounds_class.rb"))
56
56
  ln.method_at_line(5).should == "StuffModule::ThingClass#do_it"
57
57
  # ln.method_at_line(12).should == "StuffModule#blah" #why no work?
58
58
  end
59
59
 
60
60
  end
61
-
61
+
62
62
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu do
4
-
4
+
5
5
  describe "#report" do
6
6
  it 'should return an instance of Report' do
7
7
  MetricFu.report.instance_of?(Report).should be(true)
@@ -68,9 +68,9 @@ describe MetricFu::Report do
68
68
  before(:each) do
69
69
  @config = mock('configuration')
70
70
  end
71
-
71
+
72
72
  describe 'when the platform is os x ' do
73
-
73
+
74
74
  before(:each) do
75
75
  @config.should_receive(:platform).and_return('darwin')
76
76
  end
@@ -81,7 +81,7 @@ describe MetricFu::Report do
81
81
  @config.should_receive(:is_cruise_control_rb?).and_return(true)
82
82
  MetricFu.stub!(:configuration).and_return(@config)
83
83
  end
84
-
84
+
85
85
  it 'should return false' do
86
86
  @report.open_in_browser?.should be_false
87
87
  end
@@ -99,12 +99,12 @@ describe MetricFu::Report do
99
99
  end
100
100
  end
101
101
  end
102
-
102
+
103
103
  describe 'when the platform is not os x ' do
104
104
  before(:each) do
105
105
  @config.should_receive(:platform).and_return('other')
106
106
  end
107
-
107
+
108
108
  describe 'and we are in cruise control' do
109
109
  before(:each) do
110
110
  MetricFu.stub!(:configuration).and_return(@config)
@@ -119,14 +119,14 @@ describe MetricFu::Report do
119
119
  before(:each) do
120
120
  MetricFu.stub!(:configuration).and_return(@config)
121
121
  end
122
-
122
+
123
123
  it 'should return false' do
124
124
  @report.open_in_browser?.should be_false
125
125
  end
126
126
  end
127
127
  end
128
128
  end
129
-
129
+
130
130
 
131
131
  describe '#show_in_browser' do
132
132
  it 'should call open with the passed directory' do
@@ -134,6 +134,6 @@ describe MetricFu::Report do
134
134
  @report.should_receive(:system).with("open my_dir/index.html")
135
135
  @report.show_in_browser('my_dir')
136
136
  end
137
-
137
+
138
138
  end
139
139
  end
@@ -1,14 +1,14 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Churn do
4
-
4
+
5
5
  describe "analyze method" do
6
6
  before :each do
7
7
  MetricFu::Configuration.run {}
8
8
  File.stub!(:directory?).and_return(true)
9
9
  @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
10
10
  end
11
-
11
+
12
12
  it "should be empty on error" do
13
13
  churn = MetricFu::Churn.new
14
14
  churn.instance_variable_set(:@output, "fatal: Not a git repository")
@@ -24,13 +24,13 @@ describe Churn do
24
24
  end
25
25
 
26
26
  end
27
-
27
+
28
28
  describe "to_h method" do
29
29
  before :each do
30
30
  MetricFu::Configuration.run {}
31
31
  File.stub!(:directory?).and_return(true)
32
32
  end
33
-
33
+
34
34
  it "should put the changes into a hash" do
35
35
  churn = MetricFu::Churn.new
36
36
  churn.instance_variable_set(:@churn, {:churn => 'results'})
@@ -1,16 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- describe Flay do
3
+ describe Flay do
4
4
  describe "emit method" do
5
5
  it "should look at the dirs" do
6
6
  MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'], :filetypes => ['rb'] } }
7
7
  File.stub!(:directory?).and_return(true)
8
- @flay = MetricFu::Flay.new('base_dir')
8
+ @flay = MetricFu::Flay.new('base_dir')
9
9
 
10
10
  @flay.should_receive(:`).with("flay app lib")
11
11
  output = @flay.emit
12
12
  end
13
-
13
+
14
14
  it "should limit flay scores by the minimum_score" do
15
15
  MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
16
16
  File.stub!(:directory?).and_return(true)
@@ -20,7 +20,7 @@ describe Flay do
20
20
  output = @flay.emit
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe "analyze method" do
25
25
  before :each do
26
26
  lines = <<-HERE
@@ -42,7 +42,7 @@ Total score (lower is better) = 246
42
42
  @flay = MetricFu::Flay.new('base_dir')
43
43
  @flay.instance_variable_set(:@output, lines)
44
44
  end
45
-
45
+
46
46
  it "should analyze and return matches" do
47
47
  @flay.analyze.should == [ ["Total score (lower is better) = 246"],
48
48
  ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
@@ -55,47 +55,47 @@ Total score (lower is better) = 246
55
55
  "app/controllers/primary_sites_controller.rb:89"] ]
56
56
  end
57
57
  end
58
-
58
+
59
59
  describe "to_h method" do
60
-
60
+
61
61
  before :each do
62
- lines = [ ["Total score (lower is better) = 284"],
63
- ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
64
- "app/controllers/link_targets_controller.rb:57",
65
- "app/controllers/primary_sites_controller.rb:138"],
66
- ["2) Similar code found in :if (mass = 64)",
67
- "app/controllers/primary_sites_controller.rb:75",
68
- "app/controllers/primary_sites_controller.rb:76",
69
- "app/controllers/primary_sites_controller.rb:88",
70
- "app/controllers/primary_sites_controller.rb:89"],
71
- ["3) Similar code found in :defn (mass = 40)",
72
- "app/controllers/link_targets_controller.rb:40",
73
- "app/controllers/primary_sites_controller.rb:98"],
74
- ["4) Similar code found in :defn (mass = 38)",
75
- "app/controllers/link_targets_controller.rb:13",
76
- "app/controllers/primary_sites_controller.rb:50"],
77
- ["5) Similar code found in :defn (mass = 38)",
78
- "app/models/primary_site.rb:104",
79
- "app/models/primary_site.rb:109"],
80
- ["6) Similar code found in :call (mass = 36)",
81
- "app/controllers/bookmarklet_integration_controller.rb:6",
62
+ lines = [ ["Total score (lower is better) = 284"],
63
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
64
+ "app/controllers/link_targets_controller.rb:57",
65
+ "app/controllers/primary_sites_controller.rb:138"],
66
+ ["2) Similar code found in :if (mass = 64)",
67
+ "app/controllers/primary_sites_controller.rb:75",
68
+ "app/controllers/primary_sites_controller.rb:76",
69
+ "app/controllers/primary_sites_controller.rb:88",
70
+ "app/controllers/primary_sites_controller.rb:89"],
71
+ ["3) Similar code found in :defn (mass = 40)",
72
+ "app/controllers/link_targets_controller.rb:40",
73
+ "app/controllers/primary_sites_controller.rb:98"],
74
+ ["4) Similar code found in :defn (mass = 38)",
75
+ "app/controllers/link_targets_controller.rb:13",
76
+ "app/controllers/primary_sites_controller.rb:50"],
77
+ ["5) Similar code found in :defn (mass = 38)",
78
+ "app/models/primary_site.rb:104",
79
+ "app/models/primary_site.rb:109"],
80
+ ["6) Similar code found in :call (mass = 36)",
81
+ "app/controllers/bookmarklet_integration_controller.rb:6",
82
82
  "app/controllers/bookmarklet_integration_controller.rb:17"]]
83
-
83
+
84
84
  MetricFu::Configuration.run {}
85
85
  File.stub!(:directory?).and_return(true)
86
86
  flay = MetricFu::Flay.new('base_dir')
87
87
  flay.instance_variable_set(:@matches, lines)
88
88
  @results = flay.to_h
89
89
  end
90
-
90
+
91
91
  it "should find the total_score" do
92
92
  @results[:flay][:total_score].should == '284'
93
93
  end
94
-
94
+
95
95
  it "should have 6 matches" do
96
96
  @results[:flay][:matches].size.should == 6
97
97
  end
98
-
98
+
99
99
  it "should capture info for match" do
100
100
  @results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
101
101
  @results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
@@ -5,7 +5,7 @@ describe Flog do
5
5
  File.stub!(:directory?).and_return(true)
6
6
  @flog = MetricFu::Flog.new('base_dir')
7
7
  end
8
-
8
+
9
9
  describe "emit method" do
10
10
  it "should look for files and flog them" do
11
11
  Dir.should_receive(:glob).with("lib/**/*.rb").and_return(["found/file.rb"])
@@ -15,41 +15,41 @@ describe Flog do
15
15
  @flog.emit
16
16
  end
17
17
  end
18
-
18
+
19
19
  describe "analyze method" do
20
20
  it "should harvest the flog information and put it into method_containers" do
21
21
  first_full_method_name = "ClassName#first_method_name"
22
22
  second_full_method_name = "ClassName#second_method_name"
23
-
23
+
24
24
  flogger = mock('flogger', :calls => {first_full_method_name => {:branch => 11.1, :puts => 1.1},
25
- second_full_method_name => {:branch => 22.2, :puts => 2.2}},
25
+ second_full_method_name => {:branch => 22.2, :puts => 2.2}},
26
26
  :method_locations => {first_full_method_name => '/file/location.rb:11',
27
- second_full_method_name => '/file/location.rb:22'},
27
+ second_full_method_name => '/file/location.rb:22'},
28
28
  :totals => {first_full_method_name => 11.11,
29
29
  second_full_method_name => 22.22})
30
30
  @flog.instance_variable_set(:@flogger, flogger)
31
31
  @flog.analyze
32
32
  method_containers = @flog.instance_variable_get(:@method_containers)
33
33
  method_containers.size.should == 1
34
-
35
- expected={:methods=>{"ClassName#first_method_name" => { :path=>"/file/location.rb:11",
36
- :score=>11.11,
37
- :operators=>{ :branch=>11.1,
34
+
35
+ expected={:methods=>{"ClassName#first_method_name" => { :path=>"/file/location.rb:11",
36
+ :score=>11.11,
37
+ :operators=>{ :branch=>11.1,
38
38
  :puts=>1.1}},
39
- "ClassName#second_method_name" => {:path=>"/file/location.rb:22",
40
- :score=>22.22,
41
- :operators=>{ :branch=>22.2,
42
- :puts=>2.2}}},
39
+ "ClassName#second_method_name" => {:path=>"/file/location.rb:22",
40
+ :score=>22.22,
41
+ :operators=>{ :branch=>22.2,
42
+ :puts=>2.2}}},
43
43
  :path=>"/file/location.rb",
44
44
  :average_score=>((11.11 + 22.22) / 2.0),
45
45
  :total_score=>33.33,
46
46
  :highest_score=>22.22,
47
47
  :name=>"ClassName"}
48
-
48
+
49
49
  method_containers["ClassName"].to_h.should == expected
50
50
  end
51
51
  end
52
-
52
+
53
53
  describe "to_h method" do
54
54
  it "should make-a nice hash" do
55
55
  flogger = mock('flogger', :total => 111.1, :average => 7.3)
@@ -58,13 +58,13 @@ describe Flog do
58
58
  :ignore_me_2 => mock('container_2', :highest_score => 33.3, :to_h => 'container_2'),
59
59
  :ignore_me_3 => mock('container_3', :highest_score => 22.2, :to_h => 'container_3')}
60
60
  @flog.instance_variable_set(:@method_containers, method_containers)
61
-
61
+
62
62
  expected = {:flog => { :total => 111.1,
63
63
  :average => 7.3,
64
64
  :method_containers => ['container_2', 'container_3', 'container_1']}}
65
-
65
+
66
66
  @flog.to_h.should == expected
67
67
  end
68
-
68
+
69
69
  end
70
70
  end