/
output_defined_job_test.rb
111 lines (96 loc) · 2.96 KB
/
output_defined_job_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
class OutputDefinedJobTest < Test::Unit::TestCase
context "A defined job with a :task" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
job_type :some_job, "before :task after"
every 2.hours do
some_job "during"
end
file
end
should "output the defined job with the task" do
assert_match /^.+ .+ .+ .+ before during after$/, @output
end
end
context "A defined job with a :task and some options" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
job_type :some_job, "before :task after :option1 :option2"
every 2.hours do
some_job "during", :option1 => 'happy', :option2 => 'birthday'
end
file
end
should "output the defined job with the task and options" do
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, @output
end
end
context "A defined job with a :task and an option where the option is set globally" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
job_type :some_job, "before :task after :option1"
set :option1, 'happy'
every 2.hours do
some_job "during"
end
file
end
should "output the defined job with the task and options" do
assert_match /^.+ .+ .+ .+ before during after happy$/, @output
end
end
context "A defined job with a :task and an option where the option is set globally and locally" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
job_type :some_job, "before :task after :option1"
set :option1, 'global'
every 2.hours do
some_job "during", :option1 => 'local'
end
file
end
should "output the defined job using the local option" do
assert_match /^.+ .+ .+ .+ before during after local$/, @output
end
end
context "A defined job with a :task and an option that is not set" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
job_type :some_job, "before :task after :option1"
every 2.hours do
some_job "during", :option2 => 'happy'
end
file
end
should "output the defined job with that option left untouched" do
assert_match /^.+ .+ .+ .+ before during after :option1$/, @output
end
end
context "A defined job that uses a :path where none is explicitly set" do
setup do
Whenever.stubs(:path).returns('/my/path')
@output = Whenever.cron \
<<-file
set :job_template, nil
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