jscruggs-metric_fu 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/HISTORY +13 -0
  2. data/README +1 -1
  3. data/Rakefile +1 -29
  4. data/TODO +1 -2
  5. data/lib/base/base_template.rb +18 -6
  6. data/lib/base/configuration.rb +22 -2
  7. data/lib/base/generator.rb +15 -2
  8. data/lib/base/graph.rb +37 -0
  9. data/lib/generators/churn.rb +6 -1
  10. data/lib/generators/flay.rb +5 -0
  11. data/lib/generators/flog.rb +6 -0
  12. data/lib/generators/rcov.rb +10 -0
  13. data/lib/generators/reek.rb +5 -0
  14. data/lib/generators/roodi.rb +7 -0
  15. data/lib/generators/saikuro.rb +184 -187
  16. data/lib/graphs/flay_grapher.rb +34 -0
  17. data/lib/graphs/flog_grapher.rb +37 -0
  18. data/lib/graphs/rcov_grapher.rb +34 -0
  19. data/lib/graphs/reek_grapher.rb +44 -0
  20. data/lib/graphs/roodi_grapher.rb +34 -0
  21. data/lib/metric_fu.rb +4 -0
  22. data/lib/templates/awesome/awesome_template.rb +30 -0
  23. data/lib/templates/awesome/churn.html.erb +19 -0
  24. data/lib/templates/awesome/default.css +75 -0
  25. data/lib/templates/awesome/flay.html.erb +27 -0
  26. data/lib/templates/awesome/flog.html.erb +46 -0
  27. data/lib/templates/awesome/index.html.erb +28 -0
  28. data/lib/templates/awesome/layout.html.erb +27 -0
  29. data/lib/templates/awesome/rcov.html.erb +36 -0
  30. data/lib/templates/awesome/reek.html.erb +34 -0
  31. data/lib/templates/awesome/roodi.html.erb +21 -0
  32. data/lib/templates/awesome/saikuro.html.erb +71 -0
  33. data/lib/templates/awesome/stats.html.erb +41 -0
  34. data/lib/templates/standard/churn.html.erb +1 -0
  35. data/lib/templates/standard/flay.html.erb +1 -0
  36. data/lib/templates/standard/flog.html.erb +3 -2
  37. data/lib/templates/standard/rcov.html.erb +5 -4
  38. data/lib/templates/standard/reek.html.erb +1 -0
  39. data/lib/templates/standard/roodi.html.erb +1 -0
  40. data/lib/templates/standard/saikuro.html.erb +1 -0
  41. data/lib/templates/standard/stats.html.erb +1 -0
  42. data/spec/base/base_template_spec.rb +35 -14
  43. data/spec/base/configuration_spec.rb +4 -4
  44. data/spec/base/generator_spec.rb +23 -1
  45. data/spec/base/md5_tracker_spec.rb +1 -1
  46. data/spec/base/report_spec.rb +1 -1
  47. data/spec/generators/churn_spec.rb +8 -8
  48. data/spec/generators/flay_spec.rb +4 -1
  49. data/spec/generators/flog_spec.rb +10 -2
  50. data/spec/generators/reek_spec.rb +2 -1
  51. data/spec/generators/saikuro_spec.rb +22 -17
  52. data/spec/generators/stats_spec.rb +1 -1
  53. data/tasks/metric_fu.rake +8 -1
  54. data/vendor/_fonts/monaco.ttf +0 -0
  55. metadata +30 -20
  56. data/tasks/railroad.rake +0 -39
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper.rb"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu::Generator do
4
4
 
@@ -154,6 +154,28 @@ describe MetricFu::Generator do
154
154
  @concrete_class.should_receive(:to_h)
155
155
  @concrete_class.generate_report
156
156
  end
157
+
158
+ it "should raise error if the concrete class is missing a required dependency" do
159
+ concrete_class_with_missing_gem = Class.new(MetricFu::Generator) do
160
+ def self.verify_dependencies!
161
+ raise 'gem install something # if you want these tasks'
162
+ end
163
+ end
164
+ lambda { concrete_class_with_missing_gem.generate_report }.should raise_error("gem install something # if you want these tasks")
165
+ end
157
166
 
158
167
  end
168
+
169
+ describe "instantiation" do
170
+ it "should fail is dependencies not verified" do
171
+ ConcreteClass.should_receive(:verify_dependencies!).and_raise("Missing a required gem. Please 'gem install something'")
172
+ lambda { ConcreteClass.new() }.should raise_error("Missing a required gem. Please 'gem install something'")
173
+ end
174
+
175
+ it "should succeed when dependencies verified" do
176
+ ConcreteClass.should_receive(:verify_dependencies!).and_return(true)
177
+ ConcreteClass.new()
178
+ end
179
+ end
180
+
159
181
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu::MD5Tracker do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper.rb"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Churn do
4
4
  describe "initialize" do
