2009-02-17 02:32:55 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2009-02-16 03:24:10 +00:00
|
|
|
|
|
|
|
class OutputRunnerTest < Test::Unit::TestCase
|
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
context "A runner with path set" do
|
2009-02-16 03:24:10 +00:00
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
2009-02-16 03:24:10 +00:00
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using that path" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
2009-02-16 03:24:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
context "A runner that overrides the path set" do
|
2009-02-16 03:24:10 +00:00
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah", :path => '/some/other/path'
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using that path" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /some/other/path && script/runner -e production "blahblah"', @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A runner with no path set and RAILS_ROOT defined" do
|
|
|
|
setup do
|
|
|
|
Whenever.stubs(:path).returns('/my/path')
|
2009-02-16 03:24:10 +00:00
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using that path" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
2009-02-16 03:24:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
context "A runner with path set AND RAILS_ROOT defined" do
|
2009-02-16 03:24:10 +00:00
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
Whenever.stubs(:path).returns('/my/rails/path')
|
2009-02-16 03:24:10 +00:00
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
2009-02-17 00:22:37 +00:00
|
|
|
set :path, '/my/path'
|
2009-02-16 03:24:10 +00:00
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
should "use the path" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e production "blahblah"', @output
|
2009-02-16 03:24:10 +00:00
|
|
|
assert_no_match /\/rails\/path/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-17 00:22:37 +00:00
|
|
|
context "A runner with an environment set" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using that environment" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e silly "blahblah"', @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A runner that overrides the environment set" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah", :environment => :serious
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using that environment" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
|
2009-02-17 00:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-02 10:26:15 +00:00
|
|
|
context "A runner where the environment is overridden using the :set option" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron :set => 'environment=serious', :string => \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/my/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using the override environment" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
|
2009-06-02 10:26:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A runner where the environment and path are overridden using the :set option" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/silly/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using the overridden path and environment" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
|
2009-06-02 10:26:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/silly/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using the overridden path and environment" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
|
2009-06-02 10:26:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A runner where the environment is overridden using the :set option but no value is given" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron :set => ' environment=', :string => \
|
|
|
|
<<-file
|
|
|
|
set :environment, :silly
|
|
|
|
set :path, '/silly/path'
|
|
|
|
every 2.hours do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using the original environmnet" do
|
2010-04-12 19:55:52 +00:00
|
|
|
assert_match two_hours + ' cd /silly/path && script/runner -e silly "blahblah"', @output
|
2009-06-02 10:26:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-09 14:57:14 +00:00
|
|
|
end
|