9 Cache.delete!(:ddl) rescue nil
12 ddl.stubs(:action_interface).returns({:output => {}})
13 ddl.stubs(:actions).returns(["rspec"])
14 ddl.stubs(:pluginname).returns("rspec")
16 @reply = Reply.new("rspec", ddl)
19 describe "#initialize" do
20 it "should set an empty data hash" do
21 @reply.data.should == {}
24 it "should set statuscode to zero" do
25 @reply.statuscode.should == 0
28 it "should set statusmsg to OK" do
29 @reply.statusmsg.should == "OK"
33 describe "#initialize_data" do
36 @ddl = DDL.new("rspec", :agent, false)
39 it "should set defaults correctly" do
40 @ddl.action :rspec, :description => "testing rspec" do
41 @ddl.output :one, :description => "rspec test", :display_as => "rspec", :default => "default"
42 @ddl.output :three, :description => "rspec test", :display_as => "rspec", :default => []
43 @ddl.output :two, :description => "rspec test", :display_as => "rspec"
46 reply = Reply.new(:rspec, @ddl)
47 reply.data.should == {:one => "default", :two => nil, :three => []}
50 it "should detect missing actions" do
51 reply = Reply.new(:rspec, @ddl)
52 expect { reply.initialize_data }.to raise_error(/No action 'rspec' defined/)
57 it "should set statusmsg" do
59 @reply.statusmsg.should == "foo"
62 it "should set statuscode to 1 by default" do
64 @reply.statuscode.should == 1
67 it "should set statuscode" do
69 @reply.statuscode.should == 2
74 it "should set statusmsg" do
77 }.to raise_error(RPCAborted, "foo")
79 @reply.statusmsg.should == "foo"
82 it "should set statuscode to 1 by default" do
85 }.to raise_error(RPCAborted)
88 it "should set statuscode" do
91 }.to raise_error(UnknownRPCAction)
93 @reply.statuscode.should == 2
96 it "should raise RPCAborted for code 1" do
99 }.to raise_error(RPCAborted)
102 it "should raise UnknownRPCAction for code 2" do
104 @reply.fail! "foo", 2
105 }.to raise_error(UnknownRPCAction)
108 it "should raise MissingRPCData for code 3" do
110 @reply.fail! "foo", 3
111 }.to raise_error(MissingRPCData)
114 it "should raise InvalidRPCData for code 4" do
116 @reply.fail! "foo", 4
117 }.to raise_error(InvalidRPCData)
120 it "should raise UnknownRPCError for all other codes" do
122 @reply.fail! "foo", 5
123 }.to raise_error(UnknownRPCError)
126 @reply.fail! "foo", "x"
127 }.to raise_error(UnknownRPCError)
132 it "should save the correct data to the data hash" do
133 @reply[:foo] = "foo1"
134 @reply["foo"] = "foo2"
136 @reply.data[:foo].should == "foo1"
137 @reply.data["foo"].should == "foo2"
142 it "should return the correct saved data" do
143 @reply[:foo] = "foo1"
144 @reply["foo"] = "foo2"
146 @reply[:foo].should == "foo1"
147 @reply["foo"].should == "foo2"
151 describe "#to_hash" do
152 it "should have the correct keys" do
153 @reply.to_hash.keys.sort.should == [:data, :statuscode, :statusmsg]
156 it "should have the correct statuscode" do
158 @reply.to_hash[:statuscode].should == 2
161 it "should have the correct statusmsg" do
163 @reply.to_hash[:statusmsg].should == "meh"
166 it "should have the correct data" do
168 @reply.to_hash[:data][:foo].should == :bar