@@ -8,20 +8,20 @@ describe Churn do
8
8
  end
9
9
 
10
10
  it "should setup git if .git exits" do
11
- File.should_receive(:exist?).with(".git").and_return(true)
11
+ MetricFu::Churn.should_receive(:system).and_return(true)
12
12
  Churn::Git.should_receive(:new)
13
13
  MetricFu::Churn.new
14
14
  end
15
15
 
16
16
  it "should setup git if .svn exits" do
17
- File.should_receive(:exist?).with(".git").and_return(false)
17
+ MetricFu::Churn.should_receive(:system).and_return(false)
18
18
  File.should_receive(:exist?).with(".svn").and_return(true)
19
19
  Churn::Svn.should_receive(:new)
20
20
  MetricFu::Churn.new()
21
21
  end
22
22
 
23
23
  it "should raise an error if not .svn or .git" do
24
- File.stub!(:exist?).and_return(false)
24
+ MetricFu::Churn.should_receive(:system).and_return(false)
25
25
  lambda{MetricFu::Churn.new()}.should raise_error(Exception)
26
26
  end
27
27
  end
@@ -30,7 +30,7 @@ describe Churn do
30
30
  before :each do
31
31
  MetricFu::Configuration.run {|config| config.churn = {:minimum_churn_count => 2} }
32
32
  File.stub!(:directory?).and_return(true)
33
- File.should_receive(:exist?).with(".git").and_return(true)
33
+ MetricFu::Churn.should_receive(:system).and_return(true)
34
34
  @git = Churn::Git.new
35
35
  Churn::Git.should_receive(:new).and_return(@git)
36
36
  @lines = <<-HERE.gsub(/^\s*/, "")
@@ -73,7 +73,7 @@ describe Churn do
73
73
  before :each do
74
74
  MetricFu::Configuration.run{|config| config.churn = {:minimum_churn_count => 2} }
75
75
  File.stub!(:directory?).and_return(true)
76
- File.should_receive(:exist?).with(".git").and_return(false)
76
+ MetricFu::Churn.should_receive(:system).and_return(false)
77
77
  File.should_receive(:exist?).with(".svn").and_return(true)
78
78
  @svn = Churn::Svn.new
79
79
  Churn::Svn.should_receive(:new).and_return(@svn)
@@ -120,7 +120,7 @@ describe Churn do
120
120
  before :each do
121
121
  MetricFu::Configuration.run {}
122
122
  File.stub!(:directory?).and_return(true)
123
- File.should_receive(:exist?).with(".git").and_return(true)
123
+ MetricFu::Churn.should_receive(:system).and_return(true)
124
124
  @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
125
125
  end
126
126
 
@@ -139,7 +139,7 @@ describe Churn do
139
139
  before :each do
140
140
  MetricFu::Configuration.run {}
141
141
  File.stub!(:directory?).and_return(true)
142
- File.should_receive(:exist?).with(".git").and_return(true)
142
+ MetricFu::Churn.should_receive(:system).and_return(true)
143
143
  end
144
144
 
145
145
  it "should put the changes into a hash" do
@@ -1,6 +1,9 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Flay do
4
+ before :each do
5
+ MetricFu::Flay.stub!(:verify_dependencies!).and_return(true)
6
+ end
4
7
  describe "emit method" do
5
8
  before :each do
6
9
  MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
  describe Flog do
3
3
  before :each do
4
4
  @text = <<-HERE
@@ -123,6 +123,7 @@ describe Flog do
123
123
  1.2: assignment
124
124
  1.2: all
125
125
  HERE
126
+ MetricFu::Flog.stub!(:verify_dependencies!).and_return(true)
126
127
  end
127
128
 
128
129
  describe "parse method" do
@@ -168,6 +169,13 @@ describe Flog do
168
169
  flog_page = flog.parse(text)
169
170
  flog_page.scanned_methods.first.name.should == "SomeNamespace::UsersController#create"
170
171
  end
172
+
173
+ it "should parse empty flog files" do
174
+ text = ""
175
+ flog = MetricFu::Flog.new('base_dir')
176
+ flog_page = flog.parse(text)
177
+ flog_page.should be_nil
178
+ end
171
179
  end
172
180
 
173
181
  describe "to_h function" do
@@ -197,4 +205,4 @@ describe Flog do
197
205
  @flog_hash[:flog][:pages].first[:path].should == "/app/controllers/user_controller.rb"
198
206
  end
199
207
  end
200
- end
208
+ end
@@ -1,8 +1,9 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Reek do
4
4
  describe "analyze method" do
