whenever 0.8.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +20 -7
  4. data/Appraisals +19 -0
  5. data/CHANGELOG.md +116 -3
  6. data/Gemfile +3 -3
  7. data/LICENSE +2 -2
  8. data/README.md +133 -32
  9. data/Rakefile +3 -10
  10. data/bin/whenever +3 -0
  11. data/bin/wheneverize +8 -5
  12. data/gemfiles/activesupport4.1.gemfile +7 -0
  13. data/gemfiles/activesupport4.2.gemfile +7 -0
  14. data/gemfiles/activesupport5.0.gemfile +7 -0
  15. data/gemfiles/activesupport5.1.gemfile +7 -0
  16. data/gemfiles/activesupport5.2.gemfile +7 -0
  17. data/lib/whenever/capistrano/v2/hooks.rb +8 -0
  18. data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
  19. data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
  20. data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
  21. data/lib/whenever/capistrano.rb +5 -6
  22. data/lib/whenever/command_line.rb +69 -48
  23. data/lib/whenever/cron.rb +54 -25
  24. data/lib/whenever/job.rb +13 -14
  25. data/lib/whenever/job_list.rb +54 -24
  26. data/lib/whenever/numeric.rb +13 -0
  27. data/lib/whenever/numeric_seconds.rb +48 -0
  28. data/lib/whenever/os.rb +7 -0
  29. data/lib/whenever/output_redirection.rb +1 -0
  30. data/lib/whenever/setup.rb +19 -15
  31. data/lib/whenever/version.rb +2 -2
  32. data/lib/whenever.rb +19 -14
  33. data/test/functional/command_line_test.rb +379 -243
  34. data/test/functional/output_at_test.rb +227 -249
  35. data/test/functional/output_default_defined_jobs_test.rb +251 -193
  36. data/test/functional/output_defined_job_test.rb +65 -91
  37. data/test/functional/output_env_test.rb +22 -26
  38. data/test/functional/output_jobs_for_roles_test.rb +46 -65
  39. data/test/functional/output_jobs_with_mailto_test.rb +168 -0
  40. data/test/functional/output_redirection_test.rb +232 -291
  41. data/test/test_case.rb +32 -0
  42. data/test/test_helper.rb +44 -15
  43. data/test/unit/capistrano_support_test.rb +128 -134
  44. data/test/unit/cron_test.rb +373 -208
  45. data/test/unit/executable_test.rb +142 -0
  46. data/test/unit/job_test.rb +111 -117
  47. data/whenever.gemspec +7 -4
  48. metadata +63 -44
@@ -1,33 +1,29 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
1
+ require 'test_helper'
2
2
 
3
- class OutputEnvTest < Test::Unit::TestCase
4
-
5
- context "The output from Whenever with environment variables set" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- env :MYVAR, 'blah'
10
- env 'MAILTO', "someone@example.com"
11
- env :BLANKVAR, ''
12
- env :NILVAR, nil
13
- file
14
- end
3
+ class OutputEnvTest < Whenever::TestCase
4
+ setup do
5
+ @output = Whenever.cron \
6
+ <<-file
7
+ env :MYVAR, 'blah'
8
+ env 'MAILTO', "someone@example.com"
9
+ env :BLANKVAR, ''
10
+ env :NILVAR, nil
11
+ file
12
+ end
15
13
 
16
- should "output MYVAR environment variable" do
17
- assert_match "MYVAR=blah", @output
18
- end
19
-
20
- should "output MAILTO environment variable" do
21
- assert_match "MAILTO=someone@example.com", @output
22
- end
14
+ should "output MYVAR environment variable" do
15
+ assert_match "MYVAR=blah", @output
16
+ end
23
17
 
24
- should "output BLANKVAR environment variable" do
25
- assert_match "BLANKVAR=\"\"", @output
26
- end
18
+ should "output MAILTO environment variable" do
19
+ assert_match "MAILTO=someone@example.com", @output
20
+ end
27
21
 
28
- should "output NILVAR environment variable" do
29
- assert_match "NILVAR=\"\"", @output
30
- end
22
+ should "output BLANKVAR environment variable" do
23
+ assert_match "BLANKVAR=\"\"", @output
31
24
  end
32
25
 
26
+ should "output NILVAR environment variable" do
27
+ assert_match "NILVAR=\"\"", @output
28
+ end
33
29
  end
@@ -1,84 +1,65 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
1
+ require 'test_helper'
2
2
 
