super-clean-box 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/super-clean-box.gemspec +12 -0
  3. data/whenever-1.1.2/Appraisals +69 -0
  4. data/whenever-1.1.2/CHANGELOG.md +434 -0
  5. data/whenever-1.1.2/CONTRIBUTING.md +38 -0
  6. data/whenever-1.1.2/Gemfile +11 -0
  7. data/whenever-1.1.2/LICENSE +22 -0
  8. data/whenever-1.1.2/Makefile +5 -0
  9. data/whenever-1.1.2/README.md +350 -0
  10. data/whenever-1.1.2/Rakefile +10 -0
  11. data/whenever-1.1.2/bin/whenever +49 -0
  12. data/whenever-1.1.2/bin/wheneverize +71 -0
  13. data/whenever-1.1.2/gemfiles/activesupport5.0.gemfile +11 -0
  14. data/whenever-1.1.2/gemfiles/activesupport5.1.gemfile +11 -0
  15. data/whenever-1.1.2/gemfiles/activesupport5.2.gemfile +11 -0
  16. data/whenever-1.1.2/gemfiles/activesupport6.0.gemfile +17 -0
  17. data/whenever-1.1.2/gemfiles/activesupport6.1.gemfile +17 -0
  18. data/whenever-1.1.2/gemfiles/activesupport7.0.gemfile +11 -0
  19. data/whenever-1.1.2/gemfiles/activesupport7.1.gemfile +11 -0
  20. data/whenever-1.1.2/gemfiles/activesupport7.2.gemfile +11 -0
  21. data/whenever-1.1.2/gemfiles/activesupport8.0.gemfile +11 -0
  22. data/whenever-1.1.2/gemfiles/activesupport8.1.gemfile +11 -0
  23. data/whenever-1.1.2/lib/whenever/capistrano/v2/hooks.rb +8 -0
  24. data/whenever-1.1.2/lib/whenever/capistrano/v2/recipes.rb +49 -0
  25. data/whenever-1.1.2/lib/whenever/capistrano/v2/support.rb +53 -0
  26. data/whenever-1.1.2/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
  27. data/whenever-1.1.2/lib/whenever/capistrano.rb +7 -0
  28. data/whenever-1.1.2/lib/whenever/command_line.rb +171 -0
  29. data/whenever-1.1.2/lib/whenever/cron.rb +181 -0
  30. data/whenever-1.1.2/lib/whenever/job.rb +56 -0
  31. data/whenever-1.1.2/lib/whenever/job_list.rb +186 -0
  32. data/whenever-1.1.2/lib/whenever/numeric.rb +13 -0
  33. data/whenever-1.1.2/lib/whenever/numeric_seconds.rb +48 -0
  34. data/whenever-1.1.2/lib/whenever/os.rb +7 -0
  35. data/whenever-1.1.2/lib/whenever/output_redirection.rb +57 -0
  36. data/whenever-1.1.2/lib/whenever/setup.rb +31 -0
  37. data/whenever-1.1.2/lib/whenever/version.rb +3 -0
  38. data/whenever-1.1.2/lib/whenever.rb +42 -0
  39. data/whenever-1.1.2/test/functional/command_line_test.rb +458 -0
  40. data/whenever-1.1.2/test/functional/output_at_test.rb +246 -0
  41. data/whenever-1.1.2/test/functional/output_default_defined_jobs_test.rb +310 -0
  42. data/whenever-1.1.2/test/functional/output_defined_job_test.rb +113 -0
  43. data/whenever-1.1.2/test/functional/output_description_test.rb +25 -0
  44. data/whenever-1.1.2/test/functional/output_env_test.rb +29 -0
  45. data/whenever-1.1.2/test/functional/output_jobs_for_roles_test.rb +65 -0
  46. data/whenever-1.1.2/test/functional/output_jobs_with_mailto_test.rb +168 -0
  47. data/whenever-1.1.2/test/functional/output_redirection_test.rb +248 -0
  48. data/whenever-1.1.2/test/test_case.rb +32 -0
  49. data/whenever-1.1.2/test/test_helper.rb +51 -0
  50. data/whenever-1.1.2/test/unit/capistrano_support_test.rb +147 -0
  51. data/whenever-1.1.2/test/unit/cron_test.rb +418 -0
  52. data/whenever-1.1.2/test/unit/executable_test.rb +142 -0
  53. data/whenever-1.1.2/test/unit/job_test.rb +114 -0
  54. data/whenever-1.1.2/whenever.gemspec +29 -0
  55. metadata +94 -0
