merb_whenever 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,209 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class OutputRunnerTest < Test::Unit::TestCase
4
+
5
+ context "A runner with path set" do
6
+ setup do
7
+ @output = Whenever.cron \
8
+ <<-file
9
+ set :path, '/my/path'
10
+ every 2.hours do
11
+ runner "blahblah"
12
+ end
13
+ file
14
+ end
15
+
16
+ should "output the runner using that path" do
17
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
18
+ end
19
+ end
20
+
21
+ context "A runner that overrides the path set" do
22
+ setup do
23
+ @output = Whenever.cron \
24
+ <<-file
25
+ set :path, '/my/path'
26
+ every 2.hours do
27
+ runner "blahblah", :path => '/some/other/path'
28
+ end
29
+ file
30
+ end
31
+
32
+ should "output the runner using that path" do
33
+ assert_match two_hours + ' /some/other/path/script/runner -e production "blahblah"', @output
34
+ end
35
+ end
36
+
37
+ context "A runner with no path set and RAILS_ROOT defined" do
38
+ setup do
39
+ Whenever.stubs(:path).returns('/my/path')
40
+
41
+ @output = Whenever.cron \
42
+ <<-file
43
+ every 2.hours do
44
+ runner "blahblah"
45
+ end
46
+ file
47
+ end
48
+
49
+ should "output the runner using that path" do
50
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
51
+ end
52
+ end
53
+
54
+ context "A runner with path set AND RAILS_ROOT defined" do
55
+ setup do
56
+ Whenever.stubs(:path).returns('/my/rails/path')
57
+
58
+ @output = Whenever.cron \
59
+ <<-file
60
+ set :path, '/my/path'
61
+ every 2.hours do
62
+ runner "blahblah"
63
+ end
64
+ file
65
+ end
66
+
67
+ should "use the path" do
68
+ assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
69
+ assert_no_match /\/rails\/path/, @output
70
+ end
71
+ end
72
+
73
+ context "A runner with no path set and no RAILS_ROOT defined" do
74
+ setup do
75
+ Whenever.stubs(:path).returns(nil)
76
+
77
+ @input = <<-file
78
+ every 2.hours do
79
+ runner "blahblah"
80
+ end
81
+ file
82
+ end
83
+
84
+ should "raise an exception" do
85
+ assert_raises ArgumentError do
86
+ Whenever.cron(@input)
87
+ end
88
+ end
89
+ end
90
+
91
+ context "A runner with an environment set" do
92
+ setup do
93
+ @output = Whenever.cron \
94
+ <<-file
95
+ set :environment, :silly
96
+ set :path, '/my/path'
97
+ every 2.hours do
98
+ runner "blahblah"
99
+ end
100
+ file
101
+ end
102
+
103
+ should "output the runner using that environment" do
104
+ assert_match two_hours + ' /my/path/script/runner -e silly "blahblah"', @output
105
+ end
106
+ end
107
+
108
+ context "A runner that overrides the environment set" do
109
+ setup do
110
+ @output = Whenever.cron \
111
+ <<-file
112
+ set :environment, :silly
113
+ set :path, '/my/path'
114
+ every 2.hours do
115
+ runner "blahblah", :environment => :serious
116
+ end
117
+ file
118
+ end
119
+
120
+ should "output the runner using that environment" do
121
+ assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
122
+ end
123
+ end
124
+
125
+ context "A runner where the environment is overridden using the :set option" do
126
+ setup do
127
+ @output = Whenever.cron :set => 'environment=serious', :string => \
128
+ <<-file
129
+ set :environment, :silly
130
+ set :path, '/my/path'
131
+ every 2.hours do
132
+ runner "blahblah"
133
+ end
134
+ file
135
+ end
136
+
137
+ should "output the runner using the override environment" do
138
+ assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
139
+ end
140
+ end
141
+
142
+ context "A runner where the environment and path are overridden using the :set option" do
143
+ setup do
144
+ @output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
145
+ <<-file
146
+ set :environment, :silly
147
+ set :path, '/silly/path'
148
+ every 2.hours do
149
+ runner "blahblah"
150
+ end
151
+ file
152
+ end
153
+
154
+ should "output the runner using the overridden path and environment" do
155
+ assert_match two_hours + ' /serious/path/script/runner -e serious "blahblah"', @output
156
+ end
157
+ end
158
+
159
+ context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
160
+ setup do
161
+ @output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
162
+ <<-file
163
+ set :environment, :silly
164
+ set :path, '/silly/path'
165
+ every 2.hours do
166
+ runner "blahblah"
167
+ end
168
+ file
169
+ end
170
+
171
+ should "output the runner using the overridden path and environment" do
172
+ assert_match two_hours + ' /serious/path/script/runner -e serious "blahblah"', @output
173
+ end
174
+ end
175
+
176
+ context "A runner where the environment is overridden using the :set option but no value is given" do
177
+ setup do
178
+ @output = Whenever.cron :set => ' environment=', :string => \
179
+ <<-file
180
+ set :environment, :silly
181
+ set :path, '/silly/path'
182
+ every 2.hours do
183
+ runner "blahblah"
184
+ end
185
+ file
186
+ end
187
+
188
+ should "output the runner using the original environmnet" do
189
+ assert_match two_hours + ' /silly/path/script/runner -e silly "blahblah"', @output
190
+ end
191
+ end
192
+
193
+ context "A runner which makes use of double quotes" do
194
+ setup do
195
+ @output = Whenever.cron \
196
+ <<-file
197
+ set :path, '/my/path'
198
+ every 2.hours do
199
+ runner 'Product.import("http://example.com/product.xml")'
200
+ end
201
+ file
202
+ end
203
+
204
+ should "output the runner using the original environmnet" do
205
+ assert_match two_hours + ' /my/path/script/runner -e production "Product.import(\"http://example.com/product.xml\")"', @output
206
+ end
207
+ end
208
+
209
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/whenever")
5
+
6
+ begin
7
+ require 'shoulda'
8
+ rescue LoadError
9
+ warn 'To test Whenever you need the shoulda gem:'
10
+ warn '$ sudo gem install thoughtbot-shoulda'
11
+ exit(1)
12
+ end
13
+
14
+ begin
15
+ require 'mocha'
16
+ rescue LoadError
17
+ warn 'To test Whenever you need the mocha gem:'
18
+ warn '$ sudo gem install mocha'
19
+ exit(1)
20
+ end
21
+
22
+
23
+ module TestExtensions
24
+
25
+ def two_hours
26
+ "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
27
+ end
28
+
29
+ end
30
+
31
+ class Test::Unit::TestCase
32
+ include TestExtensions
33
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_whenever
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Javan Makhmali
8
+ - Roberto Thais
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-11-30 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: chronic
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.2.3
25
+ version:
26
+ description: Clean ruby syntax for defining and deploying messy cron jobs. Modified for use with merb
27
+ email: javan@javan.us
28
+ executables:
29
+ - whenever
30
+ - wheneverize
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ files:
36
+ - .gitignore
37
+ - CHANGELOG.rdoc
38
+ - README.rdoc
39
+ - Rakefile
40
+ - bin/whenever
41
+ - bin/wheneverize
42
+ - lib/merb_whenever.rb
43
+ - lib/whenever/base.rb
44
+ - lib/whenever/command_line.rb
45
+ - lib/whenever/job_list.rb
46
+ - lib/whenever/job_types/default.rb
47
+ - lib/whenever/job_types/rake_task.rb
48
+ - lib/whenever/job_types/runner.rb
49
+ - lib/whenever/outputs/cron.rb
50
+ - lib/whenever/outputs/cron/output_redirection.rb
51
+ - lib/whenever/version.rb
52
+ - test/command_line_test.rb
53
+ - test/cron_test.rb
54
+ - test/output_at_test.rb
55
+ - test/output_command_test.rb
56
+ - test/output_env_test.rb
57
+ - test/output_rake_test.rb
58
+ - test/output_redirection_test.rb
59
+ - test/output_runner_test.rb
60
+ - test/test_helper.rb
61
+ - merb_whenever.gemspec
62
+ has_rdoc: true
63
+ homepage: http://github.com/javan/whenever
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Clean ruby syntax for defining and deploying messy cron jobs.
90
+ test_files:
91
+ - test/command_line_test.rb
92
+ - test/cron_test.rb
93
+ - test/output_at_test.rb
94
+ - test/output_command_test.rb
95
+ - test/output_env_test.rb
96
+ - test/output_rake_test.rb
97
+ - test/output_redirection_test.rb
98
+ - test/output_runner_test.rb
99
+ - test/test_helper.rb