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 OutputCommandTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
context "A plain command" do
|
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command" do
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A command when the cron_log is set" do
|
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
set :cron_log, 'logfile.log'
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command with the log syntax appended" do
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A command when the cron_log is set and the comand overrides it" do
|
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
set :cron_log, 'logfile.log'
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah", :cron_log => 'otherlog.log'
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command with the log syntax appended" do
|
|
|
|
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A command when the cron_log is set and the comand rejects it" do
|
|
|
|
setup do
|
2009-02-17 00:22:37 +00:00
|
|
|
@output = Whenever.cron \
|
2009-02-16 03:24:10 +00:00
|
|
|
<<-file
|
|
|
|
set :cron_log, 'logfile.log'
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah", :cron_log => false
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the command without the log syntax appended" do
|
|
|
|
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-02 10:26:15 +00:00
|
|
|
context "A command when the cron_log is set and is overridden by the :set option" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron :set => 'cron_log=otherlog.log', :string => \
|
|
|
|
<<-file
|
|
|
|
set :cron_log, 'logfile.log'
|
|
|
|
every 2.hours do
|
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the otherlog.log as the log file" do
|
|
|
|
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
|
|
|
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-16 03:24:10 +00:00
|
|
|
end
|