X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fdata%2Fresult_spec.rb;fp=spec%2Funit%2Fdata%2Fresult_spec.rb;h=9ea22cdddab826be5954a205ce1b868d1707358e;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/data/result_spec.rb b/spec/unit/data/result_spec.rb new file mode 100644 index 0000000..9ea22cd --- /dev/null +++ b/spec/unit/data/result_spec.rb @@ -0,0 +1,72 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module Data + describe Result do + before(:each) do + @result = Result.new + end + + describe "#[]=" do + it "should only allow trusted types of data to be saved" do + expect { @result["rspec"] = Time.now }.to raise_error + @result["rspec"] = 1 + @result["rspec"] = 1.1 + @result["rspec"] = "rspec" + @result["rspec"] = true + @result["rspec"] = false + end + + it "should set the correct value" do + @result["rspec"] = "rspec value" + @result.instance_variable_get("@data").should == {:rspec => "rspec value"} + end + + it "should only allow valid data types" do + expect { @result["rspec"] = Time.now }.to raise_error(/Can only store .+ data but got Time for key rspec/) + end + end + + describe "#include" do + it "should return the correct list of keys" do + @result["x"] = "1" + @result[:y] = "2" + @result.keys.sort.should == [:x, :y] + end + end + + describe "#include?" do + it "should correctly report that a key is present or absent" do + @result.include?("rspec").should == false + @result.include?(:rspec).should == false + @result["rspec"] = "rspec" + @result.include?("rspec").should == true + @result.include?(:rspec).should == true + end + end + + describe "#[]" do + it "should retrieve the correct information" do + @result["rspec"].should == nil + @result[:rspec].should == nil + @result["rspec"] = "rspec value" + @result["rspec"].should == "rspec value" + @result[:rspec].should == "rspec value" + end + end + + describe "#method_missing" do + it "should raise the correct exception for unknown keys" do + expect { @result.nosuchdata }.to raise_error(NoMethodError) + end + + it "should retrieve the correct data" do + @result["rspec"] = "rspec value" + @result.rspec.should == "rspec value" + end + end + end + end +end