2010-09-06 17:18:39 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2009-02-16 03:24:10 +00:00
|
|
|
|
|
|
|
class OutputEnvTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
context "The output from Whenever with environment variables set" do
|
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
env :MYVAR, 'blah'
|
|
|
|
env 'MAILTO', "someone@example.com"
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output MYVAR environment variable" do
|
|
|
|
assert_match "MYVAR=blah", @output
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output MAILTO environment variable" do
|
|
|
|
assert_match "MAILTO=someone@example.com", @output
|
|
|
|
end
|
|
|
|
end
|
2009-07-15 19:37:03 +00:00
|
|
|
|
|
|
|
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
|
2009-02-16 03:24:10 +00:00
|
|
|
|
|
|
|
end
|