3
- class OutputJobsForRolesTest < Test::Unit::TestCase
4
- context "with one role requested and specified on the job" do
5
- setup do
6
- @output = Whenever.cron :roles => [:role1], :string => \
7
- <<-file
8
- every 2.hours, :roles => [:role1] do
9
- command "blahblah"
10
- end
11
- file
12
- end
3
+ class OutputJobsForRolesTest < Whenever::TestCase
4
+ test "one role requested and specified on the job" do
5
+ output = Whenever.cron :roles => [:role1], :string => \
6
+ <<-file
7
+ every 2.hours, :roles => [:role1] do
8
+ command "blahblah"
9
+ end
10
+ file
13
11
 
14
- should "output the cron job" do
15
- assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
16
- end
12
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
17
13
  end
18
14
 
19
- context "with one role requested but none specified on the job" do
20
- setup do
21
- @output = Whenever.cron :roles => [:role1], :string => \
22
- <<-file
23
- every 2.hours do
24
- command "blahblah"
25
- end
26
- file
27
- end
15
+ test "one role requested but none specified on the job" do
16
+ output = Whenever.cron :roles => [:role1], :string => \
17
+ <<-file
18
+ every 2.hours do
19
+ command "blahblah"
20
+ end
21
+ file
28
22
 
29
23
  # this should output the job because not specifying a role means "all roles"
30
- should "output the cron job" do
31
- assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
32
- end
24
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
33
25
  end
34
26
 
35
- context "with no roles requested but one specified on the job" do
36
- setup do
37
- @output = Whenever.cron \
38
- <<-file
39
- every 2.hours, :roles => [:role1] do
40
- command "blahblah"
41
- end
42
- file
43
- end
27
+ test "no roles requested but one specified on the job" do
28
+ output = Whenever.cron \
29
+ <<-file
30
+ every 2.hours, :roles => [:role1] do
31
+ command "blahblah"
32
+ end
33
+ file
44
34
 
45
35
  # this should output the job because not requesting roles means "all roles"
46
- should "output the cron job" do
47
- assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", @output
48
- end
36
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'\n\n", output
49
37
  end
50
38
 
51
- context "with a different role requested than the one specified on the job" do
52
- setup do
53
- @output = Whenever.cron :roles => [:role1], :string => \
54
- <<-file
55
- every 2.hours, :roles => [:role2] do
56
- command "blahblah"
57
- end
58
- file
59
- end
39
+ test "a different role requested than the one specified on the job" do
40
+ output = Whenever.cron :roles => [:role1], :string => \
41
+ <<-file
42
+ every 2.hours, :roles => [:role2] do
43
+ command "blahblah"
44
+ end
45
+ file
60
46
 
61
- should "not output the cron job" do
62
- assert_equal "", @output
63
- end
47
+ assert_equal "", output
64
48
  end
65
49
 
66
- context "with 2 roles requested and a job defined for each" do
67
- setup do
68
- @output = Whenever.cron :roles => [:role1, :role2], :string => \
69
- <<-file
70
- every 2.hours, :roles => [:role1] do
71
- command "role1_cmd"
72
- end
50
+ test "with 2 roles requested and a job defined for each" do
51
+ output = Whenever.cron :roles => [:role1, :role2], :string => \
52
+ <<-file
53
+ every 2.hours, :roles => [:role1] do
54
+ command "role1_cmd"
55
+ end
73
56
 
74
- every :hour, :roles => [:role2] do
75
- command "role2_cmd"
76
- end
77
- file
78
- end
57
+ every :hour, :roles => [:role2] do
58
+ command "role2_cmd"
59
+ end
60
+ file
79
61
 
80
- should "output both jobs" do
81
- assert_equal two_hours + " /bin/bash -l -c 'role1_cmd'\n\n0 * * * * /bin/bash -l -c 'role2_cmd'\n\n", @output
82
- end
62
+ assert_match two_hours + " /bin/bash -l -c 'role1_cmd'", output
63
+ assert_match "0 * * * * /bin/bash -l -c 'role2_cmd'", output
83
64
  end
84
65
  end
