whenever 0.5.0 → 0.5.2

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.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  pkg
3
- doc
3
+ doc
4
+ .*.sw[a-z]
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.5.2 / September 15th, 2010
2
+
3
+ * Quotes automatically escaped in jobs. [Jay Adkisson]
4
+
5
+ * Added --cut option to the command line to allow pruning of the crontab. [Peer Allan]
6
+
7
+ * Switched to aaronh-chronic which is ruby 1.9.2 compatible. [Aaron Hurley, Javan Makhmali]
8
+
9
+ * Lots of internal reorganizing; tests broken into unit and functional. [Javan Makhmali]
10
+
11
+
1
12
  == 0.5.0 / June 28th, 2010
2
13
 
3
14
  * New job_type API for writing custom jobs. Internals use this to define command, runner, and rake. [Javan Makhmali - inspired by idlefingers (Damien)]
data/README.rdoc CHANGED
@@ -55,9 +55,9 @@ Would run <code>/usr/local/bin/awesome party extreme</code> every two hours. <co
55
55
 
56
56
  The default job types that ship with Whenever are defined like so:
57
57
 
58
- job_type :command, ':task'
59
- job_type :runner, 'cd :path && script/runner -e :environment ":task"'
60
- job_type :rake, 'cd :path && RAILS_ENV=:environment /usr/bin/env rake :task'
58
+ job_type :command, ":task"
59
+ job_type :runner, "cd :path && script/runner -e :environment ':task'"
60
+ job_type :rake, "cd :path && RAILS_ENV=:environment /usr/bin/env rake :task"
61
61
 
62
62
  If a <code>:path</code> is not set it will default to the directory in which <code>whenever</code> was executed. <code>:environment</code> will default to 'production'.
63
63
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- require 'lib/whenever/version.rb'
4
+ require File.expand_path(File.dirname(__FILE__) + "/lib/whenever/version")
5
5
 
6
6
  begin
7
7
  require 'jeweler'
@@ -13,7 +13,10 @@ begin
13
13
  gemspec.email = "javan@javan.us"
14
14
  gemspec.homepage = "http://github.com/javan/whenever"
15
15
  gemspec.authors = ["Javan Makhmali"]
16
- gemspec.add_dependency("chronic", '>= 0.2.3')
16
+ gemspec.add_dependency 'aaronh-chronic', '>= 0.3.9'
17
+ gemspec.add_dependency 'activesupport', '>= 2.3.4'
18
+ gemspec.add_development_dependency 'shoulda', '>= 2.1.1'
19
+ gemspec.add_development_dependency 'mocha', '>= 0.9.5'
17
20
  end
18
21
  Jeweler::GemcutterTasks.new
19
22
  rescue LoadError
@@ -22,10 +25,10 @@ end
22
25
 
23
26
  require 'rake/testtask'
24
27
  Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/*.rb'
27
- test.verbose = true
28
- end
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/{functional,unit}/**/*_test.rb'
30
+ test.verbose = true
31
+ end
29
32
 
30
33
  task :test => :check_dependencies
31
34
 
data/bin/whenever CHANGED
@@ -10,6 +10,9 @@ OptionParser.new do |opts|
10
10
  opts.banner = "Usage: whenever [options]"
11
11
  opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
12
12
  opts.on('-w', '--write-crontab') { options[:write] = true }
