7 describe StandardDefinition do
9 PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1})
12 describe "#initialize" do
13 it "should replace spaces in the package name with dashes" do
14 plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {}, "testplugin")
15 plugin.metadata[:name].should == "test-plugin"
18 it "should set dependencies if present" do
19 plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [{:name => "foo", :version => nil}], {}, "testplugin")
20 plugin.dependencies.should == [{:name => "foo", :version => nil},
21 {:name => "mcollective-common", :version => nil}]
24 it "should set mc name and version dependencies" do
25 plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
26 plugin.mcname.should == "pe-mcollective"
27 plugin.mcversion.should == "1"
30 it "should replace underscores with dashes in the name" do
31 plugin = StandardDefinition.new(".", "test_plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
32 plugin.metadata[:name].should == "test-plugin"
35 it "should replace whitespaces with a single dash in the name" do
36 plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
37 plugin.metadata[:name].should == "test-plugin"
41 describe "#identify_packages" do
42 it "should attempt to identify all packages" do
43 StandardDefinition.any_instance.expects(:common).once.returns(:check)
44 StandardDefinition.any_instance.expects(:plugin).once.returns(:check)
46 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
47 plugin.packagedata[:common].should == :check
48 plugin.packagedata["testplugin"].should == :check
54 it "should return nil if the plugin doesn't contain any files" do
55 StandardDefinition.any_instance.expects(:common).returns(nil)
56 PluginPackager.expects(:check_dir_present).returns(false)
57 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
58 plugin.packagedata["testplugin"].should == nil
61 it "should add plugin files to the file list" do
62 StandardDefinition.any_instance.expects(:common).returns(nil)
63 PluginPackager.expects(:check_dir_present).returns(true)
64 Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
65 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
66 plugin.packagedata["testplugin"][:files].should == ["file.rb"]
69 it "should add common package as dependency if present" do
70 StandardDefinition.any_instance.expects(:common).returns(true)
71 PluginPackager.expects(:check_dir_present).returns(true)
72 Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
73 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
74 plugin.packagedata["testplugin"][:files].should == ["file.rb"]
75 plugin.packagedata["testplugin"][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
76 plugin.packagedata["testplugin"][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :iteration => 1}
82 StandardDefinition.any_instance.expects(:plugin).returns(false)
85 it "should return nil if common doesn't contain any files" do
86 PluginPackager.expects(:check_dir_present).returns(false)
87 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
88 plugin.packagedata[:common].should == nil
91 it "should add common files to the file list" do
92 PluginPackager.expects(:check_dir_present).returns(true)
93 Dir.expects(:glob).with("./util/*").returns(["common.rb"])
94 plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
95 plugin.packagedata[:common][:files].should == ["common.rb"]