spec/invoker/commander_spec.rb in invoker-1.0.3 vs spec/invoker/commander_spec.rb in invoker-1.0.4
- old
+ new
@@ -1,14 +1,14 @@
require "spec_helper"
describe "Invoker::Commander" do
-
+
describe "With no processes configured" do
before do
@commander = Invoker::Commander.new()
end
-
+
it "should throw error" do
invoker_config.stubs(:processes).returns([])
expect {
@commander.start_manager()
@@ -23,13 +23,18 @@
it "should find command by label and start it, if found" do
invoker_config.stubs(:processes).returns([OpenStruct.new(:label => "resque", :cmd => "foo", :dir => "bar")])
invoker_config.expects(:process).returns(OpenStruct.new(:label => "resque", :cmd => "foo", :dir => "bar"))
@commander.expects(:add_command).returns(true)
-
+
@commander.add_command_by_label("resque")
end
+
+ it "should not start already running process" do
+ @commander.workers.expects(:[]).returns(OpenStruct.new(:pid => "bogus"))
+ expect(@commander.add_command_by_label("resque")).to be_false
+ end
end
describe "#remove_command" do
describe "when a worker is found" do
before do
@@ -56,11 +61,11 @@
# @commander = Invoker::Commander.new()
# @commander.workers.expects(:[]).returns(OpenStruct.new(:pid => "bogus"))
# end
# it "should return false" do
-
+
# end
# end
end
describe "when no worker is found" do
@@ -88,10 +93,11 @@
Invoker.send(:remove_const,:COMMANDER)
end
it "should populate workers and open_pipes" do
@commander.expects(:start_event_loop)
+ @commander.expects(:load_env).returns({})
@commander.start_manager()
expect(@commander.open_pipes).not_to be_empty
expect(@commander.workers).not_to be_empty
worker = @commander.workers['sleep']
@@ -129,6 +135,51 @@
@commander.expects(:hello).returns(true)
@commander.run_runnables()
end
end
+ describe "#load_env" do
+ before do
+ @commander = Invoker::Commander.new()
+ end
+
+ it "should load .env file from the specified directory" do
+ dir = "/tmp"
+ begin
+ env_file = File.new("#{dir}/.env", "w")
+ env_data =<<-EOD
+FOO=foo
+BAR=bar
+ EOD
+ env_file.write(env_data)
+ env_file.close
+ env_options = @commander.load_env(dir)
+ expect(env_options).to include("FOO" => "foo", "BAR" => "bar")
+ ensure
+ File.delete(env_file.path)
+ end
+ end
+
+ it "should default to current directory if no directory is specified" do
+ dir = ENV["HOME"]
+ ENV.stubs(:[]).with("PWD").returns(dir)
+ begin
+ env_file = File.new("#{dir}/.env", "w")
+ env_data =<<-EOD
+FOO=bar
+BAR=foo
+ EOD
+ env_file.write(env_data)
+ env_file.close
+ env_options = @commander.load_env
+ expect(env_options).to include("FOO" => "bar", "BAR" => "foo")
+ ensure
+ File.delete(env_file.path)
+ end
+ end
+
+ it "should return empty hash if there is no .env file" do
+ dir = "/tmp"
+ expect(@commander.load_env(dir)).to eq({})
+ end
+ end
end