5
5
  before :each do
6
+ MetricFu::Reek.stub!(:verify_dependencies!).and_return(true)
6
7
  @lines = <<-HERE
7
8
  "app/controllers/activity_reports_controller.rb" -- 4 warnings:
8
9
  ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
3
  describe Saikuro do
4
4
  describe "to_h method" do
5
5
  before :all do
@@ -10,44 +10,49 @@ describe Saikuro do
10
10
  saikuro.analyze
11
11
  @output = saikuro.to_h
12
12
  end
13
-
13
+
14
14
  it "should find the filename of a file" do
15
15
  @output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
16
16
  end
17
-
17
+
18
18
  it "should find the name of the classes" do
19
19
  @output[:saikuro][:classes].first[:name].should == "UsersController"
20
20
  @output[:saikuro][:classes][1][:name].should == "SessionsController"
21
21
  end
22
-
22
+
23
23
  it "should put the most complex method first" do
24
24
  @output[:saikuro][:methods].first[:name].should == "UsersController#create"
25
25
  @output[:saikuro][:methods].first[:complexity].should == 4
26
26
  end
27
-
27
+
28
28
  it "should find the complexity of a method" do
29
29
  @output[:saikuro][:methods].first[:complexity].should == 4
30
30
  end
31
-
31
+
32
32
  it "should find the lines of a method" do
33
33
  @output[:saikuro][:methods].first[:lines].should == 15
34
34
  end
35
35
  end
36
-
37
- describe "emit method" do
36
+
37
+ describe "format_directories method" do
38
38
  it "should format the directories" do
39
39
  MetricFu::Configuration.run {}
40
40
  File.stub!(:directory?).and_return(true)
41
41
  saikuro = MetricFu::Saikuro.new
42
-
42
+
43
43
  MetricFu.saikuro[:input_directory] = ["app", "lib"]
44
-
45
- File.stub!(:dirname).and_return('..')
46
- File.stub!(:expand_path)
47
-
48
- saikuro.should_receive(:sh).with(/"app \| lib"/)
49
-
50
- saikuro.emit
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
51
56
  end
52
57
  end
53
58
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Stats do
4
4
  describe "emit method" do
@@ -6,8 +6,15 @@ namespace :metrics do
6
6
  MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
7
7
  MetricFu.report.save_output(MetricFu.report.to_yaml,
8
8
  MetricFu.base_directory,
9
- 'report.yml')
9
+ "report.yml")
10
+ MetricFu.report.save_output(MetricFu.report.to_yaml,
11
+ MetricFu.data_directory,
12
+ "#{Time.now.strftime("%Y%m%d")}.yml")
10
13
  MetricFu.report.save_templatized_report
14
+
15
+ MetricFu.graphs.each {|graph| MetricFu.graph.add(graph) }
16
+ MetricFu.graph.generate
17
+
11
18
  if MetricFu.report.open_in_browser?
12
19
  MetricFu.report.show_in_browser(MetricFu.output_directory)
13
20
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jscruggs-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
@@ -9,11 +9,13 @@ authors:
9
9
  - Andre Arko
10
10
  - Petrik de Heus
11
11
  - Grant McInnes
12
+ - Nick Quaranto
13
+ - "\xC3\x89douard Bri\xC3\xA8re"
12
14
  autorequire:
13
15
  bindir: bin
14
16
  cert_chain: []
15
17
 
16
- date: 2009-04-08 00:00:00 -07:00
18
+ date: 2009-05-16 00:00:00 -07:00
17
19
  default_executable:
18
20
  dependencies:
19
21
  - !ruby/object:Gem::Dependency
@@ -37,44 +39,34 @@ dependencies:
37
39
  version: 2.1.0
38
40
  version:
39
41
  - !ruby/object:Gem::Dependency
40
- name: rcov
41
- type: :runtime
42
- version_requirement:
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">"
46
- - !ruby/object:Gem::Version
47
- version: 0.8.1
48
- version:
49
- - !ruby/object:Gem::Dependency
50
- name: reek
42
+ name: relevance-rcov
51
43
  type: :runtime
52
44
  version_requirement:
53
45
  version_requirements: !ruby/object:Gem::Requirement
54
46
  requirements:
55
47
  - - ">="
56
48
  - !ruby/object:Gem::Version
57
- version: 1.0.0
49
+ version: 0.8.3.3
58
50
  version:
59
51
  - !ruby/object:Gem::Dependency
60
- name: roodi
52
+ name: mojombo-chronic
61
53
  type: :runtime
62
54
  version_requirement:
63
55
  version_requirements: !ruby/object:Gem::Requirement
64
56
  requirements:
65
57
  - - ">="
66
58
  - !ruby/object:Gem::Version
