1047d8e8ceef475b0e8c23d63e6bf9d479b89a44
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / aggregate / average_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4 require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/aggregate/average.rb"
5
6 module MCollective
7   class Aggregate
8     describe Average do
9       describe "#startup_hook" do
10         it "should set the correct result hash" do
11           result = Average.new(:test, [], "%d", :test_action)
12           result.result.should == {:value => 0, :type => :numeric, :output => :test}
13           result.aggregate_format.should == "%d"
14         end
15
16         it "should set a defauly aggregate_format if one isn't defined" do
17           result = Average.new(:test, [], nil, :test_action)
18           result.aggregate_format.should == "Average of test: %f"
19         end
20       end
21
22       describe "#process_result" do
23         it "should add the reply value to the result hash" do
24           average = Average.new([:test], [], "%d", :test_action)
25           average.process_result(1, {:test => 1})
26           average.result[:value].should == 1
27         end
28       end
29
30       describe "#summarize" do
31         it "should calculate the average and return a result class" do
32           result_obj = mock
33           result_obj.stubs(:new).returns(:success)
34
35           average = Average.new([:test], [], "%d", :test_action)
36           average.process_result(10, {:test => 10})
37           average.process_result(20, {:test => 20})
38           average.stubs(:result_class).returns(result_obj)
39           average.summarize.should == :success
40           average.result[:value].should == 15
41         end
42       end
43     end
44   end
45 end