2010-09-06 17:18:39 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2010-07-02 21:39:17 +00:00
|
|
|
|
|
|
|
class JobTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
context "A Job" do
|
2010-09-07 03:38:11 +00:00
|
|
|
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
|
2010-07-02 21:39:17 +00:00
|
|
|
job = new_job(:template => ":task", :task => 'abc123')
|
2010-09-07 03:38:11 +00:00
|
|
|
assert_equal 'abc123', job.output
|
2010-07-02 21:39:17 +00:00
|
|
|
end
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
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
|
|
|
|
|
2010-07-02 21:39:17 +00:00
|
|
|
should "output the :task if it's in single quotes" do
|
|
|
|
job = new_job(:template => "':task'", :task => 'abc123')
|
|
|
|
assert_equal %q('abc123'), job.output
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the :task if it's in double quotes" do
|
|
|
|
job = new_job(:template => '":task"', :task => 'abc123')
|
|
|
|
assert_equal %q("abc123"), job.output
|
|
|
|
end
|
|
|
|
|
2010-07-03 05:15:59 +00:00
|
|
|
should "output escaped single quotes in when it's wrapped in them" do
|
|
|
|
job = new_job(
|
|
|
|
:template => "before ':foo' after",
|
|
|
|
:foo => "quote -> ' <- quote"
|
|
|
|
)
|
|
|
|
assert_equal %q(before 'quote -> '\'' <- quote' after), job.output
|
2010-07-02 21:39:17 +00:00
|
|
|
end
|
|
|
|
|
2010-07-03 05:15:59 +00:00
|
|
|
should "output escaped double quotes when it's wrapped in them" do
|
|
|
|
job = new_job(
|
|
|
|
:template => 'before ":foo" after',
|
|
|
|
:foo => 'quote -> " <- quote'
|
|
|
|
)
|
|
|
|
assert_equal %q(before "quote -> \" <- quote" after), job.output
|
2010-07-02 21:39:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2010-09-07 03:38:11 +00:00
|
|
|
def new_job(options={})
|
2010-07-02 21:39:17 +00:00
|
|
|
Whenever::Job.new(options)
|
|
|
|
end
|
|
|
|
|
2010-07-03 05:15:59 +00:00
|
|
|
end
|