spec/invoker/process_manager_spec.rb in invoker-1.4.1 vs spec/invoker/process_manager_spec.rb in invoker-1.5.1

- old
+ new

@@ -1,16 +1,22 @@ require "spec_helper" describe Invoker::ProcessManager do let(:process_manager) { Invoker::ProcessManager.new } + describe "#start_process_by_name" do 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")) + @original_invoker_config = Invoker.config + Invoker.config = mock + + 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")) process_manager.expects(:start_process).returns(true) process_manager.start_process_by_name("resque") + + Invoker.config = @original_invoker_config end it "should not start already running process" do process_manager.workers.expects(:[]).returns(OpenStruct.new(:pid => "bogus")) expect(process_manager.start_process_by_name("resque")).to be_falsey @@ -91,8 +97,34 @@ end it "should return empty hash if there is no .env file" do dir = "/tmp" expect(process_manager.load_env(dir)).to eq({}) + end + + it "should load .local.env file if it exists" 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 + + local_env_file = File.new("#{dir}/.env.local", "w") + local_env_data =<<-EOD +FOO=emacs + EOD + local_env_file.write(local_env_data) + local_env_file.close + + env_options = process_manager.load_env(dir) + expect(env_options).to include("FOO" => "emacs", "BAR" => "bar") + ensure + File.delete(env_file.path) + File.delete(local_env_file.path) + end end end end