Skip to content

Commit

Permalink
Rails Best Practices grapher now silently ignore dates with missing m…
Browse files Browse the repository at this point in the history
…etric data
  • Loading branch information
cgriego committed Jul 25, 2010
1 parent 275c68f commit 2b58286
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
18 changes: 6 additions & 12 deletions lib/graphs/rails_best_practices_grapher.rb
@@ -1,25 +1,19 @@
module MetricFu

class RailsBestPracticesGrapher < Grapher

attr_accessor :rails_best_practices_count, :labels

def initialize
super
@rails_best_practices_count = []
@labels = {}
end

def get_metrics(metrics, date)
if metrics[:rails_best_practices] && metrics[:rails_best_practices][:problems]
size = metrics[:rails_best_practices][:problems].size
else
size = 0
if metrics && metrics[:rails_best_practices]
size = (metrics[:rails_best_practices][:problems] || []).size
@rails_best_practices_count.push(size)
@labels.update( { @labels.size => date })
end
@rails_best_practices_count.push(size)
@labels.update( { @labels.size => date })
end

end

end
45 changes: 31 additions & 14 deletions spec/graphs/rails_best_practices_grapher_spec.rb
Expand Up @@ -19,25 +19,42 @@
end

describe "responding to #get_metrics" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "01022003"
end
context "when metrics were not generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "metric_missing.yml")))
@date = "01022003"
end

it "should push 100 to rails_best_practices_count" do
@stats_grapher.rails_best_practices_count.should_receive(:push).with(2)
@stats_grapher.get_metrics(@metrics, @date)
end
it "should not push to rails_best_practices_count" do
@stats_grapher.rails_best_practices_count.should_not_receive(:push)
@stats_grapher.get_metrics(@metrics, @date)
end

it "should update labels with the date" do
@stats_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
@stats_grapher.get_metrics(@metrics, @date)
it "should not update labels with the date" do
@stats_grapher.labels.should_not_receive(:update)
@stats_grapher.get_metrics(@metrics, @date)
end
end

context "when no metrics have been collected" do
it "should push 0 to rails_best_practices_count" do
context "when metrics have been generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "01022003"
end

it "should push to rails_best_practices_count" do
@stats_grapher.rails_best_practices_count.should_receive(:push).with(2)
@stats_grapher.get_metrics(@metrics, @date)
end

it "should push 0 to rails_best_practices_count when no problems were found" do
@stats_grapher.rails_best_practices_count.should_receive(:push).with(0)
@stats_grapher.get_metrics({}, @date)
@stats_grapher.get_metrics({ :rails_best_practices => {} }, @date)
end

it "should update labels with the date" do
@stats_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
@stats_grapher.get_metrics(@metrics, @date)
end
end
end
Expand Down

0 comments on commit 2b58286

Please sign in to comment.