Permalink
Browse files

Merge branch 'master' of https://github.com/joshuacronemeyer/metric_fu

…into joshuacronemeyer-master

* 'master' of https://github.com/joshuacronemeyer/metric_fu:
  Fixed a bug reported by Andrew Davis on the mailing list where configuring the data directory causes dates to be 0/0

Conflicts:
	TODO
	lib/base/graph.rb
	spec/base/graph_spec.rb
  • Loading branch information...
2 parents c6fdeaf + 6002d56 commit 995abe2649d2ef8eff9e0f8a3eff7cc20a4fc0f4 @jscruggs committed Nov 13, 2010
Showing with 44 additions and 4 deletions.
  1. +2 −0 TODO
  2. +9 −4 lib/base/graph.rb
  3. +33 −0 spec/base/graph_spec.rb
View
2 TODO
@@ -2,3 +2,5 @@
* Color code flog results with scale from: http://jakescruggs.blogspot.com/2008/08/whats-good-flog-score.html
* Make running metric_fu on metric_fu less embarrassing
+* Load all gems at config time so you fail fast if one is missing
+
View
@@ -23,17 +23,22 @@ def generate
puts "Generating graphs"
Dir[File.join(MetricFu.data_directory, '*.yml')].sort.each do |metric_file|
puts "Generating graphs for #{metric_file}"
- date = metric_file.split('/')[3].split('.')[0]
- y, m, d = date[0..3].to_i, date[4..5].to_i, date[6..7].to_i
+ date_parts = year_month_day_from_filename(metric_file)
metrics = YAML::load(File.open(metric_file))
self.clazz.each do |grapher|
- grapher.get_metrics(metrics, "#{m}/#{d}")
+ grapher.get_metrics(metrics, "#{date_parts[:m]}/#{date_parts[:d]}")
end
end
self.clazz.each do |grapher|
grapher.graph!
end
end
+
+ private
+ def year_month_day_from_filename(path_to_file_with_date)
+ date = path_to_file_with_date.match(/\/(\d+).yml$/)[1]
+ {:y => date[0..3].to_i, :m => date[4..5].to_i, :d => date[6..7].to_i}
+ end
end
-end
+end
View
@@ -21,4 +21,37 @@
@graph.add("rcov", 'gchart')
end
end
+
+ describe "responding to #add with gchart enabled" do
+ it 'should instantiate a grapher and push it to clazz' do
+ @graph.clazz.should_receive(:push).with(an_instance_of(RcovGchartGrapher))
+ @graph.add("rcov", 'gchart')
+ end
+ end
+
+ describe "setting the date on the graph" do
+ it "should set the date once for one data point" do
+ Dir.should_receive(:[]).and_return(["metric_fu/tmp/_data/20101105.yml"])
+ File.should_receive(:join)
+ File.should_receive(:open).and_return("Metrics")
+ mock_grapher = stub
+ mock_grapher.should_receive(:get_metrics).with("Metrics", "11/5")
+ mock_grapher.should_receive(:graph!)
+
+ @graph.clazz = [mock_grapher]
+ @graph.generate
+ end
+
+ it "should set the date when the data directory isn't in the default place" do
+ Dir.should_receive(:[]).and_return(["/some/kind/of/weird/directory/somebody/configured/_data/20101105.yml"])
+ File.should_receive(:join)
+ File.should_receive(:open).and_return("Metrics")
+ mock_grapher = stub
+ mock_grapher.should_receive(:get_metrics).with("Metrics", "11/5")
+ mock_grapher.should_receive(:graph!)
+
+ @graph.clazz = [mock_grapher]
+ @graph.generate
+ end
+ end
end

0 comments on commit 995abe2

Please sign in to comment.