@@ -15,92 +15,96 @@ def parse_date(str)
1515 [ "10" , 0 ..59 , [ 10 ] ] ,
1616 [ "10,30" , 0 ..59 , [ 10 , 30 ] ] ,
1717 [ "10-15" , 0 ..59 , [ 10 , 11 , 12 , 13 , 14 , 15 ] ] ,
18- [ "10-40/10" , 0 ..59 , [ 10 , 20 , 30 , 40 ] ] ,
18+ [ "10-40/10" , 0 ..59 , [ 10 , 20 , 30 , 40 ] ]
1919 ] . each do |element , range , expected |
2020 it "should return #{ expected } for '#{ element } ' when range is #{ range } " do
2121 parser = CronParser . new ( '* * * * *' )
22- parser . parse_element ( element , range ) . first . to_a . sort . should == expected . sort
22+ expect ( parser . parse_element ( element , range ) . first . to_a . sort ) . to eq ( expected . sort )
2323 end
2424 end
2525end
2626
2727describe "CronParser#next" do
2828 [
29- [ "* * * * *" , "2011-08-15 12:00" , "2011-08-15 12:01" , 1 ] ,
30- [ "* * * * *" , "2011-08-15 02:25" , "2011-08-15 02:26" , 1 ] ,
31- [ "* * * * *" , "2011-08-15 02:59" , "2011-08-15 03:00" , 1 ] ,
32- [ "*/15 * * * *" , "2011-08-15 02:02" , "2011-08-15 02:15" , 1 ] ,
33- [ "*/15,25 * * * *" , "2011-08-15 02:15" , "2011-08-15 02:25" , 1 ] ,
34- [ "30 3,6,9 * * *" , "2011-08-15 02:15" , "2011-08-15 03:30" , 1 ] ,
35- [ "30 9 * * *" , "2011-08-15 10:15" , "2011-08-16 09:30" , 1 ] ,
36- [ "30 9 * * *" , "2011-08-31 10:15" , "2011-09-01 09:30" , 1 ] ,
37- [ "30 9 * * *" , "2011-09-30 10:15" , "2011-10-01 09:30" , 1 ] ,
38- [ "0 9 * * *" , "2011-12-31 10:15" , "2012-01-01 09:00" , 1 ] ,
39- [ "* * 12 * *" , "2010-04-15 10:15" , "2010-05-12 00:00" , 1 ] ,
40- [ "* * * * 1,3" , "2010-04-15 10:15" , "2010-04-19 00:00" , 1 ] ,
41- [ "* * * * MON,WED" , "2010-04-15 10:15" , "2010-04-19 00:00" , 1 ] ,
42- [ "0 0 1 1 *" , "2010-04-15 10:15" , "2011-01-01 00:00" , 1 ] ,
43- [ "0 0 * * 1" , "2011-08-01 00:00" , "2011-08-08 00:00" , 1 ] ,
44- [ "0 0 * * 1" , "2011-07-25 00:00" , "2011-08-01 00:00" , 1 ] ,
45- [ "45 23 7 3 *" , "2011-01-01 00:00" , "2011-03-07 23:45" , 1 ] ,
46- [ "0 0 1 jun *" , "2013-05-14 11:20" , "2013-06-01 00:00" , 1 ] ,
47- [ "0 0 1 may,jul *" , "2013-05-14 15:00" , "2013-07-01 00:00" , 1 ] ,
48- [ "0 0 1 MAY,JUL *" , "2013-05-14 15:00" , "2013-07-01 00:00" , 1 ] ,
49- [ "40 5 * * *" , "2014-02-01 15:56" , "2014-02-02 05:40" , 1 ] ,
50- [ "0 5 * * 1" , "2014-02-01 15:56" , "2014-02-03 05:00" , 1 ] ,
51- [ "10 8 15 * *" , "2014-02-01 15:56" , "2014-02-15 08:10" , 1 ] ,
52- [ "50 6 * * 1" , "2014-02-01 15:56" , "2014-02-03 06:50" , 1 ] ,
53- [ "1 2 * apr mOn" , "2014-02-01 15:56" , "2014-04-07 02:01" , 1 ] ,
54- [ "1 2 3 4 7" , "2014-02-01 15:56" , "2014-04-03 02:01" , 1 ] ,
55- [ "1 2 3 4 7" , "2014-04-04 15:56" , "2014-04-06 02:01" , 1 ] ,
56- [ "1-20/3 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
57- [ "1,2,3 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
58- [ "1-9,15-30 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
59- [ "1-9/3,15-30/4 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
60- [ "1 2 3 jan mon" , "2014-02-01 15:56" , "2015-01-03 02:01" , 1 ] ,
61- [ "1 2 3 4 mON" , "2014-02-01 15:56" , "2014-04-03 02:01" , 1 ] ,
62- [ "1 2 3 jan 5" , "2014-02-01 15:56" , "2015-01-02 02:01" , 1 ] ,
63- [ "@yearly" , "2014-02-01 15:56" , "2015-01-01 00:00" , 1 ] ,
64- [ "@annually" , "2014-02-01 15:56" , "2015-01-01 00:00" , 1 ] ,
65- [ "@monthly" , "2014-02-01 15:56" , "2014-03-01 00:00" , 1 ] ,
66- [ "@weekly" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
67- [ "@daily" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
68- [ "@midnight" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
69- [ "@hourly" , "2014-02-01 15:56" , "2014-02-01 16:00" , 1 ] ,
70- [ "*/3 * * * *" , "2014-02-01 15:56" , "2014-02-01 15:57" , 1 ] ,
71- [ "0 5 * 2,3 *" , "2014-02-01 15:56" , "2014-02-02 05:00" , 1 ] ,
72- [ "15-59/15 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:15" , 1 ] ,
73- [ "15-59/15 * * * *" , "2014-02-01 15:00" , "2014-02-01 15:15" , 1 ] ,
74- [ "15-59/15 * * * *" , "2014-02-01 15:01" , "2014-02-01 15:15" , 1 ] ,
75- [ "15-59/15 * * * *" , "2014-02-01 15:16" , "2014-02-01 15:30" , 1 ] ,
76- [ "15-59/15 * * * *" , "2014-02-01 15:26" , "2014-02-01 15:30" , 1 ] ,
77- [ "15-59/15 * * * *" , "2014-02-01 15:36" , "2014-02-01 15:45" , 1 ] ,
78- [ "15-59/15 * * * *" , "2014-02-01 15:45" , "2014-02-01 16:15" , 4 ] ,
79- [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 16:15" , 3 ] ,
80- [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 16:15" , 2 ] ,
81- ] . each do |line , now , expected_next , num |
29+ [ "* * * * *" , "2011-08-15 12:00" , "2011-08-15 12:01" , 1 ] ,
30+ [ "* * * * *" , "2011-08-15 02:25" , "2011-08-15 02:26" , 1 ] ,
31+ [ "* * * * *" , "2011-08-15 02:59" , "2011-08-15 03:00" , 1 ] ,
32+ [ "*/15 * * * *" , "2011-08-15 02:02" , "2011-08-15 02:15" , 1 ] ,
33+ [ "*/15,25 * * * *" , "2011-08-15 02:15" , "2011-08-15 02:25" , 1 ] ,
34+ [ "30 3,6,9 * * *" , "2011-08-15 02:15" , "2011-08-15 03:30" , 1 ] ,
35+ [ "30 9 * * *" , "2011-08-15 10:15" , "2011-08-16 09:30" , 1 ] ,
36+ [ "30 9 * * *" , "2011-08-31 10:15" , "2011-09-01 09:30" , 1 ] ,
37+ [ "30 9 * * *" , "2011-09-30 10:15" , "2011-10-01 09:30" , 1 ] ,
38+ [ "0 9 * * *" , "2011-12-31 10:15" , "2012-01-01 09:00" , 1 ] ,
39+ [ "* * 12 * *" , "2010-04-15 10:15" , "2010-05-12 00:00" , 1 ] ,
40+ [ "* * * * 1,3" , "2010-04-15 10:15" , "2010-04-19 00:00" , 1 ] ,
41+ [ "* * * * MON,WED" , "2010-04-15 10:15" , "2010-04-19 00:00" , 1 ] ,
42+ [ "0 0 1 1 *" , "2010-04-15 10:15" , "2011-01-01 00:00" , 1 ] ,
43+ [ "0 0 * * 1" , "2011-08-01 00:00" , "2011-08-08 00:00" , 1 ] ,
44+ [ "0 0 * * 1" , "2011-07-25 00:00" , "2011-08-01 00:00" , 1 ] ,
45+ [ "45 23 7 3 *" , "2011-01-01 00:00" , "2011-03-07 23:45" , 1 ] ,
46+ [ "0 0 1 jun *" , "2013-05-14 11:20" , "2013-06-01 00:00" , 1 ] ,
47+ [ "0 0 1 may,jul *" , "2013-05-14 15:00" , "2013-07-01 00:00" , 1 ] ,
48+ [ "0 0 1 MAY,JUL *" , "2013-05-14 15:00" , "2013-07-01 00:00" , 1 ] ,
49+ [ "40 5 * * *" , "2014-02-01 15:56" , "2014-02-02 05:40" , 1 ] ,
50+ [ "0 5 * * 1" , "2014-02-01 15:56" , "2014-02-03 05:00" , 1 ] ,
51+ [ "10 8 15 * *" , "2014-02-01 15:56" , "2014-02-15 08:10" , 1 ] ,
52+ [ "50 6 * * 1" , "2014-02-01 15:56" , "2014-02-03 06:50" , 1 ] ,
53+ [ "1 2 * apr mOn" , "2014-02-01 15:56" , "2014-04-07 02:01" , 1 ] ,
54+ [ "1 2 3 4 7" , "2014-02-01 15:56" , "2014-04-03 02:01" , 1 ] ,
55+ [ "1 2 3 4 7" , "2014-04-04 15:56" , "2014-04-06 02:01" , 1 ] ,
56+ [ "1-20/3 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
57+ [ "1,2,3 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
58+ [ "1-9,15-30 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
59+ [ "1-9/3,15-30/4 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:01" , 1 ] ,
60+ [ "1 2 3 jan mon" , "2014-02-01 15:56" , "2015-01-03 02:01" , 1 ] ,
61+ [ "1 2 3 4 mON" , "2014-02-01 15:56" , "2014-04-03 02:01" , 1 ] ,
62+ [ "1 2 3 jan 5" , "2014-02-01 15:56" , "2015-01-02 02:01" , 1 ] ,
63+ [ "@yearly" , "2014-02-01 15:56" , "2015-01-01 00:00" , 1 ] ,
64+ [ "@annually" , "2014-02-01 15:56" , "2015-01-01 00:00" , 1 ] ,
65+ [ "@monthly" , "2014-02-01 15:56" , "2014-03-01 00:00" , 1 ] ,
66+ [ "@weekly" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
67+ [ "@daily" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
68+ [ "@midnight" , "2014-02-01 15:56" , "2014-02-02 00:00" , 1 ] ,
69+ [ "@hourly" , "2014-02-01 15:56" , "2014-02-01 16:00" , 1 ] ,
70+ [ "*/3 * * * *" , "2014-02-01 15:56" , "2014-02-01 15:57" , 1 ] ,
71+ [ "0 5 * 2,3 *" , "2014-02-01 15:56" , "2014-02-02 05:00" , 1 ] ,
72+ [ "15-59/15 * * * *" , "2014-02-01 15:56" , "2014-02-01 16:15" , 1 ] ,
73+ [ "15-59/15 * * * *" , "2014-02-01 15:00" , "2014-02-01 15:15" , 1 ] ,
74+ [ "15-59/15 * * * *" , "2014-02-01 15:01" , "2014-02-01 15:15" , 1 ] ,
75+ [ "15-59/15 * * * *" , "2014-02-01 15:16" , "2014-02-01 15:30" , 1 ] ,
76+ [ "15-59/15 * * * *" , "2014-02-01 15:26" , "2014-02-01 15:30" , 1 ] ,
77+ [ "15-59/15 * * * *" , "2014-02-01 15:36" , "2014-02-01 15:45" , 1 ] ,
78+ [ "15-59/15 * * * *" , "2014-02-01 15:45" , "2014-02-01 16:15" , 4 ] ,
79+ [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 16:15" , 3 ] ,
80+ [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 16:15" , 2 ]
81+ ] . each do |line , now , expected_next , num |
8282 it "returns #{ expected_next } for '#{ line } ' when now is #{ now } " do
8383 parsed_now = parse_date ( now )
8484 expected = parse_date ( expected_next )
85+
8586 parser = CronParser . new ( line )
86- parser . next ( parsed_now ) . xmlschema . should == expected . xmlschema
87+
88+ expect ( parser . next ( parsed_now ) . xmlschema ) . to eq ( expected . xmlschema )
8789 end
8890 it "returns the expected class" do
8991 parsed_now = parse_date ( now )
90- expected = parse_date ( expected_next )
92+
9193 parser = CronParser . new ( line )
92- result = parser . next ( parsed_now , num )
93- result . class . to_s . should == ( num > 1 ? 'Array' : 'Time' )
94+
95+ result = parser . next ( parsed_now , num )
96+ expect ( result . class . to_s ) . to eq ( ( num > 1 ? 'Array' : 'Time' ) )
9497 end
9598 it "returns the expected count" do
9699 parsed_now = parse_date ( now )
97- expected = parse_date ( expected_next )
100+
98101 parser = CronParser . new ( line )
99- result = parser . next ( parsed_now , num )
102+
103+ result = parser . next ( parsed_now , num )
100104 if result . class . to_s == 'Array'
101- result . size . should == num
105+ expect ( result . size ) . to eq ( num )
102106 else
103- result . class . to_s . should == 'Time'
107+ expect ( result . class . to_s ) . to eq ( 'Time' )
104108 end
105109 end
106110 end
@@ -156,15 +160,15 @@ def parse_date(str)
156160 [ "15-59/15 * * * *" , "2014-02-01 15:26" , "2014-02-01 15:15" ] ,
157161 [ "15-59/15 * * * *" , "2014-02-01 15:36" , "2014-02-01 15:30" ] ,
158162 [ "15-59/15 * * * *" , "2014-02-01 15:45" , "2014-02-01 15:30" ] ,
159- [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 15:45" ] ,
160- ] . each do |line , now , expected_next |
161- it "should return #{ expected_next } for '#{ line } ' when now is #{ now } " do
162- now = parse_date ( now )
163- expected_next = parse_date ( expected_next )
163+ [ "15-59/15 * * * *" , "2014-02-01 15:46" , "2014-02-01 15:45" ]
164+ ] . each do |line , now , expected_last |
165+ it "should return #{ expected_last } for '#{ line } ' when now is #{ now } " do
166+ parsed_now = parse_date ( now )
167+ expected = parse_date ( expected_last )
164168
165169 parser = CronParser . new ( line )
166170
167- parser . last ( now ) . should == expected_next
171+ expect ( parser . last ( parsed_now ) ) . to eq ( expected )
168172 end
169173 end
170174end
@@ -182,7 +186,7 @@ def parse_date(str)
182186describe "time source" do
183187 it "should use an alternate specified time source" do
184188 ExtendedTime = Class . new ( Time )
185- ExtendedTime . should_receive ( :local ) . once
186- CronParser . new ( "* * * * *" , ExtendedTime ) . next
189+ allow ( ExtendedTime ) . to receive ( :local ) . once
190+ CronParser . new ( "* * * * *" , ExtendedTime ) . next
187191 end
188192end
0 commit comments