Sets the PATH automatically unless it's already provided or told not to.

This commit is contained in:
Javan Makhmali 2009-07-15 15:37:03 -04:00
parent ed86aeb792
commit 51a6b3720a
5 changed files with 57 additions and 4 deletions

View File

@ -1,6 +1,11 @@
== 0.3.6 / June 15th, 2009
* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
== 0.3.5 / June 13th, 2009
* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm, 6am']). [Sam Ruby]
* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
* Fixed issue with new lines. #18 [Javan Makhmali]

View File

@ -57,6 +57,8 @@ module Whenever
end
def generate_cron_output
set_path_environment_variable
[environment_variables, cron_jobs].compact.join
end
@ -78,6 +80,19 @@ module Whenever
end
end
def set_path_environment_variable
return if path_should_not_be_set_automatically?
@env[:PATH] = read_path unless read_path.blank?
end
def read_path
ENV['PATH'] if ENV
end
def path_should_not_be_set_automatically?
@set_path_automatically === false || @env[:PATH] || @env["PATH"]
end
def environment_variables
return if @env.empty?

View File

@ -2,7 +2,7 @@ module Whenever
module VERSION #:nodoc:
MAJOR = 0
MINOR = 3
TINY = 5
TINY = 6
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@ -20,4 +20,37 @@ class OutputEnvTest < Test::Unit::TestCase
end
end
context "No PATH environment variable set" do
setup do
Whenever::JobList.any_instance.expects(:read_path).at_least_once.returns('/usr/local/bin')
@output = Whenever.cron ""
end
should "add a PATH variable based on the user's PATH" do
assert_match "PATH=/usr/local/bin", @output
end
end
context "A PATH environment variable set" do
setup do
Whenever::JobList.stubs(:read_path).returns('/usr/local/bin')
@output = Whenever.cron "env :PATH, '/my/path'"
end
should "use that path and the user's PATH" do
assert_match "PATH=/my/path", @output
assert_no_match /local/, @output
end
end
context "No PATH set and instructed not to automatically load the user's path" do
setup do
@output = Whenever.cron "set :set_path_automatically, false"
end
should "not have a PATH set" do
assert_no_match /PATH/, @output
end
end
end

View File

@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{whenever}
s.version = "0.3.5"
s.version = "0.3.6"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Javan Makhmali"]
s.date = %q{2009-07-13}
s.date = %q{2009-07-15}
s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
s.email = %q{javan@javan.us}
s.executables = ["whenever", "wheneverize"]