spec/cronline_spec.rb in rufus-scheduler-2.0.17 vs spec/cronline_spec.rb in rufus-scheduler-2.0.18

- old
+ new

@@ -34,11 +34,11 @@ describe '.new' do it 'interprets cron strings correctly' do to_a '* * * * *', [ [0], nil, nil, nil, nil, nil, nil, nil ] - to_a '10-12 * * * *', [ [0], [10, 11, 12], nil, nil, nil, nil, nil, nil ] + to_a '10-12 * * * *', [ [0], [10, 11, 12], nil, nil, nil, nil, nil, nil ] to_a '* * * * sun,mon', [ [0], nil, nil, nil, nil, [0, 1], nil, nil ] to_a '* * * * mon-wed', [ [0], nil, nil, nil, nil, [1, 2, 3], nil, nil ] to_a '* * * * 7', [ [0], nil, nil, nil, nil, [0], nil, nil ] to_a '* * * * 0', [ [0], nil, nil, nil, nil, [0], nil, nil ] to_a '* * * * 0,1', [ [0], nil, nil, nil, nil, [0,1], nil, nil ] @@ -54,10 +54,25 @@ to_a '1-5 * * * * *', [ [1,2,3,4,5], nil, nil, nil, nil, nil, nil, nil ] to_a '0 0 1 1 *', [ [0], [0], [0], [1], [1], nil, nil, nil ] end + it 'rejects invalid weekday expressions' do + + lambda { cl '0 17 * * MON_FRI' }.should raise_error + # underline instead of dash + + lambda { cl '* * * * 9' }.should raise_error + lambda { cl '* * * * 0-12' }.should raise_error + lambda { cl '* * * * BLABLA' }.should raise_error + end + + it 'rejects invalid cronlines' do + + lambda { cl '* nada * * 9' }.should raise_error(ArgumentError) + end + it 'interprets cron strings with TZ correctly' do to_a '* * * * * EST', [ [0], nil, nil, nil, nil, nil, nil, 'EST' ] to_a '* * * * * * EST', [ nil, nil, nil, nil, nil, nil, nil, 'EST' ] @@ -92,10 +107,33 @@ to_a '07-08 * * * *', [ [0], [7, 8], nil, nil, nil, nil, nil, nil ] to_a '* */08 * * *', [ [0], nil, [0, 8, 16, 24], nil, nil, nil, nil, nil ] to_a '* 01-09/04 * * *', [ [0], nil, [1, 5, 9], nil, nil, nil, nil, nil ] to_a '* * * * 06', [ [0], nil, nil, nil, nil, [6], nil, nil ] end + + it 'interprets cron strings with L correctly' do + + to_a '* * L * *', [[0], nil, nil, ['L'], nil, nil, nil, nil ] + to_a '* * 2-5,L * *', [[0], nil, nil, [2,3,4,5,'L'], nil, nil, nil, nil ] + to_a '* * */8,L * *', [[0], nil, nil, [1,9,17,25,'L'], nil, nil, nil, nil ] + end + + it 'does not support ranges for L' do + + lambda { cl '* * 15-L * *'}.should raise_error(ArgumentError) + lambda { cl '* * L/4 * *'}.should raise_error(ArgumentError) + end + + it 'does not support multiple Ls' do + + lambda { cl '* * L,L * *'}.should raise_error(ArgumentError) + end + + it 'raises if L is used for something else than days' do + + lambda { cl '* L * * *'}.should raise_error(ArgumentError) + end end describe '#next_time' do def nt(cronline, now) @@ -205,10 +243,18 @@ now = local(1970, 1, 12) nt('* * * * sun#2,sun#3', now).should == local(1970, 1, 18) end + + it 'computes the next time correctly when there is a L (last day of month)' do + + nt('* * L * *', local(1970,1,1)).should == local(1970, 1, 31) + nt('* * L * *', local(1970,2,1)).should == local(1970, 2, 28) + nt('* * L * *', local(1972,2,1)).should == local(1972, 2, 29) + nt('* * L * *', local(1970,4,1)).should == local(1970, 4, 30) + end end describe '#matches?' do it 'matches correctly in UTC (TZ not specified)' do @@ -260,9 +306,15 @@ it 'matches correctly when there is a sun#2 involved' do match '* * 13 * fri#2', utc(1970, 2, 13) no_match '* * 13 * fri#2', utc(1970, 2, 20) + end + + it 'matches correctly when there is a L involved' do + + match '* * L * *', utc(1970, 1, 31) + no_match '* * L * *', utc(1970, 1, 30) end it 'matches correctly when there is a sun#2,sun#3 involved' do no_match '* * * * sun#2,sun#3', local(1970, 1, 4)