8 Cache.delete!(:ddl) rescue nil
12 it "should default to agent ddls" do
13 DDL::AgentDDL.expects(:new).once
17 it "should return the correct plugin ddl class" do
18 DDL.new("rspec", :agent, false).class.should == DDL::AgentDDL
21 it "should default to base when no specific class exist" do
22 DDL.new("rspec", :rspec, false).class.should == DDL::Base
26 describe "#load_and_cache" do
27 it "should setup the cache" do
30 Cache.expects(:setup).once.returns(true)
31 DDL.load_and_cache("rspec", :agent, false)
34 it "should attempt to read from the cache and return found ddl" do
36 Cache.expects(:read).with(:ddl, "agent/rspec").returns("rspec")
37 DDL.load_and_cache("rspec", :agent, false).should == "rspec"
40 it "should handle cache misses then create and save a new ddl object" do
42 Cache.expects(:read).with(:ddl, "agent/rspec").raises("failed")
43 Cache.expects(:write).with(:ddl, "agent/rspec", kind_of(DDL::AgentDDL)).returns("rspec")
45 DDL.load_and_cache("rspec", :agent, false).should == "rspec"
49 describe "#string_to_number" do
50 it "should turn valid strings into numbers" do
51 ["1", "0", "9999"].each do |i|
52 DDL.string_to_number(i).class.should == Fixnum
55 ["1.1", "0.0", "9999.99"].each do |i|
56 DDL.string_to_number(i).class.should == Float
60 it "should raise errors for invalid values" do
61 expect { DDL.string_to_number("rspec") }.to raise_error
65 describe "#string_to_boolean" do
66 it "should turn valid strings into boolean" do
67 ["true", "yes", "1"].each do |t|
68 DDL.string_to_boolean(t).should == true
69 DDL.string_to_boolean(t.upcase).should == true
72 ["false", "no", "0"].each do |f|
73 DDL.string_to_boolean(f).should == false
74 DDL.string_to_boolean(f.upcase).should == false
78 it "should raise errors for invalid values" do
79 expect { DDL.string_to_boolean("rspec") }.to raise_error