X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fgenerators%2Fbase_spec.rb;fp=spec%2Funit%2Fgenerators%2Fbase_spec.rb;h=a30720dcb5b1a4e7bb5ed3e93bd1f953be5c507c;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/generators/base_spec.rb b/spec/unit/generators/base_spec.rb new file mode 100644 index 0000000..a30720d --- /dev/null +++ b/spec/unit/generators/base_spec.rb @@ -0,0 +1,83 @@ +#!/usr/bin/env rspec + +require "spec_helper" + +module MCollective + module Generators + describe Base do + before :each do + @erb = mock + @erb.stubs(:result) + File.stubs(:dirname).returns("/tmp") + @base = Base.new(nil, nil, nil, nil, nil, nil, nil) + end + + describe "#initialize" do + it "should set the correct metaparameters" do + res = Base.new("name", "description", "author", "license", "version", "url", "timeout") + res.meta.should == {:name => "name", + :description => "description", + :author => "author", + :license => "license", + :version => "version", + :url => "url", + :timeout => "timeout"} + end + end + + describe "#create_metadata_string" do + it "should load the ddl template if it is present" do + File.expects(:read).returns("ddl") + ERB.expects(:new).with("ddl", nil, "-").returns(@erb) + @base.create_metadata_string + end + + it "should raise an error if the template is not present" do + File.expects(:read).raises(Errno::ENOENT) + expect{ + @base.create_metadata_string + }.to raise_error(Errno::ENOENT) + end + end + + describe "#create_plugin_string " do + it "should load the plugin template if it is present" do + File.expects(:read).returns("plugin") + ERB.expects(:new).with("plugin", nil, "-").returns(@erb) + @base.create_plugin_string + end + + it "should raise an error if the template is not present" do + File.expects(:read).raises(Errno::ENOENT) + expect{ + @base.create_plugin_string + }.to raise_error(Errno::ENOENT) + end + end + + describe "#write_plugins" do + it "should fail if the directory already exists" do + Dir.expects(:mkdir).raises(Errno::EEXIST) + @base.plugin_name = "foo" + expect{ + @base.write_plugins + }.to raise_error(RuntimeError) + end + + it "should create the directory and the plugin files if it doesn't exist" do + Dir.stubs(:pwd).returns("/tmp") + @base.stubs(:puts) + + Dir.expects(:mkdir).with("foo") + Dir.expects(:mkdir).with("foo/agent") + File.expects(:open).with("foo/agent/foo.ddl", "w") + File.expects(:open).with("foo/agent/foo.rb", "w") + + @base.plugin_name = "foo" + @base.mod_name = "agent" + @base.write_plugins + end + end + end + end +end