67
- version: 1.3.5
59
+ version: 0.3.0
68
60
  version:
69
61
  - !ruby/object:Gem::Dependency
70
- name: chronic
62
+ name: topfunky-gruff
71
63
  type: :runtime
72
64
  version_requirement:
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
66
  requirements:
75
67
  - - ">="
76
68
  - !ruby/object:Gem::Version
77
- version: 0.2.3
69
+ version: 0.3.5
78
70
  version:
79
71
  description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, Reek, Roodi and Rails' stats task
80
72
  email: jake.scruggs@gmail.com
@@ -95,6 +87,7 @@ files:
95
87
  - lib/base/base_template.rb
96
88
  - lib/base/configuration.rb
97
89
  - lib/base/generator.rb
90
+ - lib/base/graph.rb
98
91
  - lib/base/md5_tracker.rb
99
92
  - lib/base/report.rb
100
93
  - lib/generators/churn.rb
@@ -105,7 +98,24 @@ files:
105
98
  - lib/generators/roodi.rb
106
99
  - lib/generators/saikuro.rb
107
100
  - lib/generators/stats.rb
101
+ - lib/graphs/flay_grapher.rb
102
+ - lib/graphs/flog_grapher.rb
103
+ - lib/graphs/rcov_grapher.rb
104
+ - lib/graphs/reek_grapher.rb
105
+ - lib/graphs/roodi_grapher.rb
108
106
  - lib/metric_fu.rb
107
+ - lib/templates/awesome/awesome_template.rb
108
+ - lib/templates/awesome/churn.html.erb
109
+ - lib/templates/awesome/default.css
110
+ - lib/templates/awesome/flay.html.erb
111
+ - lib/templates/awesome/flog.html.erb
112
+ - lib/templates/awesome/index.html.erb
113
+ - lib/templates/awesome/layout.html.erb
114
+ - lib/templates/awesome/rcov.html.erb
115
+ - lib/templates/awesome/reek.html.erb
116
+ - lib/templates/awesome/roodi.html.erb
117
+ - lib/templates/awesome/saikuro.html.erb
118
+ - lib/templates/awesome/stats.html.erb
109
119
  - lib/templates/standard/churn.html.erb
110
120
  - lib/templates/standard/default.css
111
121
  - lib/templates/standard/flay.html.erb
@@ -118,7 +128,7 @@ files:
118
128
  - lib/templates/standard/standard_template.rb
119
129
  - lib/templates/standard/stats.html.erb
120
130
  - tasks/metric_fu.rake
121
- - tasks/railroad.rake
131
+ - vendor/_fonts/monaco.ttf
122
132
  - vendor/saikuro/saikuro.rb
123
133
  - Manifest.txt
124
134
  has_rdoc: true
@@ -147,7 +157,7 @@ rubyforge_project:
147
157
  rubygems_version: 1.2.0
148
158
  signing_key:
149
159
  specification_version: 2
150
- summary: A fistful of code metrics
160
+ summary: A fistful of code metrics, with awesome templates and graphs
151
161
  test_files:
152
162
  - spec/base/base_template_spec.rb
153
163
  - spec/base/configuration_spec.rb
@@ -1,39 +0,0 @@
1
- namespace :metrics do
2
-
3
- RAILROAD_DIR = File.join(MetricFu::BASE_DIRECTORY, 'railroad')
4
- RAILROAD_FILE = File.join(RAILROAD_DIR, 'index.html')
5
-
6
- task :railroad => ['railroad:all'] do
7
- end
8
-
9
- namespace :railroad do
10
-
11
- desc "Create all railroad reports"
12
- task :all => [:models, :controllers, :aasm] do
13
- #system("open #{RAILROAD_INDEX}") if PLATFORM['darwin']
14
- end
15
-
16
- desc "Create a railroad models report"
17
- task :models do
18
- #mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
19
- `railroad -M -a -m -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'model-diagram.png')}`
20
- #`echo "<a href=\"railroad/models.png\">Model diagram</a><br />" >> #{RAILROAD_FILE}`
21
- end
22
-
23
- desc "Create a railroad controllers report"
24
- task :controllers do
25
- #mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
26
- `railroad -C -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'controller-diagram.png')}`
27
- #`echo "<a href=\"railroad/controllers.png\">Controller diagram</a><br />" >> #{RAILROAD_FILE}`
28
- end
29
-
30
- desc "Create a railroad acts_as_state_machine report"
31
- task :aasm do
32
- #mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
33
- `railroad -A -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'aasm-diagram.png')}`
34
- #`echo "<a href=\"railroad/aasm.png\">State machine diagram</a><br />" >> #{RAILROAD_FILE}`
35
- end
36
-
37
- end
38
-
39
- end