X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Frpc%2Fresult_spec.rb;fp=spec%2Funit%2Frpc%2Fresult_spec.rb;h=22c0b4140f25a430e7d9557b0a0dc309853ce482;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/rpc/result_spec.rb b/spec/unit/rpc/result_spec.rb new file mode 100755 index 0000000..22c0b41 --- /dev/null +++ b/spec/unit/rpc/result_spec.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module RPC + describe Result do + before(:each) do + @result = Result.new("tester", "test", {:foo => "bar", :bar => "baz"}) + end + + it "should include Enumerable" do + Result.ancestors.include?(Enumerable).should == true + end + + describe "#initialize" do + it "should set the agent" do + @result.agent.should == "tester" + end + + it "should set the action" do + @result.action.should == "test" + end + + it "should set the results" do + @result.results.should == {:foo => "bar", :bar => "baz"} + end + end + + describe "#[]" do + it "should access the results hash and return correct data" do + @result[:foo].should == "bar" + @result[:bar].should == "baz" + end + end + + describe "#[]=" do + it "should set the correct result data" do + @result[:meh] = "blah" + + @result[:foo].should == "bar" + @result[:bar].should == "baz" + @result[:meh].should == "blah" + end + end + + describe "#fetch" do + it "should fetch data with the correct default behavior" do + @result.fetch(:foo, "default").should == "bar" + @result.fetch(:rspec, "default").should == "default" + end + end + + describe "#each" do + it "should itterate all the pairs" do + data = {} + + @result.each {|k,v| data[k] = v} + + data[:foo].should == "bar" + data[:bar].should == "baz" + end + end + + describe "#to_json" do + it "should correctly json encode teh data" do + result = Result.new("tester", "test", {:statuscode => 0, :statusmsg => "OK", :sender => "rspec", :data => {:foo => "bar", :bar => "baz"}}) + JSON.load(result.to_json).should == {"agent" => "tester", "action" => "test", "statuscode" => 0, "statusmsg" => "OK", "sender" => "rspec", "data" => {"foo" => "bar", "bar" => "baz"}} + end + end + end + end +end