spec/invoker/config_spec.rb in invoker-0.1.2 vs spec/invoker/config_spec.rb in invoker-1.0.0
- old
+ new
@@ -14,14 +14,118 @@
command = ruby try_sleep.rb
EOD
file.write(config_data)
file.close
lambda {
- Invoker::Parsers::Config.new(file.path)
+ Invoker::Parsers::Config.new(file.path, 9000)
}.should.raise(Invoker::Errors::InvalidConfig)
ensure
file.unlink()
end
end
end
-end
+ describe "for ports" do
+ it "should replace port in commands" do
+ begin
+ file = Tempfile.new("invalid_config.ini")
+
+ config_data =<<-EOD
+[try_sleep]
+directory = /tmp
+command = ruby try_sleep.rb -p $PORT
+
+[ls]
+directory = /tmp
+command = ls -p $PORT
+
+[noport]
+directory = /tmp
+command = ls
+ EOD
+ file.write(config_data)
+ file.close
+
+ config = Invoker::Parsers::Config.new(file.path, 9000)
+ command1 = config.processes.first
+
+ command1.port.should == 9001
+ command1.cmd.should =~ /9001/
+
+ command2 = config.processes[1]
+
+ command2.port.should == 9002
+ command2.cmd.should =~ /9002/
+
+ command2 = config.processes[2]
+
+ command2.port.should == nil
+ ensure
+ file.unlink()
+ end
+ end
+
+ it "should use port from separate option" do
+ begin
+ file = Tempfile.new("invalid_config.ini")
+ config_data =<<-EOD
+[try_sleep]
+directory = /tmp
+command = ruby try_sleep.rb -p $PORT
+
+[ls]
+directory = /tmp
+port = 3000
+command = pwd
+
+[noport]
+directory = /tmp
+command = ls
+ EOD
+ file.write(config_data)
+ file.close
+
+ config = Invoker::Parsers::Config.new(file.path, 9000)
+ command1 = config.processes.first
+
+ command1.port.should == 9001
+ command1.cmd.should =~ /9001/
+
+ command2 = config.processes[1]
+
+ command2.port.should == 3000
+
+ command2 = config.processes[2]
+
+ command2.port.should == nil
+ ensure
+ file.unlink()
+ end
+ end
+ end
+
+ describe "loading power config" do
+ before do
+ @file = Tempfile.new("config.ini")
+ end
+
+ it "does not load config if platform is not darwin" do
+ Invoker.expects(:darwin?).returns(false)
+ Invoker::Power::Config.expects(:load_config).never
+ Invoker::Parsers::Config.new(@file.path, 9000)
+ end
+
+ it "does not load config if platform is darwin but there is no power config file" do
+ Invoker.expects(:darwin?).returns(true)
+ File.expects(:exists?).with(Invoker::Power::Config::CONFIG_LOCATION).returns(false)
+ Invoker::Power::Config.expects(:load_config).never
+ Invoker::Parsers::Config.new(@file.path, 9000)
+ end
+
+ it "loads config if platform is darwin and power config file exists" do
+ Invoker.expects(:darwin?).returns(true)
+ File.expects(:exists?).with(Invoker::Power::Config::CONFIG_LOCATION).returns(true)
+ Invoker::Power::Config.expects(:load_config).once
+ Invoker::Parsers::Config.new(@file.path, 9000)
+ end
+ end
+end