13
+ opts.on('-c', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
14
+ options[:cut] = lines.to_i if lines
15
+ end
13
16
  opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
14
17
  options[:update] = true
15
18
  options[:identifier] = identifier if identifier
data/lib/whenever.rb CHANGED
@@ -1,20 +1,10 @@
1
1
  require 'chronic'
2
+ require 'active_support/all'
2
3
 
3
- # It was previously defined as a dependency of this gem, but that became
4
- # problematic. See: http://github.com/javan/whenever/issues#issue/1
5
- begin
6
- require 'active_support/all'
7
- rescue LoadError
8
- warn 'To use Whenever you need the active_support gem:'
9
- warn '$ gem install activesupport'
10
- exit(1)
11
- end
12
-
13
- # Whenever files
14
4
  require 'whenever/base'
15
5
  require 'whenever/job_list'
16
6
  require 'whenever/job'
17
- require 'whenever/outputs/cron'
18
- require 'whenever/outputs/cron/output_redirection'
7
+ require 'whenever/cron'
8
+ require 'whenever/output_redirection'
19
9
  require 'whenever/command_line'
20
10
  require 'whenever/version'
@@ -12,6 +12,7 @@ module Whenever
12
12
  @options = options
13
13
 
14
14
  @options[:file] ||= 'config/schedule.rb'
15
+ @options[:cut] ||= 0
15
16
  @options[:identifier] ||= default_identifier
16
17
 
17
18
  unless File.exists?(@options[:file])
@@ -23,6 +24,13 @@ module Whenever
23
24
  warn("[fail] Can only update, write or clear. Choose one.")
24
25
  exit(1)
25
26
  end
27
+
28
+ unless @options[:cut].to_s =~ /[0-9]*/
29
+ warn("[fail] Can't cut negative lines from the crontab #{options[:cut]}")
30
+ exit(1)
31
+ end
32
+ @options[:cut] = @options[:cut].to_i
33
+
26
34
  end
27
35
 
28
36
  def run
@@ -53,7 +61,7 @@ module Whenever
53
61
  command << "-u #{@options[:user]}" if @options[:user]
54
62
 
55
63
  command_results = %x[#{command.join(' ')} 2> /dev/null]
56
- @current_crontab = $?.exitstatus.zero? ? command_results : ''
64
+ @current_crontab = $?.exitstatus.zero? ? prepare(command_results) : ''
57
65
  end
58
66
 
59
67
  def write_crontab(contents)
@@ -95,6 +103,11 @@ module Whenever
95
103
  end
96
104
  end
97
105
 
106
+ #
107
+ def prepare(contents)
108
+ contents.split("\n")[@options[:cut]..-1].join("\n")
109
+ end
110
+
98
111
  def comment_base
99
112
  "Whenever generated tasks for: #{@options[:identifier]}"
100
113
  end
@@ -1,6 +1,5 @@
1
1
  module Whenever
2
2
  module Output
3
-
4
3
  class Cron
5
4
 
6
5
  attr_accessor :time, :task
@@ -43,7 +42,7 @@ module Whenever
43
42
  end
44
43
 
45
44
  def output_redirection
46
- OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
45
+ Whenever::Output::Cron::OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
47
46
  end
48
47
 
49
48
  protected
@@ -60,7 +59,7 @@ module Whenever
60
59
  end
61
60
 
62
61
  if shortcut
63
- if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at>0)
62
+ if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at > 0)
64
63
  raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
65
64
  else
66
65
  return shortcut
@@ -134,6 +133,5 @@ module Whenever
134
133
  end
135
134
 
136
135
  end
137
-
138
136
  end
139
137
  end
data/lib/whenever/job.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Whenever
2
2
  class Job
3
3
 
4
- attr_accessor :at, :output_redirection
4
+ attr_reader :at, :output_redirection
5
5
 
6
6
  def initialize(options = {})
7
7
  @options = options
@@ -13,10 +13,29 @@ module Whenever
13
13
  end
14
14
 
15
15
  def output
