6 describe Applications do
8 tmpfile = Tempfile.new("mc_applications_spec")
12 @tmpdir = FileUtils.mkdir_p(path)
13 @tmpdir = @tmpdir[0] if @tmpdir.is_a?(Array) # ruby 1.9.2
16 @appsdir = File.join([@tmpdir, "mcollective", "application"])
17 FileUtils.mkdir_p(@appsdir)
19 FileUtils.cp(File.join([File.dirname(__FILE__), "..", "fixtures", "application", "test.rb"]), @appsdir)
23 FileUtils.rm_r(@tmpdir)
27 it "should load the config" do
28 Applications.expects(:load_config).once
29 PluginManager.expects("[]").once
33 it "should return the correct stored application" do
37 Applications.expects(:load_config).once
38 PluginManager.expects("[]").with("test_application").once.returns(app)
39 Applications["test"].should == app
44 it "should load the configuration" do
48 Applications.expects(:load_config).once
49 Applications.expects(:load_application).once
50 PluginManager.expects("[]").once.returns(app)
52 Applications.run("test")
55 it "should load the application" do
59 Applications.expects(:load_config).once
60 Applications.expects(:load_application).with("test").once
61 PluginManager.expects("[]").once.returns(app)
63 Applications.run("test")
66 it "should invoke the application run method" do
68 app.stubs(:run).returns("hello world")
70 Applications.expects(:load_config).once
71 Applications.expects(:load_application)
72 PluginManager.expects("[]").once.returns(app)
74 Applications.run("test").should == "hello world"
78 describe "#load_application" do
79 it "should return the existing application if already loaded" do
83 PluginManager << {:type => "test_application", :class => app}
85 Applications.expects("load_config").never
87 Applications.load_application("test")
90 it "should load the config" do
91 Applications.expects("load_config").returns(true).once
92 Applications.load_application("test")
95 it "should load the correct class from disk" do
96 PluginManager.expects("loadclass").with("MCollective::Application::Test")
97 Applications.expects("load_config").returns(true).once
99 Applications.load_application("test")
102 it "should add the class to the plugin manager" do
103 Applications.expects("load_config").returns(true).once
105 PluginManager.expects("<<").with({:type => "test_application", :class => "MCollective::Application::Test"})
107 Applications.load_application("test")
112 it "should load the configuration" do
113 Applications.expects("load_config").returns(true).once
114 Config.instance.expects("libdir").returns([@tmpdir])
118 it "should add found applications to the list" do
119 Applications.expects("load_config").returns(true).once
120 Config.instance.expects("libdir").returns([@tmpdir])
122 Applications.list.should == ["test"]
125 it "should print a friendly error and exit on failure" do
126 Applications.expects("load_config").raises(Exception)
127 IO.any_instance.expects(:puts).with(regexp_matches(/Failed to generate application list/)).once
130 Applications.list.should
131 }.to raise_error(SystemExit)
135 describe "#filter_extra_options" do
136 it "should parse --config=x" do
137 ["--config=x --foo=bar -f -f bar", "--foo=bar --config=x -f -f bar"].each do |t|
138 Applications.filter_extra_options(t).should == "--config=x"
142 it "should parse --config x" do
143 ["--config x --foo=bar -f -f bar", "--foo=bar --config x -f -f bar"].each do |t|
144 Applications.filter_extra_options(t).should == "--config=x"
148 it "should parse -c x" do
149 ["-c x --foo=bar -f -f bar", "--foo=bar -c x -f -f bar"].each do |t|
150 Applications.filter_extra_options(t).should == "--config=x"