diff --git a/README.md b/README.md index 1477e7f..f11bdff 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ This will create an initial "config/schedule.rb" file you. runner "Task.do_something_great" end + every '0 0 27-31 * *' do + command "echo 'you can use raw cron sytax too'" + end + More examples on the wiki: ### Define your own job types diff --git a/lib/whenever/cron.rb b/lib/whenever/cron.rb index 8e16bc6..ea14b0c 100644 --- a/lib/whenever/cron.rb +++ b/lib/whenever/cron.rb @@ -34,6 +34,7 @@ module Whenever def time_in_cron_syntax case @time + when /^.+ .+ .+ .+ .+.?$/ then @time # raw cron sytax given when Symbol then parse_symbol when String then parse_as_string else parse_time diff --git a/test/functional/output_at_test.rb b/test/functional/output_at_test.rb index a239655..96fe6d4 100644 --- a/test/functional/output_at_test.rb +++ b/test/functional/output_at_test.rb @@ -248,4 +248,21 @@ class OutputAtTest < Test::Unit::TestCase assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output end end + + context "using raw cron syntax" do + setup do + @output = Whenever.cron \ + <<-file + set :job_template, nil + every '0 0 27-31 * *' do + command "blahblah" + end + file + end + + should "output the command using the same cron syntax" do + assert_match '0 0 27-31 * * blahblah', @output + end + end + end diff --git a/test/unit/cron_test.rb b/test/unit/cron_test.rb index 6eafa4c..5427a31 100644 --- a/test/unit/cron_test.rb +++ b/test/unit/cron_test.rb @@ -199,6 +199,15 @@ class CronTest < Test::Unit::TestCase end end end + + context "When given raw cron sytax" do + should "return the same cron sytax" do + crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *'] + crons.each do |cron| + assert_equal cron, parse_time(cron) + end + end + end private