consolidated tests - moving away from testing on runners, rakes, etc. now that jobs are definable. added more units tests for Jobs.
This commit is contained in:
parent
27827c8e17
commit
f17c8d8cd2
@ -1,7 +1,7 @@
|
||||
module Whenever
|
||||
class Job
|
||||
|
||||
attr_accessor :at, :output_redirection
|
||||
attr_reader :at, :output_redirection
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
|
@ -174,4 +174,73 @@ NEW_CRON
|
||||
@command = Whenever::CommandLine.new(:update => true, :clear => true)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /silly/path && script/runner -e silly 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,37 +0,0 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
||||
|
||||
class OutputCommandTest < Test::Unit::TestCase
|
||||
|
||||
context "A plain command" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
every 2.hours do
|
||||
command "blahblah"
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the command" do
|
||||
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
||||
end
|
||||
end
|
||||
|
||||
context "An every statement with two commands in it" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
every 1.hour do
|
||||
command "first"
|
||||
command "second"
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output both commands" do
|
||||
assert_match "0 * * * * first", @output
|
||||
assert_match "0 * * * * second", @output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,9 +1,59 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
||||
|
||||
class OutputRakeTest < Test::Unit::TestCase
|
||||
class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
||||
|
||||
# Rake are generated in an almost identical way to runners so we
|
||||
# only need some basic tests to ensure they are output correctly
|
||||
# command
|
||||
|
||||
context "A plain command" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
every 2.hours do
|
||||
command "blahblah"
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the command" do
|
||||
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
||||
end
|
||||
end
|
||||
|
||||
# runner
|
||||
|
||||
context "A runner with path set" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
set :path, '/my/path'
|
||||
every 2.hours do
|
||||
runner 'blahblah'
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the runner using that path" do
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
context "A runner that overrides the path set" do
|
||||
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 + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
# rake
|
||||
|
||||
context "A rake command with path set" do
|
||||
setup do
|
||||
@ -37,38 +87,4 @@ class OutputRakeTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "A rake command with environment set" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
set :environment, :silly
|
||||
set :path, '/my/path'
|
||||
every 2.hours do
|
||||
rake "blahblah"
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the rake command using that environment" do
|
||||
assert_match two_hours + ' cd /my/path && RAILS_ENV=silly /usr/bin/env rake blahblah', @output
|
||||
end
|
||||
end
|
||||
|
||||
context "A rake command that overrides the environment set" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
set :environment, :silly
|
||||
set :path, '/my/path'
|
||||
every 2.hours do
|
||||
rake "blahblah", :environment => :serious
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the rake command using that environment" do
|
||||
assert_match two_hours + ' cd /my/path && RAILS_ENV=serious /usr/bin/env rake blahblah', @output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -83,5 +83,23 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
||||
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
||||
end
|
||||
end
|
||||
|
||||
context "A defined job that uses a :path where none is explicitly set" do
|
||||
setup do
|
||||
Whenever.expects(:path).returns('/my/path')
|
||||
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
job_type :some_job, "cd :path && :task"
|
||||
every 2.hours do
|
||||
some_job 'blahblah'
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "default to using the Whenever.path" do
|
||||
assert_match two_hours + %( cd /my/path && blahblah), @output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,175 +0,0 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
||||
|
||||
class OutputRunnerTest < Test::Unit::TestCase
|
||||
|
||||
context "A runner with path set" do
|
||||
setup do
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
set :path, '/my/path'
|
||||
every 2.hours do
|
||||
runner 'blahblah'
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the runner using that path" do
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
context "A runner that overrides the path set" do
|
||||
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 + %( cd /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')
|
||||
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
every 2.hours do
|
||||
runner 'blahblah'
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "output the runner using that path" do
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
context "A runner with path set AND RAILS_ROOT defined" do
|
||||
setup do
|
||||
Whenever.stubs(:path).returns('/my/rails/path')
|
||||
|
||||
@output = Whenever.cron \
|
||||
<<-file
|
||||
set :path, '/my/path'
|
||||
every 2.hours do
|
||||
runner "blahblah"
|
||||
end
|
||||
file
|
||||
end
|
||||
|
||||
should "use the path" do
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
||||
assert_no_match /\/rails\/path/, @output
|
||||
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 + %( cd /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 + %( cd /my/path && script/runner -e serious 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
assert_match two_hours + %( cd /my/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
||||
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
|
||||
assert_match two_hours + %( cd /silly/path && script/runner -e silly 'blahblah'), @output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -3,11 +3,36 @@ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
||||
class JobTest < Test::Unit::TestCase
|
||||
|
||||
context "A Job" do
|
||||
should "output the :task" do
|
||||
job = new_job(:template => ":task", :task => 'abc123')
|
||||
assert_equal %q(abc123), job.output
|
||||
should "return the :at set when #at is called" do
|
||||
assert_equal 'foo', new_job(:at => 'foo').at
|
||||
end
|
||||
|
||||
should "return :output when #output_redirection is called" do
|
||||
assert_equal 'foo', new_job(:output => 'foo').output_redirection
|
||||
end
|
||||
|
||||
should "return :not_set when #output_redirection is called and no :output is set" do
|
||||
assert_equal :not_set, new_job.output_redirection
|
||||
end
|
||||
|
||||
should "substitute the :task when #output is called" do
|
||||
job = new_job(:template => ":task", :task => 'abc123')
|
||||
assert_equal 'abc123', job.output
|
||||
end
|
||||
|
||||
should "substitute the :path when #output is called" do
|
||||
assert_equal 'foo', new_job(:template => ':path', :path => 'foo').output
|
||||
end
|
||||
|
||||
should "substitute the :path with the default Whenever.path if none is provided when #output is called" do
|
||||
Whenever.expects(:path).returns('/my/path')
|
||||
assert_equal '/my/path', new_job(:template => ':path').output
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "A Job with quotes" do
|
||||
|
||||
should "output the :task if it's in single quotes" do
|
||||
job = new_job(:template => "':task'", :task => 'abc123')
|
||||
assert_equal %q('abc123'), job.output
|
||||
@ -37,7 +62,7 @@ class JobTest < Test::Unit::TestCase
|
||||
|
||||
private
|
||||
|
||||
def new_job(options)
|
||||
def new_job(options={})
|
||||
Whenever::Job.new(options)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user