11 File.stubs(:dirname).returns("/tmp")
12 @base = Base.new(nil, nil, nil, nil, nil, nil, nil)
15 describe "#initialize" do
16 it "should set the correct metaparameters" do
17 res = Base.new("name", "description", "author", "license", "version", "url", "timeout")
18 res.meta.should == {:name => "name",
19 :description => "description",
21 :license => "license",
22 :version => "version",
24 :timeout => "timeout"}
28 describe "#create_metadata_string" do
29 it "should load the ddl template if it is present" do
30 File.expects(:read).returns("ddl")
31 ERB.expects(:new).with("ddl", nil, "-").returns(@erb)
32 @base.create_metadata_string
35 it "should raise an error if the template is not present" do
36 File.expects(:read).raises(Errno::ENOENT)
38 @base.create_metadata_string
39 }.to raise_error(Errno::ENOENT)
43 describe "#create_plugin_string " do
44 it "should load the plugin template if it is present" do
45 File.expects(:read).returns("plugin")
46 ERB.expects(:new).with("plugin", nil, "-").returns(@erb)
47 @base.create_plugin_string
50 it "should raise an error if the template is not present" do
51 File.expects(:read).raises(Errno::ENOENT)
53 @base.create_plugin_string
54 }.to raise_error(Errno::ENOENT)
58 describe "#write_plugins" do
59 it "should fail if the directory already exists" do
60 Dir.expects(:mkdir).raises(Errno::EEXIST)
61 @base.plugin_name = "foo"
64 }.to raise_error(RuntimeError)
67 it "should create the directory and the plugin files if it doesn't exist" do
68 Dir.stubs(:pwd).returns("/tmp")
71 Dir.expects(:mkdir).with("foo")
72 Dir.expects(:mkdir).with("foo/agent")
73 File.expects(:open).with("foo/agent/foo.ddl", "w")
74 File.expects(:open).with("foo/agent/foo.rb", "w")
76 @base.plugin_name = "foo"
77 @base.mod_name = "agent"