X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fgenerators%2Fagent_generator_spec.rb;fp=spec%2Funit%2Fgenerators%2Fagent_generator_spec.rb;h=0bb5b9722a15ac8dfc30be0b7011e2f1740d182a;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/generators/agent_generator_spec.rb b/spec/unit/generators/agent_generator_spec.rb new file mode 100644 index 0000000..0bb5b97 --- /dev/null +++ b/spec/unit/generators/agent_generator_spec.rb @@ -0,0 +1,72 @@ +#! /usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module Generators + describe AgentGenerator do + + describe "#create_ddl" do + + before :each do + AgentGenerator.any_instance.stubs(:create_plugin_content) + AgentGenerator.any_instance.stubs(:create_plugin_string) + AgentGenerator.any_instance.stubs(:write_plugins) + AgentGenerator.any_instance.expects(:create_metadata_string).returns("metadata\n") + end + + it "should create a ddl with nothing but metadata if no actions are specified" do + result = AgentGenerator.new("foo").ddl + result.should == "metadata\n" + end + + it "should add action strings to metadata if there are actions specfied" do + result = AgentGenerator.new("foo", ["action1", "action2"]).ddl + expected = File.read(File.join(File.dirname(__FILE__), "snippets", "agent_ddl")) + result.should == expected + end + end + + describe "#create_plugin_content" do + before :each do + AgentGenerator.any_instance.stubs(:create_plugin_string) + AgentGenerator.any_instance.stubs(:write_plugins) + AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n") + AgentGenerator.any_instance.stubs(:create_ddl) + end + + it "should create the correct pluginf ile content with actions if they are specified" do + AgentGenerator.any_instance.stubs(:create_metadata_string).returns("meta\n") + result = AgentGenerator.new("foo", ["action1", "action2"]).content + result.should == " action \"action1\" do\n end\n\n action \"action2\" do\n end\n" + end + end + + describe "#action_help" do + before :each do + AgentGenerator.any_instance.stubs(:create_plugin_content) + AgentGenerator.any_instance.stubs(:create_plugin_string) + AgentGenerator.any_instance.stubs(:write_plugins) + AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n") + end + + it "should load and return the action_help snippet" do + erb = mock + erb.stubs(:result).returns("result") + File.stubs(:dirname).returns("/tmp") + File.expects(:read).with("/tmp/templates/action_snippet.erb").returns("result") + ERB.expects(:new).with("result").returns(erb) + AgentGenerator.new("foo", ["action"]) + end + + it "should raise an error if the action_help snippet does not exist" do + File.stubs(:dirname).returns("/tmp") + File.stubs(:read).raises(Errno::ENOENT, "No such file or directory") + expect{ + AgentGenerator.new("foo", ["action"]) + }.to raise_error(Errno::ENOENT) + end + end + end + end +end