7 describe AgentGenerator do
9 describe "#create_ddl" do
12 AgentGenerator.any_instance.stubs(:create_plugin_content)
13 AgentGenerator.any_instance.stubs(:create_plugin_string)
14 AgentGenerator.any_instance.stubs(:write_plugins)
15 AgentGenerator.any_instance.expects(:create_metadata_string).returns("metadata\n")
18 it "should create a ddl with nothing but metadata if no actions are specified" do
19 result = AgentGenerator.new("foo").ddl
20 result.should == "metadata\n"
23 it "should add action strings to metadata if there are actions specfied" do
24 result = AgentGenerator.new("foo", ["action1", "action2"]).ddl
25 expected = File.read(File.join(File.dirname(__FILE__), "snippets", "agent_ddl"))
26 result.should == expected
30 describe "#create_plugin_content" do
32 AgentGenerator.any_instance.stubs(:create_plugin_string)
33 AgentGenerator.any_instance.stubs(:write_plugins)
34 AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n")
35 AgentGenerator.any_instance.stubs(:create_ddl)
38 it "should create the correct pluginf ile content with actions if they are specified" do
39 AgentGenerator.any_instance.stubs(:create_metadata_string).returns("meta\n")
40 result = AgentGenerator.new("foo", ["action1", "action2"]).content
41 result.should == " action \"action1\" do\n end\n\n action \"action2\" do\n end\n"
45 describe "#action_help" do
47 AgentGenerator.any_instance.stubs(:create_plugin_content)
48 AgentGenerator.any_instance.stubs(:create_plugin_string)
49 AgentGenerator.any_instance.stubs(:write_plugins)
50 AgentGenerator.any_instance.stubs(:create_metadata_string).returns("metadata\n")
53 it "should load and return the action_help snippet" do
55 erb.stubs(:result).returns("result")
56 File.stubs(:dirname).returns("/tmp")
57 File.expects(:read).with("/tmp/templates/action_snippet.erb").returns("result")
58 ERB.expects(:new).with("result").returns(erb)
59 AgentGenerator.new("foo", ["action"])
62 it "should raise an error if the action_help snippet does not exist" do
63 File.stubs(:dirname).returns("/tmp")
64 File.stubs(:read).raises(Errno::ENOENT, "No such file or directory")
66 AgentGenerator.new("foo", ["action"])
67 }.to raise_error(Errno::ENOENT)