29e0dcc6b092334898c2be0677b8df7ead871cc8
[packages/precise/mcollective.git] / spec / unit / aggregate / base_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 module MCollective
6   class Aggregate
7     describe Base do
8       describe "#initialize" do
9         it "should set the correct instance variables and call the startup hook" do
10           Base.any_instance.expects(:startup_hook).once
11           base = Base.new("value", [], "%s%s", "rspec")
12           base.name.should == "MCollective::Aggregate::Base"
13           base.output_name.should == "value"
14           base.aggregate_format.should == "%s%s"
15           base.action.should == "rspec"
16         end
17       end
18
19       describe "#startup_hook and #process_result" do
20         it "should raise an exception for an unimplemented startup_hook method " do
21           expect{
22             base = Base.new("value", [], "", "rspec")
23           }.to raise_error(RuntimeError, "'startup_hook' method of function class MCollective::Aggregate::Base has not yet been implemented")
24         end
25
26         it "should raise an exception for an unimplemented process_result method" do
27           Base.any_instance.stubs(:startup_hook)
28           base = Base.new("value", [], "", "rspec")
29           expect{
30             base.process_result
31           }.to raise_error(RuntimeError,"'process_result' method of function class MCollective::Aggregate::Base has not yet been implemented")
32         end
33       end
34
35       describe "summarize" do
36         it "should raise and exception if the result type has not been set" do
37           Base.any_instance.stubs(:startup_hook)
38           base = Base.new("value", [], "", "rspec")
39           expect{
40             base.summarize
41           }.to raise_error(RuntimeError, "Result type is not set while trying to summarize aggregate function results")
42         end
43
44         it "should return the correct result class if result type has been set" do
45           result_object = mock
46           result_object.stubs(:new)
47
48           Base.any_instance.stubs(:startup_hook)
49           base = Base.new("value", [], "", "rspec")
50           base.result[:type] = :result_type
51           base.expects(:result_class).with(:result_type).returns(result_object)
52           base.summarize
53         end
54       end
55     end
56   end
57 end