spec/cronline_spec.rb in rufus-scheduler-2.0.24 vs spec/cronline_spec.rb in rufus-scheduler-3.0.0
- old
+ new
@@ -3,17 +3,18 @@
# Specifying rufus-scheduler
#
# Sat Mar 21 12:55:27 JST 2009
#
-require 'spec_base'
+require 'tzinfo'
+require 'spec_helper'
-describe Rufus::CronLine do
+describe Rufus::Scheduler::CronLine do
def cl(cronline_string)
- Rufus::CronLine.new(cronline_string)
+ Rufus::Scheduler::CronLine.new(cronline_string)
end
def match(line, time)
cl(line).matches?(time).should == true
end
@@ -109,11 +110,11 @@
end
it 'does not support ranges for monthdays (sun#1-sun#2)' do
lambda {
- Rufus::CronLine.new('* * * * sun#1-sun#2')
+ Rufus::Scheduler::CronLine.new('* * * * sun#1-sun#2')
}.should raise_error(ArgumentError)
end
it 'accepts items with initial 0' do
@@ -163,11 +164,11 @@
end
describe '#next_time' do
def nt(cronline, now)
- Rufus::CronLine.new(cronline).next_time(now)
+ Rufus::Scheduler::CronLine.new(cronline).next_time(now)
end
it 'computes the next occurence correctly' do
now = Time.at(0).getutc # Thu Jan 01 00:00:00 UTC 1970
@@ -183,10 +184,11 @@
# historical note:
# (comment made in 2006 or 2007, the underlying libs got better and
# that slowness is gone)
nt('0 0 * * thu', now).should == now + 604800
+ nt('00 0 * * thu', now).should == now + 604800
nt('0 0 * * *', now).should == now + 24 * 3600
nt('0 24 * * *', now).should == now + 24 * 3600
now = local(2008, 12, 31, 23, 59, 59, 0)
@@ -292,16 +294,22 @@
nt('* * L * *', lo(1970, 1, 1)).should == lo(1970, 1, 31)
nt('* * L * *', lo(1970, 2, 1)).should == lo(1970, 2, 28)
nt('* * L * *', lo(1972, 2, 1)).should == lo(1972, 2, 29)
nt('* * L * *', lo(1970, 4, 1)).should == lo(1970, 4, 30)
end
+
+ it 'returns a time with subseconds chopped off' do
+
+ nt('* * * * *', Time.now).usec.should == 0
+ nt('* * * * *', Time.now).iso8601(10).match(/\.0+[^\d]/).should_not == nil
+ end
end
describe '#previous_time' do
def pt(cronline, now)
- Rufus::CronLine.new(cronline).previous_time(now)
+ Rufus::Scheduler::CronLine.new(cronline).previous_time(now)
end
it 'returns the previous time the cron should have triggered' do
pt('* * * * sun', lo(1970, 1, 1)).should == lo(1969, 12, 28, 23, 59, 00)
@@ -384,20 +392,33 @@
describe '#monthdays' do
it 'returns the appropriate "sun#2"-like string' do
- class Rufus::CronLine
+ class Rufus::Scheduler::CronLine
public :monthdays
end
- cl = Rufus::CronLine.new('* * * * *')
+ cl = Rufus::Scheduler::CronLine.new('* * * * *')
cl.monthdays(local(1970, 1, 1)).should == %w[ thu#1 thu#-5 ]
cl.monthdays(local(1970, 1, 7)).should == %w[ wed#1 wed#-4 ]
cl.monthdays(local(1970, 1, 14)).should == %w[ wed#2 wed#-3 ]
cl.monthdays(local(2011, 3, 11)).should == %w[ fri#2 fri#-3 ]
+ end
+ end
+
+ describe '#frequency' do
+
+ it 'returns the shortest delta between two occurrences' do
+
+ Rufus::Scheduler::CronLine.new('* * * * *').frequency.should == 60
+ Rufus::Scheduler::CronLine.new('* * * * * *').frequency.should == 1
+
+ Rufus::Scheduler::CronLine.new('5 23 * * *').frequency.should == 24 * 3600
+ Rufus::Scheduler::CronLine.new('5 * * * *').frequency.should == 3600
+ Rufus::Scheduler::CronLine.new('10,20,30 * * * *').frequency.should == 600
end
end
end