whenever/test/output_runner_test.rb

125 lines
3.0 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2009-02-16 03:24:10 +00:00
class OutputRunnerTest < Test::Unit::TestCase
context "A runner with path set" do
2009-02-16 03:24:10 +00:00
setup do
@output = Whenever.cron \
2009-02-16 03:24:10 +00:00
<<-file
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
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
end
end
context "A runner that overrides the path set" do
2009-02-16 03:24:10 +00:00
setup do
@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
assert_match two_hours + ' /some/other/path/script/runner -e production "blahblah"', @output
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
@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
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
end
end
context "A runner with path set AND RAILS_ROOT defined" do
2009-02-16 03:24:10 +00:00
setup do
Whenever.stubs(:path).returns('/my/rails/path')
2009-02-16 03:24:10 +00:00
@output = Whenever.cron \
2009-02-16 03:24:10 +00:00
<<-file
set :path, '/my/path'
2009-02-16 03:24:10 +00:00
every 2.hours do
runner "blahblah"
end
file
end
should "use the path" do
2009-02-16 03:24:10 +00:00
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
assert_no_match /\/rails\/path/, @output
end
end
context "A runner with no path set and no RAILS_ROOT defined" do
2009-02-16 03:24:10 +00:00
setup do
Whenever.stubs(:path).returns(nil)
2009-02-16 03:24:10 +00:00
@input = <<-file
every 2.hours do
runner "blahblah"
end
file
end
should "raise an exception" do
assert_raises ArgumentError do
Whenever.cron(@input)
2009-02-16 03:24:10 +00:00
end
end
end
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
assert_match two_hours + ' /my/path/script/runner -e silly "blahblah"', @output
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
assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
end
end
2009-02-16 03:24:10 +00:00
end