@@ -0,0 +1,168 @@
1
+ require 'test_helper'
2
+
3
+ class OutputJobsWithMailtoTest < Whenever::TestCase
4
+ test "defined job with a mailto argument" do
5
+ output = Whenever.cron \
6
+ <<-file
7
+ every 2.hours do
8
+ command "blahblah", mailto: 'someone@example.com'
9
+ end
10
+ file
11
+
12
+ output_without_empty_line = lines_without_empty_line(output.lines)
13
+
14
+ assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
15
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
16
+ end
17
+
18
+ test "defined job with every method's block and a mailto argument" do
19
+ output = Whenever.cron \
20
+ <<-file
21
+ every 2.hours, mailto: 'someone@example.com' do
22
+ command "blahblah"
23
+ end
24
+ file
25
+
26
+ output_without_empty_line = lines_without_empty_line(output.lines)
27
+
28
+ assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
29
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
30
+ end
31
+
32
+ test "defined job which overrided mailto argument in the block" do
33
+ output = Whenever.cron \
34
+ <<-file
35
+ every 2.hours, mailto: 'of_the_block@example.com' do
36
+ command "blahblah", mailto: 'overrided_in_the_block@example.com'
37
+ end
38
+ file
39
+
40
+ output_without_empty_line = lines_without_empty_line(output.lines)
41
+
42
+ assert_equal 'MAILTO=overrided_in_the_block@example.com', output_without_empty_line.shift
43
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
44
+ end
45
+
46
+ test "defined some jobs with various mailto argument" do
47
+ output = Whenever.cron \
48
+ <<-file
49
+ every 2.hours do
50
+ command "blahblah"
51
+ end
52
+
53
+ every 2.hours, mailto: 'john@example.com' do
54
+ command "blahblah_of_john"
55
+ command "blahblah2_of_john"
56
+ end
57
+
58
+ every 2.hours, mailto: 'sarah@example.com' do
59
+ command "blahblah_of_sarah"
60
+ end
61
+
62
+ every 2.hours do
63
+ command "blahblah_of_martin", mailto: 'martin@example.com'
64
+ command "blahblah2_of_sarah", mailto: 'sarah@example.com'
65
+ end
66
+
67
+ every 2.hours do
68
+ command "blahblah2"
69
+ end
70
+ file
71
+
72
+ output_without_empty_line = lines_without_empty_line(output.lines)
73
+
74
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
75
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
76
+
77
+ assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
78
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
79
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
80
+
81
+ assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
82
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_sarah'", output_without_empty_line.shift
83
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_sarah'", output_without_empty_line.shift
84
+
85
+ assert_equal 'MAILTO=martin@example.com', output_without_empty_line.shift
86
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_martin'", output_without_empty_line.shift
87
+ end
88
+
89
+ test "defined some jobs with no mailto argument jobs and mailto argument jobs(no mailto jobs should be first line of cron output" do
90
+ output = Whenever.cron \
91
+ <<-file
92
+ every 2.hours, mailto: 'john@example.com' do
93
+ command "blahblah_of_john"
94
+ command "blahblah2_of_john"
95
+ end
96
+
97
+ every 2.hours do
98
+ command "blahblah"
99
+ end
100
+ file
101
+
102
+ output_without_empty_line = lines_without_empty_line(output.lines)
103
+
104
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
105
+
106
+ assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
107
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
108
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
109
+ end
110
+
111
+ test "defined some jobs with environment mailto define and various mailto argument" do
112
+ output = Whenever.cron \
113
+ <<-file
114
+ env 'MAILTO', 'default@example.com'
115
+
116
+ every 2.hours do
117
+ command "blahblah"
118
+ end
119
+
120
+ every 2.hours, mailto: 'sarah@example.com' do
121
+ command "blahblah_by_sarah"
122
+ end
123
+
124
+ every 2.hours do
125
+ command "blahblah_by_john", mailto: 'john@example.com'
126
+ end
127
+
128
+ every 2.hours do
129
+ command "blahblah2"
130
+ end
131
+ file
132
+
133
+ output_without_empty_line = lines_without_empty_line(output.lines)
134
+
135
+ assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
136
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
137
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
138
+
139
+ assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
140
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_sarah'", output_without_empty_line.shift
141
+
142
+ assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
143
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_john'", output_without_empty_line.shift
144
+ end
145
+ end
146
+
147
+ class OutputJobsWithMailtoForRolesTest < Whenever::TestCase
148
+ test "one role requested and specified on the job with mailto argument" do
149
+ output = Whenever.cron roles: [:role1], :string => \
150
+ <<-file
151
+ env 'MAILTO', 'default@example.com'
152
+
153
+ every 2.hours, :roles => [:role1] do
154
+ command "blahblah"
155
+ end
156
+
157
+ every 2.hours, mailto: 'sarah@example.com', :roles => [:role2] do
158
+ command "blahblah_by_sarah"
159
+ end
160
+ file
161
+
162
+ output_without_empty_line = lines_without_empty_line(output.lines)
163
+
164
+ assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
165
+ assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
166
+ assert_nil output_without_empty_line.shift
167
+ end
168
+ end