X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Faggregate%2Fbase_spec.rb;fp=spec%2Funit%2Faggregate%2Fbase_spec.rb;h=29e0dcc6b092334898c2be0677b8df7ead871cc8;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/aggregate/base_spec.rb b/spec/unit/aggregate/base_spec.rb new file mode 100644 index 0000000..29e0dcc --- /dev/null +++ b/spec/unit/aggregate/base_spec.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + class Aggregate + describe Base do + describe "#initialize" do + it "should set the correct instance variables and call the startup hook" do + Base.any_instance.expects(:startup_hook).once + base = Base.new("value", [], "%s%s", "rspec") + base.name.should == "MCollective::Aggregate::Base" + base.output_name.should == "value" + base.aggregate_format.should == "%s%s" + base.action.should == "rspec" + end + end + + describe "#startup_hook and #process_result" do + it "should raise an exception for an unimplemented startup_hook method " do + expect{ + base = Base.new("value", [], "", "rspec") + }.to raise_error(RuntimeError, "'startup_hook' method of function class MCollective::Aggregate::Base has not yet been implemented") + end + + it "should raise an exception for an unimplemented process_result method" do + Base.any_instance.stubs(:startup_hook) + base = Base.new("value", [], "", "rspec") + expect{ + base.process_result + }.to raise_error(RuntimeError,"'process_result' method of function class MCollective::Aggregate::Base has not yet been implemented") + end + end + + describe "summarize" do + it "should raise and exception if the result type has not been set" do + Base.any_instance.stubs(:startup_hook) + base = Base.new("value", [], "", "rspec") + expect{ + base.summarize + }.to raise_error(RuntimeError, "Result type is not set while trying to summarize aggregate function results") + end + + it "should return the correct result class if result type has been set" do + result_object = mock + result_object.stubs(:new) + + Base.any_instance.stubs(:startup_hook) + base = Base.new("value", [], "", "rspec") + base.result[:type] = :result_type + base.expects(:result_class).with(:result_type).returns(result_object) + base.summarize + end + end + end + end +end