Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix graph module class methods

  • Loading branch information...
commit eb73abe15127db02885c61575602f30cedf24b78 1 parent eaca8e9
@seancaffery authored
View
4 lib/stepdown/bluff_graph.rb
@@ -4,7 +4,7 @@
module Stepdown
class BluffGraph
- include Stepdown::Graph
+ extend Stepdown::Graph
BLUFF_GRAPH_SIZE = "890x400"
BLUFF_DEFAULT_OPTIONS = <<-EOS
@@ -17,7 +17,7 @@ class BluffGraph
EOS
def self.create_graph
- stats, labels = collect_stats
+ stats, labels = self.collect_stats
label_set = {}
labels.each_with_index do |label, i|
label_set.update({i => label})
View
6 lib/stepdown/graph.rb
@@ -2,7 +2,7 @@
module Stepdown
module Graph
- def self.collect_stats
+ def collect_stats
stats = Hash.new {|hsh, key| hsh[key] = [] }
labels = []
@@ -14,7 +14,7 @@ def self.collect_stats
[stats, labels]
end
- def self.load_stats
+ def load_stats
stat_collection = []
Dir.glob("#{Stepdown.output_directory}/*.yml").sort.each do |file_name|
stats = Hash.new {|hsh, key| hsh[key] = [] }
@@ -33,7 +33,7 @@ def self.load_stats
stat_collection
end
- def self.date_from_file_name(file_name)
+ def date_from_file_name(file_name)
label_date = Date.strptime(file_name.match(/(\d+)/)[1], "%Y%m%d")
"#{label_date.day} / #{label_date.month}"
end
View
47 spec/lib/stepdown/graph_spec.rb
@@ -3,20 +3,28 @@
describe Stepdown::Graph do
+ class DummyGraph
+ end
+
+ before :each do
+ @fixture = DummyGraph.new
+ @fixture.extend(Stepdown::Graph)
+ end
+
describe "collecting stats" do
before :each do
stats = [{:no_scen => 10, :unused => 2, :label => "label 1"},
{:no_scen => 20, :unused => 3, :label => "label 2"}]
- Stepdown::Graph.stub!(:load_stats).and_return(stats)
+ @fixture.stub!(:load_stats).and_return(stats)
end
it "should return the labels associated with a stat set" do
- Stepdown::Graph.collect_stats[1].should == ["label 1", "label 2"]
+ @fixture.collect_stats[1].should == ["label 1", "label 2"]
end
it "should break collect group stats based on given keys" do
- Stepdown::Graph.collect_stats[0].should == {:no_scen=>[10, 20],
+ @fixture.collect_stats[0].should == {:no_scen=>[10, 20],
:unused=>[2, 3],
:label=>["label 1", "label 2"]}
end
@@ -25,26 +33,27 @@
describe "creating a label from a file name" do
it "should return day/month" do
- Stepdown::Graph.date_from_file_name("20110512.yml").should == "12 / 5"
+ @fixture.date_from_file_name("20110512.yml").should == "12 / 5"
end
end
describe "loading stat files" do
- Stepdown.output_directory = File.dirname(__FILE__) + '/../../fixtures'
- stats = Stepdown::Graph.load_stats
- stats.should == [{:number_scenarios=>[685],
- :total_steps=>[531],
- :steps_per_scenario=>["12.91"],
- :label=>"11 / 6",
- :unused_steps=>[123]},
- {:number_scenarios=>[690],
- :total_steps=>[533],
- :steps_per_scenario=>["12.50"],
- :label=>"12 / 6",
- :unused_steps=>[123]}]
-
- stats.length.should == 2
+ it "should load correctly" do
+ Stepdown.output_directory = File.dirname(__FILE__) + '/../../fixtures'
+ stats = @fixture.load_stats
+ stats.should == [{:number_scenarios=>[685],
+ :total_steps=>[531],
+ :steps_per_scenario=>["12.91"],
+ :label=>"11 / 6",
+ :unused_steps=>[123]},
+ {:number_scenarios=>[690],
+ :total_steps=>[533],
+ :steps_per_scenario=>["12.50"],
+ :label=>"12 / 6",
+ :unused_steps=>[123]}]
+
+ stats.length.should == 2
+ end
end
-
end

0 comments on commit eb73abe

Please sign in to comment.
Something went wrong with that request. Please try again.