Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / generators / base_spec.rb
1 #!/usr/bin/env rspec
2
3 require "spec_helper"
4
5 module MCollective
6   module Generators
7     describe Base do
8       before :each do
9         @erb = mock
10         @erb.stubs(:result)
11         File.stubs(:dirname).returns("/tmp")
12         @base = Base.new(nil, nil, nil, nil, nil, nil, nil)
13       end
14
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",
20                               :author => "author",
21                               :license => "license",
22                               :version => "version",
23                               :url => "url",
24                               :timeout => "timeout"}
25         end
26       end
27
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
33         end
34
35         it "should raise an error if the template is not present" do
36           File.expects(:read).raises(Errno::ENOENT)
37           expect{
38             @base.create_metadata_string
39           }.to raise_error(Errno::ENOENT)
40         end
41       end
42
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
48         end
49
50         it "should raise an error if the template is not present" do
51           File.expects(:read).raises(Errno::ENOENT)
52           expect{
53             @base.create_plugin_string
54           }.to raise_error(Errno::ENOENT)
55         end
56       end
57
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"
62           expect{
63             @base.write_plugins
64           }.to raise_error(RuntimeError)
65         end
66
67         it "should create the directory and the plugin files if it doesn't exist" do
68           Dir.stubs(:pwd).returns("/tmp")
69           @base.stubs(:puts)
70
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")
75
76           @base.plugin_name = "foo"
77           @base.mod_name = "agent"
78           @base.write_plugins
79         end
80       end
81     end
82   end
83 end