@@ -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
@@ -0,0 +1,248 @@
1
+ require 'test_helper'
2
+
3
+ class OutputRedirectionTest < Whenever::TestCase
4
+ test "command when the output is set to nil" do
5
+ output = Whenever.cron \
6
+ <<-file
7
+ set :job_template, nil
8
+ set :output, nil
9
+ every 2.hours do
10
+ command "blahblah"
11
+ end
12
+ file
13
+
14
+ assert_match(/^.+ .+ .+ .+ blahblah >> \/dev\/null 2>&1$/, output)
15
+ end
16
+
17
+
18
+ test "command when the output is set" do
19
+ output = Whenever.cron \
20
+ <<-file
21
+ set :job_template, nil
22
+ set :output, 'logfile.log'
23
+ every 2.hours do
24
+ command "blahblah"
25
+ end
26
+ file
27
+
28
+ assert_match(/^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, output)
29
+ end
30
+
31
+ test "command when the error and standard output is set by the command" do
32
+ output = Whenever.cron \
33
+ <<-file
34
+ set :job_template, nil
35
+ every 2.hours do
36
+ command "blahblah", :output => {:standard => 'dev_null', :error => 'dev_err'}
37
+ end
38
+ file
39
+
40
+ assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
41
+ end
42
+
43
+ test "command when the output is set and the comand overrides it" do
44
+ output = Whenever.cron \
45
+ <<-file
46
+ set :job_template, nil
47
+ set :output, 'logfile.log'
48
+ every 2.hours do
49
+ command "blahblah", :output => 'otherlog.log'
50
+ end
51
+ file
52
+
53
+ assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
54
+ assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, output)
55
+ end
56
+
57
+ test "command when the output is set and the comand overrides with standard and error" do
58
+ output = Whenever.cron \
59
+ <<-file
60
+ set :job_template, nil
61
+ set :output, 'logfile.log'
62
+ every 2.hours do
63
+ command "blahblah", :output => {:error => 'dev_err', :standard => 'dev_null' }
64
+ end
65
+ file
66
+
67
+ assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
68
+ assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
69
+ end
70
+
71
+ test "command when the output is set and the comand rejects it" do
72
+ output = Whenever.cron \
73
+ <<-file
74
+ set :job_template, nil
75
+ set :output, 'logfile.log'
76
+ every 2.hours do
77
+ command "blahblah", :output => false
78
+ end
79
+ file
80
+
81
+ assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
82
+ assert_match(/^.+ .+ .+ .+ blahblah$/, output)
83
+ end
84
+
85
+ test "command when the output is set and is overridden by the :set option" do
86
+ output = Whenever.cron :set => 'output=otherlog.log', :string => \
87
+ <<-file
88
+ set :job_template, nil
89
+ set :output, 'logfile.log'
90
+ every 2.hours do
91
+ command "blahblah"
92
+ end
93
+ file
94
+
95
+ assert_no_match(/.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, output)
96
+ assert_match(/^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1/, output)
97
+ end
98
+
99
+ test "command when the error and standard output is set" do
100
+ output = Whenever.cron \
101
+ <<-file
102
+ set :job_template, nil
103
+ set :output, {:error => 'dev_err', :standard => 'dev_null' }
104
+ every 2.hours do
105
+ command "blahblah"
106
+ end
107
+ file
108
+
109
+ assert_match(/^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, output)
110
+ end
111
+
112
+ test "command when error output is set" do
113
+ output = Whenever.cron \
114
+ <<-file
115
+ set :job_template, nil
116
+ set :output, {:error => 'dev_null'}
117
+ every 2.hours do
118
+ command "blahblah"
119
+ end
120
+ file
121
+
122
+ assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_null$/, output)
123
+ end
124
+
125
+ test "command when the standard output is set" do
126
+ output = Whenever.cron \
127
+ <<-file
128
+ set :job_template, nil
129
+ set :output, {:standard => 'dev_out'}
130
+ every 2.hours do
131
+ command "blahblah"
132
+ end
133
+ file
134
+
135
+ assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)
136
+ end
137
+
138
+ test "command when error output is set by the command" do
139
+ output = Whenever.cron \
140
+ <<-file
141
+ set :job_template, nil
142
+ every 2.hours do
143
+ command "blahblah", :output => {:error => 'dev_err'}
144
+ end
145
+ file
146
+
147
+ assert_match(/^.+ .+ .+ .+ blahblah 2>> dev_err$/, output)
148
+ end
149
+
150
+ test "command when standard output is set by the command" do
151
+ output = Whenever.cron \
152
+ <<-file
153
+ set :job_template, nil
154
+ every 2.hours do
155
+ command "blahblah", :output => {:standard => 'dev_out'}
156
+ end
157
+ file
158
+
159
+ assert_match(/^.+ .+ .+ .+ blahblah >> dev_out$/, output)
160
+ end
161
+
162
+ test "command when standard output is set to nil" do
163
+ output = Whenever.cron \
164
+ <<-file
165
+ set :job_template, nil
166
+ every 2.hours do
167
+ command "blahblah", :output => {:standard => nil}
168
+ end
169
+ file
170
+
171
+ assert_match(/^.+ .+ .+ .+ blahblah > \/dev\/null$/, output)
172
+ end
173
+
174
+ test "command when standard error is set to nil" do
175
+ output = Whenever.cron \
176
+ <<-file
177
+ set :job_template, nil
178
+ every 2.hours do
179
+ command "blahblah", :output => {:error => nil}
180
+ end
181
+ file
182
+
183
+ assert_match(/^.+ .+ .+ .+ blahblah 2> \/dev\/null$/, output)
184
+ end
185
+
186
+ test "command when standard output and standard error is set to nil" do
187
+ output = Whenever.cron \
188
+ <<-file
189
+ set :job_template, nil
190
+ every 2.hours do
191
+ command "blahblah", :output => {:error => nil, :standard => nil}
192
+ end
193
+ file
194
+
195
+ assert_match(/^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, output)
196
+ end
197
+
198
+ test "command when standard output is set and standard error is set to nil" do
199
+ output = Whenever.cron \
200
+ <<-file
201
+ set :job_template, nil
202
+ every 2.hours do
203
+ command "blahblah", :output => {:error => nil, :standard => 'my.log'}
204
+ end
205
+ file
206
+
207
+ assert_match(/^.+ .+ .+ .+ blahblah >> my.log 2> \/dev\/null$/, output)
208
+ end
209
+
210
+ test "command when standard output is nil and standard error is set" do
211
+ output = Whenever.cron \
212
+ <<-file
213
+ set :job_template, nil
214
+ every 2.hours do
215
+ command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
216
+ end
217
+ file
218
+
219
+ assert_match(/^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, output)
220
+ end
221
+
222
+ test "command when the deprecated :cron_log is set" do
223
+ output = Whenever.cron \
224
+ <<-file
225
+ set :job_template, nil
226
+ set :cron_log, "cron.log"
227
+ every 2.hours do
228
+ command "blahblah"
229
+ end
230
+ file
231
+
232
+ assert_match(/^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, output)
233
+ end
234
+
235
+
236
+ test "a command when the standard output is set to a lambda" do
237
+ output = Whenever.cron \
238
+ <<-file
239
+ set :job_template, nil
240
+ set :output, lambda { "2>&1 | logger -t whenever_cron" }
241
+ every 2.hours do
242
+ command "blahblah"
243
+ end
244
+ file
245
+
246
+ assert_match(/^.+ .+ .+ .+ blahblah 2>&1 | logger -t whenever_cron$/, output)
247
+ end
248
+ end
@@ -0,0 +1,32 @@
1
+ module Whenever
2
+ require 'minitest/autorun'
3
+ begin
4
+ # 2.0.0
5
+ class TestCase < Minitest::Test; end
6
+ rescue NameError
7
+ # 1.9.3
8
+ class TestCase < Minitest::Unit::TestCase; end
9
+ end
10
+
11
+
12
+ class TestCase
13
+ class << self
14
+ def setup(&block)
15
+ define_method(:setup) do
16
+ super()
17
+ instance_eval(&block)
18
+ end
19
+ end
20
+
21
+ def test(name, &block)
22
+ define_method("test_#{name}".to_sym, &block)
23
+ end
24
+ alias should test
25
+ end
26
+
27
+ def assert_no_match(regexp, string)
28
+ message = "<#{regexp}> expected to not match\n<#{string}>"
29
+ assert regexp !~ string, message
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'whenever'
2
+ require 'test_case'
3
+ require 'mocha/minitest'
4
+ begin
5
+ require 'active_support/all'
6
+ rescue LoadError
7
+ end
8
+
9
+ module Whenever::TestHelpers
10
+ protected
11
+ def new_job(options={})
12
+ Whenever::Job.new(options)
13
+ end
14
+
15
+ def parse_time(time = nil, task = nil, at = nil, options = {})
16
+ Whenever::Output::Cron.new(time, task, at, options).time_in_cron_syntax
17
+ end
18
+
19
+ def two_hours
20
+ "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
21
+ end
22
+
23
+ def assert_months_and_days_and_hours_and_minutes_equals(expected, time, options = {})
24
+ cron = parse_time(Whenever.seconds(1, :year), 'some task', time, options)
25
+ minutes, hours, days, months = cron.split(' ')
26
+ assert_equal expected, [months, days, hours, minutes]
27
+ end
28
+
29
+ def assert_days_and_hours_and_minutes_equals(expected, time, options = {})
30
+ cron = parse_time(Whenever.seconds(2, :months), 'some task', time, options)
31
+ minutes, hours, days, _ = cron.split(' ')
32
+ assert_equal expected, [days, hours, minutes]
33
+ end
34
+
35
+ def assert_hours_and_minutes_equals(expected, time, options = {})
36
+ cron = parse_time(Whenever.seconds(2, :days), 'some task', time, options)
37
+ minutes, hours, _ = cron.split(' ')
38
+ assert_equal expected, [hours, minutes]
39
+ end
40
+
41
+ def assert_minutes_equals(expected, time, options = {})
42
+ cron = parse_time(Whenever.seconds(2, :hours), 'some task', time, options)
43
+ assert_equal expected, cron.split(' ')[0]
44
+ end
45
+
46
+ def lines_without_empty_line(lines)
47
+ lines.map { |line| line.chomp }.reject { |line| line.empty? }
48
+ end
49
+ end
50
+
51
+ Whenever::TestCase.send(:include, Whenever::TestHelpers)
@@ -0,0 +1,147 @@
1
+ require 'test_helper'
2
+ require 'whenever/capistrano/v2/support'
3
+
4
+ class CapistranoSupportTestSubject
5
+ include Whenever::CapistranoSupport
6
+ end
7
+
8
+ class CapistranoTestCase < Whenever::TestCase
9
+ setup do
10
+ @capistrano = CapistranoSupportTestSubject.new
11
+ configuration = mock()
12
+ configuration.stubs(:load).yields(@capistrano)
13
+ Whenever::CapistranoSupport.load_into(configuration)
14
+ end
15
+ end
16
+
17
+ class CapistranoSupportTest < CapistranoTestCase
18
+ should "return fetch(:whenever_options) from #whenever_options" do
19
+ @capistrano.expects(:fetch).with(:whenever_options)
20
+ @capistrano.whenever_options
21
+ end
22
+
23
+ should "return whenever_options[:roles] as an array from #whenever_roles with one role" do
24
+ @capistrano.stubs(:whenever_options).returns({:roles => :role1})
25
+ assert_equal [:role1], @capistrano.whenever_roles
26
+ end
27
+
28
+ should "return an empty array from #whenever_roles with no defined roles" do
29
+ @capistrano.stubs(:whenever_options).returns({})
30
+ assert_equal [], @capistrano.whenever_roles
31
+ end
32
+
33
+ should "return the list of servers returned by find_servers from #whenever_servers" do
34
+ @capistrano.stubs(:whenever_options).returns({})
35
+ @capistrano.stubs(:find_servers).returns([:server1, :server2])
36
+
37
+ assert_equal [:server1, :server2], @capistrano.whenever_servers
38
+ end
39
+
40
+ should "#whenever_prepare_for_rollback: set path to previous_release if there is a previous release" do
41
+ args = {}
42
+ @capistrano.stubs(:fetch).with(:previous_release).returns("/some/path/20121221010000")
43
+ assert_equal({:path => "/some/path/20121221010000"}, @capistrano.whenever_prepare_for_rollback(args))
44
+ end
45
+
46
+ should "#whenever_prepare_for_rollback: set path to release_path and flags to whenever_clear_flags if there is no previous release" do
47
+ args = {}
48
+ @capistrano.stubs(:fetch).with(:previous_release).returns(nil)
49
+ @capistrano.stubs(:fetch).with(:release_path).returns("/some/path/20121221010000")
50
+ @capistrano.stubs(:fetch).with(:whenever_clear_flags).returns("--clear-crontab whenever_identifier")
51
+ assert_equal({:path => "/some/path/20121221010000", :flags => "--clear-crontab whenever_identifier"}, @capistrano.whenever_prepare_for_rollback(args))
52
+ end
53
+
54
+ should "#whenever_run_commands: require :command arg" do
55
+ assert_raises ArgumentError do
56
+ @capistrano.whenever_run_commands(:options => {}, :path => {}, :flags => {})
57
+ end
58
+ end
59
+
60
+ should "#whenever_run_commands: require :path arg" do
61
+ assert_raises ArgumentError do
62
+ @capistrano.whenever_run_commands(:options => {}, :command => {}, :flags => {})
63
+ end
64
+ end
65
+
66
+ should "#whenever_run_commands: require :flags arg" do
67
+ assert_raises ArgumentError do
68
+ @capistrano.whenever_run_commands(:options => {}, :path => {}, :command => {})
69
+ end
70
+ end
71
+ end
72
+
73
+ class ServerRolesTest < CapistranoTestCase
74
+ setup do
75
+ @mock_servers = ["foo", "bar"]
76
+ @capistrano.stubs(:whenever_servers).returns(@mock_servers)
77
+
78
+ @mock_server1, @mock_server2, @mock_server3 = mock("Server1"), mock("Server2"), mock("Server3")
79
+ @mock_server1.stubs(:host).returns("server1.foo.com")
80
+ @mock_server2.stubs(:host).returns("server2.foo.com")
81
+ @mock_server3.stubs(:host => "server3.foo.com", :port => 1022, :user => 'test')
82
+ @mock_servers = [@mock_server1, @mock_server2]
83
+ end
84
+
85
+ should "return a map of servers to their role(s)" do
86
+ @capistrano.stubs(:whenever_roles).returns([:role1, :role2])
87
+ @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1])
88
+ @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
89
+ assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
90
+ end
91
+
92
+ should "exclude non-requested roles" do
93
+ @capistrano.stubs(:whenever_roles).returns([:role1, :role2])
94
+ @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
95
+ @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
96
+ assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
97
+ end
98
+
99
+ should "include all roles for servers w/ >1 when they're requested" do
100
+ @capistrano.stubs(:whenever_roles).returns([:role1, :role2, :role3])
101
+ @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
102
+ @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
103
+ assert_equal({"foo" => [:role1, :role3], "bar" => [:role2]}, @capistrano.whenever_server_roles)
104
+ end
105
+
106
+ should "call run for each host w/ appropriate role args" do
107
+ @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1])
108
+ @capistrano.stubs(:role_names_for_host).with(@mock_server2).returns([:role2])
109
+ @capistrano.stubs(:whenever_servers).returns(@mock_servers)
110
+ roles = [:role1, :role2]
111
+ @capistrano.stubs(:whenever_options).returns({:roles => roles})
112
+
113
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => roles, :hosts => @mock_server1})
114
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => roles, :hosts => @mock_server2})
115
+
116
+ @capistrano.whenever_run_commands(:command => "whenever",
117
+ :path => "/foo/bar",
118
+ :flags => "--flag1 --flag2")
119
+ end
120
+
121
+ should "call run w/ all role args for servers w/ >1 role" do
122
+ @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1, :role3])
123
+ @capistrano.stubs(:whenever_servers).returns([@mock_server1])
124
+ roles = [:role1, :role2, :role3]
125
+ @capistrano.stubs(:whenever_options).returns({:roles => roles})
126
+
127
+ @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => roles, :hosts => @mock_server1})
128
+
129
+ @capistrano.whenever_run_commands(:command => "whenever",
130
+ :path => "/foo/bar",
131
+ :flags => "--flag1 --flag2")
132
+ end
133
+
134
+ should "call run w/ proper server options (port, user)" do
135
+ @capistrano.stubs(:role_names_for_host).with(@mock_server3).returns([:role3])
136
+ @capistrano.stubs(:whenever_servers).returns([@mock_server3])
137
+ @capistrano.stubs(:whenever_options).returns({:roles => [:role3]})
138
+
139
+ @capistrano.expects(:run).once.with do |command, options|
140
+ options[:hosts].user == "test" && options[:hosts].port == 1022
141
+ end
142
+
143
+ @capistrano.whenever_run_commands(:command => "whenever",
144
+ :path => "/foo/bar",
145
+ :flags => "--flag1 --flag2")
146
+ end
147
+ end