16
- @options[:template].gsub(/:\w+/) do |key|
17
- @options[key.sub(':', '').to_sym]
16
+ @options[:template].dup.gsub(/:\w+/) do |key|
17
+ before_and_after = [$`[-1..-1], $'[0..0]]
18
+ option = @options[key.sub(':', '').to_sym]
19
+
20
+ if before_and_after.all? { |c| c == "'" }
21
+ escape_single_quotes(option)
22
+ elsif before_and_after.all? { |c| c == '"' }
23
+ escape_double_quotes(option)
24
+ else
25
+ option
26
+ end
18
27
  end
19
28
  end
20
29
 
30
+ protected
31
+
32
+ def escape_single_quotes(str)
33
+ str.gsub(/'/) { "'\\''" }
34
+ end
35
+
36
+ def escape_double_quotes(str)
37
+ str.gsub(/"/) { '\"' }
38
+ end
39
+
21
40
  end
22
- end
41
+ end
@@ -1,3 +1,3 @@
1
- job_type :command, ':task'
2
- job_type :runner, 'cd :path && script/runner -e :environment ":task"'
3
- job_type :rake, 'cd :path && RAILS_ENV=:environment /usr/bin/env rake :task'
1
+ job_type :command, ":task"
2
+ job_type :runner, "cd :path && script/runner -e :environment ':task'"
3
+ job_type :rake, "cd :path && RAILS_ENV=:environment /usr/bin/env rake :task"
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.2'
3
3
  end unless defined?(Whenever::VERSION)
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class CommandLineTest < Test::Unit::TestCase
4
4
 
@@ -174,4 +174,115 @@ NEW_CRON
174
174
  @command = Whenever::CommandLine.new(:update => true, :clear => true)
175
175
  end
176
176
  end
177
+
178
+ context "A runner where the environment is overridden using the :set option" do
179
+ setup do
180
+ @output = Whenever.cron :set => 'environment=serious', :string => \
181
+ <<-file
182
+ set :environment, :silly
183
+ set :path, '/my/path'
184
+ every 2.hours do
185
+ runner "blahblah"
186
+ end
187
+ file
188
+ end
189
+
190
+ should "output the runner using the override environment" do
191
+ assert_match two_hours + %( cd /my/path && script/runner -e serious 'blahblah'), @output
192
+ end
193
+ end
194
+
195
+ context "A runner where the environment and path are overridden using the :set option" do
196
+ setup do
197
+ @output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
198
+ <<-file
199
+ set :environment, :silly
200
+ set :path, '/silly/path'
201
+ every 2.hours do
202
+ runner "blahblah"
203
+ end
204
+ file
205
+ end
206
+
207
+ should "output the runner using the overridden path and environment" do
208
+ assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
209
+ end
210
+ end
211
+
212
+ context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
213
+ setup do
214
+ @output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
215
+ <<-file
216
+ set :environment, :silly
217
+ set :path, '/silly/path'
218
+ every 2.hours do
219
+ runner "blahblah"
220
+ end
221
+ file
222
+ end
223
+
224
+ should "output the runner using the overridden path and environment" do
225
+ assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
226
+ end
227
+ end
228
+
229
+ context "A runner where the environment is overridden using the :set option but no value is given" do
230
+ setup do
231
+ @output = Whenever.cron :set => ' environment=', :string => \
232
+ <<-file
233
+ set :environment, :silly
234
+ set :path, '/silly/path'
235
+ every 2.hours do
236
+ runner "blahblah"
237
+ end
238
+ file
239
+ end
240
+
241
+ should "output the runner using the original environmnet" do
242
+ assert_match two_hours + %( cd /silly/path && script/runner -e silly 'blahblah'), @output
243
+ end
244
+ end
245
+
246
+ context "prepare-ing the output" do
247
+ setup do
248
+ File.expects(:exists?).with('config/schedule.rb').returns(true)
249
+ end
250
+
251
+ should "not trim off the top lines of the file" do
252
+ @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => 0)
253
+ existing = <<-EXISTING_CRON
254
+ # Useless Comments
255
+ # at the top of the file
256
+
257
+ # Begin Whenever generated tasks for: My identifier
258
+ My whenever job that was already here
259
+ # End Whenever generated tasks for: My identifier
260
+ EXISTING_CRON
261
+
262
+ # here-doc adds an extra newline we need removed
263
+ assert_equal existing.strip, @command.send(:prepare, existing)
264
+ end
265
+
266
+ should "trim off the top lines of the file" do
267
+ @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => '3')
268
+ existing = <<-EXISTING_CRON
269
+ # Useless Comments
270
+ # at the top of the file
271
+
272
+ # Begin Whenever generated tasks for: My identifier
273
+ My whenever job that was already here
274
+ # End Whenever generated tasks for: My identifier
275
+ EXISTING_CRON
276
+
277
+ new_cron = <<-NEW_CRON
278
+ # Begin Whenever generated tasks for: My identifier
279
+ My whenever job that was already here
280
+ # End Whenever generated tasks for: My identifier
281
+ NEW_CRON
282
+
283
+ # here-doc adds an extra newline we need removed
284
+ assert_equal new_cron.strip, @command.send(:prepare, existing)
285
+ end
286
+ end
287
+
177
288
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class OutputAtTest < Test::Unit::TestCase
4
4
 
@@ -91,7 +91,7 @@ class OutputAtTest < Test::Unit::TestCase
91
91
  end
92
92
 
93
93
  should "output the runner using one entry because the times are aligned" do
94
- assert_match '2 5,15 * * 1,3,5 cd /your/path && script/runner -e production "blahblah"', @output
94
+ assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
95
95
  end
96
96
  end
97
97
 
@@ -168,9 +168,9 @@ class OutputAtTest < Test::Unit::TestCase
168
168
 
169
169
  should "output all of the commands @daily" do
170
170
  assert_match '@daily cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output
171
- assert_match '@daily cd /your/path && script/runner -e production "runner_1"', @output
171
+ assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
172
172
  assert_match '@daily command_1', @output
173
- assert_match '@daily cd /your/path && script/runner -e production "runner_2"', @output
173
+ assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
174
174
  assert_match '@daily command_2', @output
175
175
  end
176
176
  end
@@ -1,47 +1,64 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
- class OutputRakeTest < Test::Unit::TestCase
3
+ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
4
4
 
5
- # Rake are generated in an almost identical way to runners so we
6
- # only need some basic tests to ensure they are output correctly
5
+ # command
7
6
 
8
- context "A rake command with path set" do
7
+ context "A plain command" do
8
+ setup do
9
+ @output = Whenever.cron \
10
+ <<-file
11
+ every 2.hours do
12
+ command "blahblah"
13
+ end
14
+ file
15
+ end
16
+
17
+ should "output the command" do
18
+ assert_match /^.+ .+ .+ .+ blahblah$/, @output
19
+ end
20
+ end
21
+
22
+ # runner
23
+
24
+ context "A runner with path set" do
9
25
  setup do
10
26
  @output = Whenever.cron \
11
27
  <<-file
12
28
  set :path, '/my/path'
13
29
  every 2.hours do
14
- rake "blahblah"
30
+ runner 'blahblah'
15
31
  end
16
32
  file
17
33
  end
18
34
 
19
- should "output the rake command using that path" do
20
- assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
35
+ should "output the runner using that path" do
36
+ assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
21
37
  end
22
38
  end
23
39
 
24
- context "A rake command that overrides the path set" do
40
+ context "A runner that overrides the path set" do
25
41
  setup do
26
42
  @output = Whenever.cron \
27
43
  <<-file
28
44
  set :path, '/my/path'
29
45
  every 2.hours do
30
- rake "blahblah", :path => '/some/other/path'
46
+ runner "blahblah", :path => '/some/other/path'
31
47
  end
32
48
  file
33
49
  end
34
50
 
35
- should "output the rake command using that path" do
36
- assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
51
+ should "output the runner using that path" do
52
+ assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
37
53
  end
38
54
  end
39
55
 
40
- context "A rake command with environment set" do
56
+ # rake
57
+
58
+ context "A rake command with path set" do
41
59
  setup do
42
60
  @output = Whenever.cron \
43
61
  <<-file
44
- set :environment, :silly
45
62
  set :path, '/my/path'
46
63
  every 2.hours do
47
64
  rake "blahblah"
@@ -49,25 +66,24 @@ class OutputRakeTest < Test::Unit::TestCase
49
66
  file
50
67
  end
51
68
 
52
- should "output the rake command using that environment" do
53
- assert_match two_hours + ' cd /my/path && RAILS_ENV=silly /usr/bin/env rake blahblah', @output
69
+ should "output the rake command using that path" do
70
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
54
71
  end
55
72
  end
56
73
 
57
- context "A rake command that overrides the environment set" do
74
+ context "A rake command that overrides the path set" do
58
75
  setup do
59
76
  @output = Whenever.cron \
60
77
  <<-file
61
- set :environment, :silly
62
78
  set :path, '/my/path'
63
79
  every 2.hours do
64
- rake "blahblah", :environment => :serious
80
+ rake "blahblah", :path => '/some/other/path'
65
81
  end
66
82
  file
67
83
  end
68
84
 
69
- should "output the rake command using that environment" do
70
- assert_match two_hours + ' cd /my/path && RAILS_ENV=serious /usr/bin/env rake blahblah', @output
85
+ should "output the rake command using that path" do
86
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
71
87
  end
72
88
  end
73
89
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class OutputDefinedJobTest < Test::Unit::TestCase
4
4
 
@@ -84,4 +84,22 @@ class OutputDefinedJobTest < Test::Unit::TestCase
84
84
  end
85
85
  end
86
86
 
87
+ context "A defined job that uses a :path where none is explicitly set" do
88
+ setup do
89
+ Whenever.expects(:path).returns('/my/path')
90
+
91
+ @output = Whenever.cron \
92
+ <<-file
93
+ job_type :some_job, "cd :path && :task"
94
+ every 2.hours do
95
+ some_job 'blahblah'
96
+ end
97
+ file
98
+ end
99
+
100
+ should "default to using the Whenever.path" do
101
+ assert_match two_hours + %( cd /my/path && blahblah), @output
102
+ end
103
+ end
104
+
87
105
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class OutputEnvTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class OutputRedirectionTest < Test::Unit::TestCase
4
4
 
data/test/test_helper.rb CHANGED
@@ -1,24 +1,11 @@
1
1
  require 'rubygems'
2
- require 'test/unit'
3
2
 
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
3
+ # Want to test the files here, in lib, not in an installed version of the gem.
4
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ require 'whenever'
21
6
 
7
+ require 'shoulda'
8
+ require 'mocha'
22
9
 
23
10
  module TestExtensions
24
11
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
 
3
3
  class CronTest < Test::Unit::TestCase
4
4
 
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+
3
+ class JobTest < Test::Unit::TestCase
4
+
5
+ context "A Job" do
6
+ should "return the :at set when #at is called" do
7
+ assert_equal 'foo', new_job(:at => 'foo').at
8
+ end
9
+
10
+ should "return :output when #output_redirection is called" do
11
+ assert_equal 'foo', new_job(:output => 'foo').output_redirection
12
+ end
13
+
14
+ should "return :not_set when #output_redirection is called and no :output is set" do
15
+ assert_equal :not_set, new_job.output_redirection
16
+ end
17
+
18
+ should "substitute the :task when #output is called" do
19
+ job = new_job(:template => ":task", :task => 'abc123')
20
+ assert_equal 'abc123', job.output
21
+ end
22
+
23
+ should "substitute the :path when #output is called" do
24
+ assert_equal 'foo', new_job(:template => ':path', :path => 'foo').output
25
+ end
26
+
27
+ should "substitute the :path with the default Whenever.path if none is provided when #output is called" do
28
+ Whenever.expects(:path).returns('/my/path')
29
+ assert_equal '/my/path', new_job(:template => ':path').output
30
+ end
31
+ end
32
+
33
+
34
+ context "A Job with quotes" do
35
+
36
+ should "output the :task if it's in single quotes" do
37
+ job = new_job(:template => "':task'", :task => 'abc123')
38
+ assert_equal %q('abc123'), job.output
39
+ end
40
+
41
+ should "output the :task if it's in double quotes" do
42
+ job = new_job(:template => '":task"', :task => 'abc123')
43
+ assert_equal %q("abc123"), job.output
44
+ end
45
+
46
+ should "output escaped single quotes in when it's wrapped in them" do
47
+ job = new_job(
48
+ :template => "before ':foo' after",
49
+ :foo => "quote -> ' <- quote"
50
+ )
51
+ assert_equal %q(before 'quote -> '\'' <- quote' after), job.output
52
+ end
53
+
54
+ should "output escaped double quotes when it's wrapped in them" do
55
+ job = new_job(
56
+ :template => 'before ":foo" after',
57
+ :foo => 'quote -> " <- quote'
58
+ )
59
+ assert_equal %q(before "quote -> \" <- quote" after), job.output
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def new_job(options={})
66
+ Whenever::Job.new(options)
67
+ end
68
+
69
+ end
data/whenever.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{whenever}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javan Makhmali"]
12
- s.date = %q{2010-06-28}
12
+ s.date = %q{2010-09-15}
13
13
  s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
14
14
  s.email = %q{javan@javan.us}
15
15
  s.executables = ["whenever", "wheneverize"]
@@ -26,22 +26,21 @@ Gem::Specification.new do |s|
26
26
  "lib/whenever.rb",
27
27
  "lib/whenever/base.rb",
28
28
  "lib/whenever/command_line.rb",
29
+ "lib/whenever/cron.rb",
29
30
  "lib/whenever/job.rb",
30
31
  "lib/whenever/job_list.rb",
31
32
  "lib/whenever/job_types/default.rb",
32
- "lib/whenever/outputs/cron.rb",
33
- "lib/whenever/outputs/cron/output_redirection.rb",
33
+ "lib/whenever/output_redirection.rb",
34
34
  "lib/whenever/version.rb",
35
- "test/command_line_test.rb",
36
- "test/cron_test.rb",
37
- "test/output_at_test.rb",
38
- "test/output_command_test.rb",
39
- "test/output_defined_job_test.rb",
40
- "test/output_env_test.rb",
41
- "test/output_rake_test.rb",
42
- "test/output_redirection_test.rb",
43
- "test/output_runner_test.rb",
35
+ "test/functional/command_line_test.rb",
36
+ "test/functional/output_at_test.rb",
37
+ "test/functional/output_default_defined_jobs_test.rb",
38
+ "test/functional/output_defined_job_test.rb",
39
+ "test/functional/output_env_test.rb",
40
+ "test/functional/output_redirection_test.rb",
44
41
  "test/test_helper.rb",
42
+ "test/unit/cron_test.rb",
43
+ "test/unit/job_test.rb",
45
44
  "whenever.gemspec"
46
45
  ]
47
46
  s.homepage = %q{http://github.com/javan/whenever}
@@ -50,16 +49,15 @@ Gem::Specification.new do |s|
50
49
  s.rubygems_version = %q{1.3.6}
51
50
  s.summary = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
52
51
  s.test_files = [
53
- "test/command_line_test.rb",
54
- "test/cron_test.rb",
55
- "test/output_at_test.rb",
56
- "test/output_command_test.rb",
57
- "test/output_defined_job_test.rb",
58
- "test/output_env_test.rb",
59
- "test/output_rake_test.rb",
60
- "test/output_redirection_test.rb",
61
- "test/output_runner_test.rb",
62
- "test/test_helper.rb"
52
+ "test/functional/command_line_test.rb",
53
+ "test/functional/output_at_test.rb",
54
+ "test/functional/output_default_defined_jobs_test.rb",
55
+ "test/functional/output_defined_job_test.rb",
56
+ "test/functional/output_env_test.rb",
57
+ "test/functional/output_redirection_test.rb",
58
+ "test/test_helper.rb",
59
+ "test/unit/cron_test.rb",
60
+ "test/unit/job_test.rb"
63
61
  ]
64
62
 
65
63
  if s.respond_to? :specification_version then
@@ -67,12 +65,21 @@ Gem::Specification.new do |s|
67
65
  s.specification_version = 3
68
66
 
69
67
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
- s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
68
+ s.add_runtime_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
69
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
70
+ s.add_development_dependency(%q<shoulda>, [">= 2.1.1"])
71
+ s.add_development_dependency(%q<mocha>, [">= 0.9.5"])
71
72
  else
72
- s.add_dependency(%q<chronic>, [">= 0.2.3"])
73
+ s.add_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
74
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
75
+ s.add_dependency(%q<shoulda>, [">= 2.1.1"])
76
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
73
77
  end
74
78
  else
75
- s.add_dependency(%q<chronic>, [">= 0.2.3"])
79
+ s.add_dependency(%q<aaronh-chronic>, [">= 0.3.9"])
80
+ s.add_dependency(%q<activesupport>, [">= 2.3.4"])
81
+ s.add_dependency(%q<shoulda>, [">= 2.1.1"])
82
+ s.add_dependency(%q<mocha>, [">= 0.9.5"])
76
83
  end
77
84
  end
78
85
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Javan Makhmali
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-28 00:00:00 -04:00
17
+ date: 2010-09-15 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: chronic
21
+ name: aaronh-chronic
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -26,11 +26,53 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- - 2
30
29
  - 3
31
- version: 0.2.3
30
+ - 9
31
+ version: 0.3.9
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 4
45
+ version: 2.3.4
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 1
58
+ - 1
59
+ version: 2.1.1
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 9
72
+ - 5
73
+ version: 0.9.5
74
+ type: :development
75
+ version_requirements: *id004
34
76
  description: Clean ruby syntax for defining and deploying messy cron jobs.
35
77
  email: javan@javan.us
36
78
  executables:
@@ -50,22 +92,21 @@ files:
50
92
  - lib/whenever.rb
51
93
  - lib/whenever/base.rb
52
94
  - lib/whenever/command_line.rb
95
+ - lib/whenever/cron.rb
53
96
  - lib/whenever/job.rb
54
97
  - lib/whenever/job_list.rb
55
98
  - lib/whenever/job_types/default.rb
56
- - lib/whenever/outputs/cron.rb
57
- - lib/whenever/outputs/cron/output_redirection.rb
99
+ - lib/whenever/output_redirection.rb
58
100
  - lib/whenever/version.rb
59
- - test/command_line_test.rb
60
- - test/cron_test.rb
61
- - test/output_at_test.rb
62
- - test/output_command_test.rb
63
- - test/output_defined_job_test.rb
64
- - test/output_env_test.rb
65
- - test/output_rake_test.rb
66
- - test/output_redirection_test.rb
67
- - test/output_runner_test.rb
101
+ - test/functional/command_line_test.rb
102
+ - test/functional/output_at_test.rb
103
+ - test/functional/output_default_defined_jobs_test.rb
104
+ - test/functional/output_defined_job_test.rb
105
+ - test/functional/output_env_test.rb
106
+ - test/functional/output_redirection_test.rb
68
107
  - test/test_helper.rb
108
+ - test/unit/cron_test.rb
109
+ - test/unit/job_test.rb
69
110
  - whenever.gemspec
70
111
  has_rdoc: true
71
112
  homepage: http://github.com/javan/whenever
@@ -98,13 +139,12 @@ signing_key:
98
139
  specification_version: 3
99
140
  summary: Clean ruby syntax for defining and deploying messy cron jobs.
100
141
  test_files:
101
- - test/command_line_test.rb
102
- - test/cron_test.rb
103
- - test/output_at_test.rb
104
- - test/output_command_test.rb
105
- - test/output_defined_job_test.rb
106
- - test/output_env_test.rb
107
- - test/output_rake_test.rb
108
- - test/output_redirection_test.rb
109
- - test/output_runner_test.rb
142
+ - test/functional/command_line_test.rb
143
+ - test/functional/output_at_test.rb
144
+ - test/functional/output_default_defined_jobs_test.rb
145
+ - test/functional/output_defined_job_test.rb
146
+ - test/functional/output_env_test.rb
147
+ - test/functional/output_redirection_test.rb
110
148
  - test/test_helper.rb
149
+ - test/unit/cron_test.rb
150
+ - test/unit/job_test.rb
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
-
3
- class OutputCommandTest < Test::Unit::TestCase
4
-
5
- context "A plain command" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- every 2.hours do
10
- command "blahblah"
11
- end
12
- file
13
- end
14
-
15
- should "output the command" do
16
- assert_match /^.+ .+ .+ .+ blahblah$/, @output
17
- end
18
- end
19
-
20
- context "An every statement with two commands in it" do
21
- setup do
22
- @output = Whenever.cron \
23
- <<-file
24
- every 1.hour do
25
- command "first"
26
- command "second"
27
- end
28
- file
29
- end
30
-
31
- should "output both commands" do
32
- assert_match "0 * * * * first", @output
33
- assert_match "0 * * * * second", @output
34
- end
35
- end
36
-
37
- end
@@ -1,175 +0,0 @@
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 + ' cd /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 + ' cd /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 + ' cd /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 + ' cd /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 an environment set" do
74
- setup do
75
- @output = Whenever.cron \
76
- <<-file
77
- set :environment, :silly
78
- set :path, '/my/path'
79
- every 2.hours do
80
- runner "blahblah"
81
- end
82
- file
83
- end
84
-
85
- should "output the runner using that environment" do
86
- assert_match two_hours + ' cd /my/path && script/runner -e silly "blahblah"', @output
87
- end
88
- end
89
-
90
- context "A runner that overrides the environment set" do
91
- setup do
92
- @output = Whenever.cron \
93
- <<-file
94
- set :environment, :silly
95
- set :path, '/my/path'
96
- every 2.hours do
97
- runner "blahblah", :environment => :serious
98
- end
99
- file
100
- end
101
-
102
- should "output the runner using that environment" do
103
- assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
104
- end
105
- end
106
-
107
- context "A runner where the environment is overridden using the :set option" do
108
- setup do
109
- @output = Whenever.cron :set => 'environment=serious', :string => \
110
- <<-file
111
- set :environment, :silly
112
- set :path, '/my/path'
113
- every 2.hours do
114
- runner "blahblah"
115
- end
116
- file
117
- end
118
-
119
- should "output the runner using the override environment" do
120
- assert_match two_hours + ' cd /my/path && script/runner -e serious "blahblah"', @output
121
- end
122
- end
123
-
124
- context "A runner where the environment and path are overridden using the :set option" do
125
- setup do
126
- @output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
127
- <<-file
128
- set :environment, :silly
129
- set :path, '/silly/path'
130
- every 2.hours do
131
- runner "blahblah"
132
- end
133
- file
134
- end
135
-
136
- should "output the runner using the overridden path and environment" do
137
- assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
138
- end
139
- end
140
-
141
- context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
142
- setup do
143
- @output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
144
- <<-file
145
- set :environment, :silly
146
- set :path, '/silly/path'
147
- every 2.hours do
148
- runner "blahblah"
149
- end
150
- file
151
- end
152
-
153
- should "output the runner using the overridden path and environment" do
154
- assert_match two_hours + ' cd /serious/path && script/runner -e serious "blahblah"', @output
155
- end
156
- end
157
-
158
- context "A runner where the environment is overridden using the :set option but no value is given" do
159
- setup do
160
- @output = Whenever.cron :set => ' environment=', :string => \
161
- <<-file
162
- set :environment, :silly
163
- set :path, '/silly/path'
164
- every 2.hours do
165
- runner "blahblah"
166
- end
167
- file
168
- end
169
-
170
- should "output the runner using the original environmnet" do
171
- assert_match two_hours + ' cd /silly/path && script/runner -e silly "blahblah"', @output
172
- end
173
- end
174
-
175
- end