6 describe PluginPackager do
7 describe "#load_packagers" do
8 it "should load all PluginPackager plugins" do
9 PluginManager.expects(:find_and_load).with("pluginpackager")
10 PluginPackager.load_packagers
15 it "should return the correct class" do
16 PluginPackager.expects(:const_get).with("Foo").returns(:foo)
17 result = PluginPackager["Foo"]
21 it "should do something else" do
24 }.to raise_error(NameError, 'uninitialized constant MCollective::PluginPackager::Bar')
28 describe "#get_metadata" do
29 it "should raise an exception if the ddl file can't be loaded" do
30 DDL.expects(:new).with("package", :foo, false)
32 Dir.stubs(:glob).returns('')
34 PluginPackager.get_metadata("/tmp", "foo")
35 }.to raise_error(RuntimeError)
38 it "should load the ddl file and return the metadata" do
40 DDL.expects(:new).with("package", :foo, false).returns(ddl)
42 Dir.stubs(:glob).returns(["foo.ddl"])
43 File.expects(:read).with("foo.ddl").returns("foo_ddl")
44 ddl.expects(:instance_eval).with("foo_ddl")
45 ddl.expects(:meta).returns("metadata")
46 ddl.expects(:requirements).returns({:mcollective => 1})
48 meta, requirements = PluginPackager.get_metadata("/tmp", "foo")
49 meta.should == "metadata"
50 requirements.should == 1
54 describe "#check_dir_present" do
55 it "should return true if the directory is present and not empty" do
56 File.expects(:directory?).with("/tmp").returns(true)
57 File.expects(:join).with("/tmp", "*")
58 Dir.expects(:glob).returns([1])
59 result = PluginPackager.check_dir_present("/tmp")
63 it "should return false if the directory is not present" do
64 File.expects(:directory?).with("/tmp").returns(false)
65 result = PluginPackager.check_dir_present("/tmp")
66 result.should == false
69 it "should return false if the direcotry is present but empty" do
70 File.expects(:directory?).with("/tmp").returns(true)
71 File.expects(:join).with("/tmp", "*")
72 Dir.expects(:glob).returns([])
73 result = PluginPackager.check_dir_present("/tmp")
74 result.should == false
78 describe "#do_quietly?" do
79 it "should call the block parameter if verbose is true" do
80 result = PluginPackager.do_quietly?(true) {:success}
81 result.should == :success
84 it "should call the block parameter quietly if verbose is false" do
85 std_out = Tempfile.new("mc_pluginpackager_spec")
86 File.expects(:new).with("/dev/null", "w").returns(std_out)
87 PluginPackager.do_quietly?(false) {puts "success"}
89 std_out.read.should == "success\n"
94 it "should raise an exception and reset stdout if the block raises an execption" do
96 PluginPackager.do_quietly?(false) {raise Exception, "exception"}
97 }.to raise_error(Exception, "exception")
101 describe "#build_tool?" do
102 it "should return true if the given build tool is present on the system" do
103 File.expects(:join).returns("foo")
104 File.expects(:exists?).with("foo").returns(true)
105 result = PluginPackager.build_tool?("foo")
106 result.should == true
109 it "should return false if the given build tool is not present on the system" do
110 File.stubs(:join).returns("foo")
111 File.stubs(:exists?).with("foo").returns(false)
112 result = PluginPackager.build_tool?("foo")
113 result.should == false
117 describe "#safe_system" do
118 it "should not raise any exceptions if a command ran" do
119 PluginPackager.expects(:system).with("foo").returns(true)
120 lambda{PluginPackager.safe_system("foo")}.should_not raise_error
123 it "should raise a RuntimeError if command cannot be run" do
124 PluginPackager.expects(:system).with("foo").returns(false)
126 PluginPackager.safe_system("foo")
127 }.to raise_error(RuntimeError, "Failed: foo")