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,153 +1,147 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require File.expand_path(File.dirname(__FILE__) + "/../../lib/whenever/capistrano/support")
1
+ require 'test_helper'
2
+ require 'whenever/capistrano/v2/support'
3
3
 
4
4
  class CapistranoSupportTestSubject
5
5
  include Whenever::CapistranoSupport
6
6
  end
7
7
 
8
- class CapistranoSupportTest < Test::Unit::TestCase
9
- context "when using capistrano support module" do
10
- setup do
11
- @capistrano = CapistranoSupportTestSubject.new
12
- configuration = mock
13
- configuration.stubs(:load).yields(@capistrano)
14
- Whenever::CapistranoSupport.load_into(configuration)
15
- end
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
16
 
17
- context "#whenever_options" do
18
- should "return fetch(:whenever_options)" do
19
- @capistrano.expects(:fetch).with(:whenever_options)
20
- @capistrano.whenever_options
21
- end
22
- end
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
23
22
 
24
- context "#whenever_roles with one role" do
25
- setup do
26
- @capistrano.stubs(:whenever_options).returns({:roles => :role1})
27
- end
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
28
27
 
29
- should "return whenever_options[:roles] as an array" do
30
- assert_equal [:role1], @capistrano.whenever_roles
31
- end
32
- end
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
33
32
 
34
- context "#whenever_roles with no defined roles" do
35
- setup do
36
- @capistrano.stubs(:whenever_options).returns({})
37
- end
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])
38
36
 
39
- should "return an empty array" do
40
- assert_equal [], @capistrano.whenever_roles
41
- end
42
- end
37
+ assert_equal [:server1, :server2], @capistrano.whenever_servers
38
+ end
43
39
 
44
- context "#whenever_servers" do
45
- should "return the list of servers returned by find_servers" do
46
- @capistrano.stubs(:whenever_options).returns({})
47
- @capistrano.stubs(:find_servers).returns([:server1, :server2])
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
48
53
 
49
- assert_equal [:server1, :server2], @capistrano.whenever_servers
50
- end
54
+ should "#whenever_run_commands: require :command arg" do
55
+ assert_raises ArgumentError do
56
+ @capistrano.whenever_run_commands(:options => {}, :path => {}, :flags => {})
51
57
  end
58
+ end
52
59
 
53
- context "#whenever_server_roles" do
54
- setup do
55
- @mock_servers = ["foo", "bar"]
56
- @capistrano.stubs(:whenever_servers).returns(@mock_servers)
57
- end
58
-
59
- should "return a map of servers to their role(s)" do
60
- @capistrano.stubs(:whenever_roles).returns([:role1, :role2])
61
- @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1])
62
- @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
63
- assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
64
- end
65
-
66
- should "exclude non-requested roles" do
67
- @capistrano.stubs(:whenever_roles).returns([:role1, :role2])
68
- @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
69
- @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
70
- assert_equal({"foo" => [:role1], "bar" => [:role2]}, @capistrano.whenever_server_roles)
71
- end
72
-
73
- should "include all roles for servers w/ >1 when they're requested" do
74
- @capistrano.stubs(:whenever_roles).returns([:role1, :role2, :role3])
75
- @capistrano.stubs(:role_names_for_host).with("foo").returns([:role1, :role3])
76
- @capistrano.stubs(:role_names_for_host).with("bar").returns([:role2])
77
- assert_equal({"foo" => [:role1, :role3], "bar" => [:role2]}, @capistrano.whenever_server_roles)
78
- end
60
+ should "#whenever_run_commands: require :path arg" do
61
+ assert_raises ArgumentError do
62
+ @capistrano.whenever_run_commands(:options => {}, :command => {}, :flags => {})
79
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
80
72
 
81
- context "#whenever_run_commands" do
82
- should "require :command arg" do
83
- assert_raise ArgumentError do
84
- @capistrano.whenever_run_commands(:options => {}, :path => {}, :flags => {})
85
- end
86
- end
87
-
88
- should "require :path arg" do
89
- assert_raise ArgumentError do
90
- @capistrano.whenever_run_commands(:options => {}, :command => {}, :flags => {})
91
- end
92
- end
93
-
94
- should "require :flags arg" do
95
- assert_raise ArgumentError do
96
- @capistrano.whenever_run_commands(:options => {}, :path => {}, :command => {})
97
- end
98
- end
99
-
100
- context "with some servers defined" do
101
- setup do
102
- @mock_server1, @mock_server2, @mock_server3 = mock("Server1"), mock("Server2"), mock("Server3")
103
- @mock_server1.stubs(:host).returns("server1.foo.com")
104
- @mock_server2.stubs(:host).returns("server2.foo.com")
105
- @mock_server3.stubs(:host => "server3.foo.com", :port => 1022, :user => 'test')
106
- @mock_servers = [@mock_server1, @mock_server2]
107
- end
108
-
109
- should "call run for each host w/ appropriate role args" do
110
- @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1])
111
- @capistrano.stubs(:role_names_for_host).with(@mock_server2).returns([:role2])
112
- @capistrano.stubs(:whenever_servers).returns(@mock_servers)
113
- roles = [:role1, :role2]
114
- @capistrano.stubs(:whenever_options).returns({:roles => roles})
115
-
116
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1', {:roles => roles, :hosts => @mock_server1})
117
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role2', {:roles => roles, :hosts => @mock_server2})
118
-
119
- @capistrano.whenever_run_commands(:command => "whenever",
120
- :path => "/foo/bar",
121
- :flags => "--flag1 --flag2")
122
- end
123
-
124
- should "call run w/ all role args for servers w/ >1 role" do
125
- @capistrano.stubs(:role_names_for_host).with(@mock_server1).returns([:role1, :role3])
126
- @capistrano.stubs(:whenever_servers).returns([@mock_server1])
127
- roles = [:role1, :role2, :role3]
128
- @capistrano.stubs(:whenever_options).returns({:roles => roles})
129
-
130
- @capistrano.expects(:run).once.with('cd /foo/bar && whenever --flag1 --flag2 --roles role1,role3', {:roles => roles, :hosts => @mock_server1})
131
-
132
- @capistrano.whenever_run_commands(:command => "whenever",
133
- :path => "/foo/bar",
134
- :flags => "--flag1 --flag2")
135
- end
136
-
137
- should "call run w/ proper server options (port, user)" do
138
- @capistrano.stubs(:role_names_for_host).with(@mock_server3).returns([:role3])
139
- @capistrano.stubs(:whenever_servers).returns([@mock_server3])
140
- @capistrano.stubs(:whenever_options).returns({:roles => [:role3]})
141
-
142
- @capistrano.expects(:run).once.with do |command, options|
143
- options[:hosts].user == "test" && options[:hosts].port == 1022
144
- end
145
-
146
- @capistrano.whenever_run_commands(:command => "whenever",
147
- :path => "/foo/bar",
148
- :flags => "--flag1 --flag2")
149
- end
150
- end
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
151
141
  end
142
+
143
+ @capistrano.whenever_run_commands(:command => "whenever",
144
+ :path => "/foo/bar",
145
+ :flags => "--flag1 --flag2")
152
146
  end
153
147
  end