cronos 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/TODO +4 -0
  3. data/lib/cronos.rb +42 -14
  4. data/spec/cronos_spec.rb +121 -72
  5. data/spec/spec_helper.rb +1 -2
  6. metadata +39 -35
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 10e6f846b422682bd216f2e943326d80629d76d3bbfcbed0450df8be2cdb9e38
4
+ data.tar.gz: 2b7b0f18357967bcfa562e8f9f7a7912bdfc9e1653043316bf0316c6aae78060
5
+ SHA512:
6
+ metadata.gz: 3088cfae1d5a6ad8f92c7ae58ebd50cccbff394ff7fd69690c10270a09040aa406009a751713a6f799a8446941d57a140d08e8ede98aeae608ade0560faa94a3
7
+ data.tar.gz: 2e008c2ff0ff24647d20b3e283d1b06d5453b6b91de985967a30cc80e1d568bf26c7354415a5f69dc685cfb4b1b9bc61236397cd87212a446cba62ff425a3e34
data/TODO CHANGED
@@ -1,3 +1,7 @@
1
1
  TODO:
2
2
  - more examples
3
3
  - more everything as its a start
4
+ - default time setting, when time not explicit, instead of midnight
5
+ - instantiate interval from cron string
6
+ - say method to output English description as comment at end of cron interval
7
+
data/lib/cronos.rb CHANGED
@@ -1,6 +1,6 @@
1
- module Cronos
1
+ require 'cronos/version'
2
2
 
3
- VERSION = '0.4.0'
3
+ module Cronos
4
4
 
5
5
  def self.schedule(task)
6
6
  TaskInterval.new(task)
@@ -13,6 +13,10 @@ module Cronos
13
13
 
14
14
  DAYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
15
15
 
16
+ def initialize(interval=nil)
17
+ @min, @hour, @day, @month, @dow = *parse_cron(interval) if interval
18
+ end
19
+
16
20
  # Time:
17
21
  # at(12)
18
22
  # at(1.30)
@@ -23,14 +27,14 @@ module Cronos
23
27
  def at(time)
24
28
  @hour, @min, meridian = parse_time(time)
25
29
 
26
- raise "invalid hour value for 'at'" if @hour > 12 && meridian
27
- raise "invalid minute value for 'at'" if @min > 59
30
+ raise ArgumentError, "invalid hour value for 'at'" if @hour > 12 && meridian
31
+ raise ArgumentError, "invalid minute value for 'at'" if @min > 59
28
32
 
29
33
  case meridian
30
- when 'am': @hour = 0 if @hour == 12
31
- when 'pm': @hour += 12 if @hour < 12
34
+ when 'am' then @hour = 0 if @hour == 12
35
+ when 'pm' then @hour += 12 if @hour < 12
32
36
  end
33
- raise "invalid hour value for 'at'" if @hour > 23
37
+ raise ArgumentError, "invalid hour value for 'at'" if @hour > 23
34
38
  self
35
39
  end
36
40
 
@@ -47,14 +51,14 @@ module Cronos
47
51
  # every('Feb'..'June')
48
52
  #
49
53
  def every(*multiple)
50
- return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(Fixnum)
54
+ return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(Numeric)
51
55
 
52
56
  if multiple.all? {|abbr| is_month?(abbr) }
53
57
  of(*multiple)
54
58
  elsif multiple.all? {|abbr| is_day?(abbr) }
55
59
  days(*multiple)
56
60
  else
57
- raise "Unknown interval type passed to #every"
61
+ raise ArgumentError, "Unknown interval type passed to #every"
58
62
  end
59
63
  end
60
64
 
@@ -92,7 +96,7 @@ module Cronos
92
96
  if args.first.is_a?(Range)
93
97
  @dow = format_range(args.first)
94
98
  else
95
- list = args.map {|day| day_value(day) unless day.is_a?(Fixnum) }
99
+ list = args.map {|day| day_value(day) unless day.is_a?(Numeric) }
96
100
  @dow = list.join(',')
97
101
  end
98
102
  self
@@ -115,7 +119,7 @@ module Cronos
115
119
  if args.first.is_a?(Range)
116
120
  @month = format_range(args.first)
117
121
  else
118
- list = args.map {|month| month_value(month) unless month.is_a?(Fixnum) }
122
+ list = args.map {|month| month_value(month) unless month.is_a?(Numeric) }
119
123
  @month = list.join(',')
120
124
  end
121
125
  self
@@ -185,6 +189,17 @@ module Cronos
185
189
  self
186
190
  end
187
191
 
192
+ def yearly
193
+ @min ||= 0
194
+ @hour ||= 0
195
+ @day ||= 1
196
+ @month ||= 1
197
+ @dow = nil
198
+ self
199
+ end
200
+ alias once_a_year yearly
201
+ alias annually yearly
202
+
188
203
  def to_s
189
204
  "#{min || '*'} #{hour || '*'} #{day || '*'} #{month || '*'} #{dow || '*'}"
190
205
  end
@@ -201,6 +216,12 @@ module Cronos
201
216
 
202
217
  private
203
218
 
219
+ def parse_cron(string)
220
+ parts = string.squeeze(' ').split(' ')
221
+ parts.collect! {|p| Integer(p) rescue p == '*' ? nil : p }
222
+ parts[0..4]
223
+ end
224
+
204
225
  def parse_time(time)
205
226
  meridian = /pm|am/i.match(time.to_s)[0].downcase rescue nil
206
227
  hour, min = *time.to_s.split('.')
@@ -251,14 +272,16 @@ module Cronos
251
272
  end
252
273
 
253
274
  def minutes
254
- raise 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
275
+ raise ArgumentError, 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
276
+
255
277
  calculate_intervals(60)
256
278
  @interval.min = self
257
279
  @interval
258
280
  end
259
281
 
260
282
  def hours
261
- raise 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
283
+ raise ArgumentError, 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
284
+
262
285
  calculate_intervals(24)
263
286
  @interval.min = 0
264
287
  @interval.hour = self
@@ -266,7 +289,8 @@ module Cronos
266
289
  end
267
290
 
268
291
  def months
269
- raise 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
292
+ raise ArgumentError, 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
293
+
270
294
  calculate_intervals(12, 1)
271
295
  @interval.min ||= 0
272
296
  @interval.hour ||= 0
@@ -303,6 +327,10 @@ module Cronos
303
327
  def to_s
304
328
  "#{super} #{@task}"
305
329
  end
330
+
331
+ def to_hash
332
+ super.merge(:command => task)
333
+ end
306
334
  end
307
335
 
308
336
  end
data/spec/cronos_spec.rb CHANGED
@@ -3,343 +3,392 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe Cronos do
4
4
 
5
5
  it "should return task interval instance from schedule method" do
6
- Cronos.schedule('ls').should be_kind_of(Cronos::TaskInterval)
6
+ expect(Cronos.schedule('ls')).to be_kind_of(Cronos::TaskInterval)
7
7
  end
8
8
 
9
+ it "should return task interval hash with command" do
10
+ expect(Cronos.schedule('ls').at('8.00am').to_hash[:command]).to eq('ls')
11
+ end
9
12
  end
10
13
 
11
14
  describe Cronos::Interval do
12
15
 
13
16
  it "should return default interval for every minute" do
14
- interval.to_s.should == '* * * * *'
17
+ expect(interval.to_s).to eq('* * * * *')
15
18
  end
16
19
 
17
20
  it "should return hash of values from to_hash method" do
18
- interval.at(2.01).on_the('3rd').of(:april).to_hash.should == {:minute => '1', :hour => '2', :day => '3', :month => '4', :weekday => '*'}
21
+ expect(interval.at(2.01).on_the('3rd').of(:april).to_hash).to eq({:minute => '1', :hour => '2', :day => '3', :month => '4', :weekday => '*'})
22
+ end
23
+
24
+ it "should instantiate interval from cron string" do
25
+ cron_string = '30 12 * * 0'
26
+ expect(Cronos::Interval.new(cron_string).to_s).to eq(cron_string)
19
27
  end
20
28
 
21
29
  describe "at method" do
22
30
  it "should output interval from integer with hour as integer value and 0 minute" do
23
- interval.at(8).to_s.should == '0 8 * * *'
31
+ expect(interval.at(8).to_s).to eq('0 8 * * *')
24
32
  end
25
33
 
26
34
  it "should output interval from a float with hour value from integer part and minute from decimal part" do
27
- interval.at(8.21).to_s.should == '21 8 * * *'
35
+ expect(interval.at(8.21).to_s).to eq('21 8 * * *')
28
36
  end
29
37
 
30
38
  it "should output interval from a float with hour value from integer part and minute from decimal part left justified to 2 digits" do
31
- interval.at(8.20).to_s.should == '20 8 * * *'
39
+ expect(interval.at(8.20).to_s).to eq('20 8 * * *')
32
40
  end
33
41
 
34
42
  it "should output interval from time string with pm meridian having hour adjusted 24 hour time" do
35
- interval.at('8.21pm').to_s.should == '21 20 * * *'
43
+ expect(interval.at('8.21pm').to_s).to eq('21 20 * * *')
36
44
  end
37
45
 
38
46
  it "should output interval from time string with pm meridian having hour unadjusted if hour is 12" do
39
- interval.at('12.21pm').to_s.should == '21 12 * * *'
47
+ expect(interval.at('12.21pm').to_s).to eq('21 12 * * *')
40
48
  end
41
49
 
42
50
  it "should output interval from time string with am meridian having hour adjusted to 0 if hour is 12" do
43
- interval.at('12.21am').to_s.should == '21 0 * * *'
51
+ expect(interval.at('12.21am').to_s).to eq('21 0 * * *')
44
52
  end
45
53
 
46
54
  it "should raise error if hours out of range" do
47
- lambda { interval.daily.at('24.21') }.should raise_error
55
+ expect { interval.daily.at('24.21') }.to raise_error(ArgumentError)
48
56
  end
49
57
 
50
58
  it "should raise error if minutes out of range" do
51
- lambda { interval.daily.at('23.60') }.should raise_error
59
+ expect { interval.daily.at('23.60') }.to raise_error(ArgumentError)
52
60
  end
53
61
  end
54
62
 
55
63
  describe "on method" do
56
64
  it "should output interval from integer with day of month as value" do
57
- interval.on(15).to_s.should == '* * 15 * *'
65
+ expect(interval.on(15).to_s).to eq('* * 15 * *')
58
66
  end
59
67
 
60
68
  it "should output interval from day string with ordinal suffix" do
61
- interval.on('15th').to_s.should == '* * 15 * *'
69
+ expect(interval.on('15th').to_s).to eq('* * 15 * *')
62
70
  end
63
71
 
64
72
  it "should output interval from inclusive range as dashed day of month range " do
65
- interval.on(15..17).to_s.should == '* * 15-17 * *'
73
+ expect(interval.on(15..17).to_s).to eq('* * 15-17 * *')
66
74
  end
67
75
 
68
76
  it "should output interval from string inclusive range as dashed day of month range " do
69
- interval.on('15th'..'17th').to_s.should == '* * 15-17 * *'
77
+ expect(interval.on('15th'..'17th').to_s).to eq('* * 15-17 * *')
70
78
  end
71
79
 
72
80
  it "should output interval from exclusive range as dashed day of month range " do
73
- interval.on(15...18).to_s.should == '* * 15-17 * *'
81
+ expect(interval.on(15...18).to_s).to eq('* * 15-17 * *')
74
82
  end
75
83
 
76
84
  it "should output interval from integer array as day number list" do
77
- interval.on(15, 16, 17).to_s.should == '* * 15,16,17 * *'
85
+ expect(interval.on(15, 16, 17).to_s).to eq('* * 15,16,17 * *')
78
86
  end
79
87
 
80
88
  it "should output interval from day string array as day number list" do
81
- interval.on('15th', '16th', '17th').to_s.should == '* * 15,16,17 * *'
89
+ expect(interval.on('15th', '16th', '17th').to_s).to eq('* * 15,16,17 * *')
82
90
  end
83
91
  end
84
92
 
85
93
  describe "of method" do
86
94
  it "should output interval with month number from a symbol month name" do
87
- interval.of(:january).to_s.should == '* * * 1 *'
95
+ expect(interval.of(:january).to_s).to eq('* * * 1 *')
88
96
  end
89
97
 
90
98
  it "should output interval with month number from a symbol short month name" do
91
- interval.of(:jan).to_s.should == '* * * 1 *'
99
+ expect(interval.of(:jan).to_s).to eq('* * * 1 *')
92
100
  end
93
101
 
94
102
  it "should output interval with month number from a strong month name" do
95
- interval.of('January').to_s.should == '* * * 1 *'
103
+ expect(interval.of('January').to_s).to eq('* * * 1 *')
96
104
  end
97
105
 
98
106
  it "should output interval with comma seperated month numbers from array of symbol month names" do
99
- interval.of(:january, :february, :march).to_s.should == '* * * 1,2,3 *'
107
+ expect(interval.of(:january, :february, :march).to_s).to eq('* * * 1,2,3 *')
100
108
  end
101
109
 
102
110
  it "should output interval with comma seperated month numbers from array of short symbol month names" do
103
- interval.of(:jan, :feb, :mar).to_s.should == '* * * 1,2,3 *'
111
+ expect(interval.of(:jan, :feb, :mar).to_s).to eq('* * * 1,2,3 *')
104
112
  end
105
113
 
106
114
  it "should output interval with comma seperated month numbers from array of string month names" do
107
- interval.of('January', 'February', 'March').to_s.should == '* * * 1,2,3 *'
115
+ expect(interval.of('January', 'February', 'March').to_s).to eq('* * * 1,2,3 *')
108
116
  end
109
117
 
110
118
  it "should output interval from integer inclusive range as dashed month range " do
111
- interval.of(1..3).to_s.should == '* * * 1-3 *'
119
+ expect(interval.of(1..3).to_s).to eq('* * * 1-3 *')
112
120
  end
113
121
 
114
122
  it "should output interval from string inclusive range as dashed month range " do
115
- interval.of('jan'..'mar').to_s.should == '* * * 1-3 *'
123
+ expect(interval.of('jan'..'mar').to_s).to eq('* * * 1-3 *')
116
124
  end
117
125
 
118
126
  it "should output interval from integer exclusive range as dashed month range " do
119
- interval.of(1...4).to_s.should == '* * * 1-3 *'
127
+ expect(interval.of(1...4).to_s).to eq('* * * 1-3 *')
120
128
  end
121
129
  end
122
130
 
123
131
  describe "days method" do
124
132
  it "should output interval with day number from a symbol day name" do
125
- interval.days(:monday).to_s.should == '* * * * 1'
133
+ expect(interval.days(:monday).to_s).to eq('* * * * 1')
126
134
  end
127
135
 
128
136
  it "should output interval with day number from a string day name" do
129
- interval.days('Mondays').to_s.should == '* * * * 1'
137
+ expect(interval.days('Mondays').to_s).to eq('* * * * 1')
130
138
  end
131
139
 
132
140
  it "should output interval with day number from a symbol short day name" do
133
- interval.days(:mon).to_s.should == '* * * * 1'
141
+ expect(interval.days(:mon).to_s).to eq('* * * * 1')
134
142
  end
135
143
 
136
144
  it "should output interval with day numbers from array of symbol day names" do
137
- interval.days(:monday, :wednesday, :friday).to_s.should == '* * * * 1,3,5'
145
+ expect(interval.days(:monday, :wednesday, :friday).to_s).to eq('* * * * 1,3,5')
138
146
  end
139
147
 
140
148
  it "should output interval with day numbers from array of symbol short day names" do
141
- interval.days(:mon, :wed, :fri).to_s.should == '* * * * 1,3,5'
149
+ expect(interval.days(:mon, :wed, :fri).to_s).to eq('* * * * 1,3,5')
142
150
  end
143
151
 
144
152
  it "should output interval with day numbers from array of string day names" do
145
- interval.days('Monday', 'Wednesday', 'Friday').to_s.should == '* * * * 1,3,5'
153
+ expect(interval.days('Monday', 'Wednesday', 'Friday').to_s).to eq('* * * * 1,3,5')
146
154
  end
147
155
 
148
156
  it "should output interval from integer inclusive range as dashed dow range " do
149
- interval.days(1..3).to_s.should == '* * * * 1-3'
157
+ expect(interval.days(1..3).to_s).to eq('* * * * 1-3')
150
158
  end
151
159
 
152
160
  it "should output interval from string inclusive range as dashed dow range " do
153
- interval.days('mon'..'wed').to_s.should == '* * * * 1-3'
161
+ expect(interval.days('mon'..'wed').to_s).to eq('* * * * 1-3')
154
162
  end
155
163
 
156
164
  it "should output interval from integer exclusive range as dashed dow range " do
157
- interval.days(1...4).to_s.should == '* * * * 1-3'
165
+ expect(interval.days(1...4).to_s).to eq('* * * * 1-3')
158
166
  end
159
167
  end
160
168
 
161
169
  describe "hourly method" do
162
170
  it "should output interval to run at start of every hour" do
163
- interval.hourly.to_s.should == '0 * * * *'
171
+ expect(interval.hourly.to_s).to eq('0 * * * *')
164
172
  end
165
173
 
166
174
  it "should only affect the hour and minutes" do
167
175
  interval.day = 1
168
176
  interval.month = 1
169
177
  interval.dow = 1
170
- interval.hourly.to_s.should == '0 * 1 1 1'
178
+ expect(interval.hourly.to_s).to eq('0 * 1 1 1')
171
179
  end
172
180
  end
173
181
 
174
182
  describe "daily method" do
175
183
  it "should output interval to run at 00:00 every day by default" do
176
- interval.daily.to_s.should == '0 0 * * *'
184
+ expect(interval.daily.to_s).to eq('0 0 * * *')
177
185
  end
178
186
 
179
187
  it "should only affect the hour, minutes and day" do
180
188
  interval.month = 1
181
189
  interval.dow = 1
182
- interval.daily.to_s.should == '0 0 * 1 1'
190
+ expect(interval.daily.to_s).to eq('0 0 * 1 1')
183
191
  end
184
192
 
185
193
  it "should preserve hour and minutes if set" do
186
194
  interval.min = 10
187
195
  interval.hour = 11
188
- interval.daily.to_s.should == '10 11 * * *'
196
+ expect(interval.daily.to_s).to eq('10 11 * * *')
189
197
  end
190
198
  end
191
199
 
192
200
  describe "midnight method" do
193
201
  it "should output interval to run at 00:00" do
194
- interval.midnight.to_s.should == '0 0 * * *'
202
+ expect(interval.midnight.to_s).to eq('0 0 * * *')
195
203
  end
196
204
  end
197
205
 
198
206
  describe "midday method" do
199
207
  it "should output interval to run at 12:00" do
200
- interval.midday.to_s.should == '0 12 * * *'
208
+ expect(interval.midday.to_s).to eq('0 12 * * *')
201
209
  end
202
210
  end
203
211
 
204
212
  describe "weekly method" do
205
213
  it "should output interval to run on Sunday at 00:00 by default" do
206
- interval.weekly.to_s.should == '0 0 * * 0'
214
+ expect(interval.weekly.to_s).to eq('0 0 * * 0')
207
215
  end
208
216
 
209
217
  it "should override day of month and month" do
210
218
  interval.day = 1
211
219
  interval.month = 1
212
- interval.weekly.to_s.should == '0 0 * * 0'
220
+ expect(interval.weekly.to_s).to eq('0 0 * * 0')
213
221
  end
214
222
 
215
223
  it "should preserve hour, minute and day of week if set" do
216
224
  interval.min = 10
217
225
  interval.hour = 11
218
226
  interval.dow = 1
219
- interval.daily.to_s.should == '10 11 * * 1'
227
+ expect(interval.daily.to_s).to eq('10 11 * * 1')
220
228
  end
221
229
  end
222
230
 
223
231
  describe "monthly method" do
224
232
  it "should output interval to run on the 1st day of every month at 00:00 by default" do
225
- interval.monthly.to_s.should == '0 0 1 * *'
233
+ expect(interval.monthly.to_s).to eq('0 0 1 * *')
226
234
  end
227
235
 
228
236
  it "should override day of month and month" do
229
237
  interval.day = 1
230
238
  interval.month = 1
231
- interval.monthly.to_s.should == '0 0 1 * *'
239
+ expect(interval.monthly.to_s).to eq('0 0 1 * *')
232
240
  end
233
241
 
234
242
  it "should preserve hour, minute and day if set" do
235
243
  interval.min = 10
236
244
  interval.hour = 11
237
245
  interval.day = 12
238
- interval.monthly.to_s.should == '10 11 12 * *'
246
+ expect(interval.monthly.to_s).to eq('10 11 12 * *')
239
247
  end
240
248
  end
241
249
 
242
250
  describe "weekends method" do
243
251
  it "should output interval to run at 00:00 every Saturday and Sunday" do
244
- interval.weekends.to_s.should == '0 0 * * 0,6'
252
+ expect(interval.weekends.to_s).to eq('0 0 * * 0,6')
245
253
  end
246
254
  end
247
255
 
248
256
  describe "weekdays method" do
249
257
  it "should output interval to run at 00:00 every day Monday to Friday" do
250
- interval.weekdays.to_s.should == '0 0 * * 1-5'
258
+ expect(interval.weekdays.to_s).to eq('0 0 * * 1-5')
259
+ end
260
+ end
261
+
262
+ describe "yearly method" do
263
+ it "should output interval to run on the 1st day of January at 00:00 by default" do
264
+ expect(interval.yearly.to_s).to eq('0 0 1 1 *')
265
+ end
266
+
267
+ it "should override day of week if set" do
268
+ interval.dow = 1
269
+ expect(interval.yearly.to_s).to eq('0 0 1 1 *')
270
+ end
271
+
272
+ it "should preserve hour, minute, day and month if set" do
273
+ interval.min = 10
274
+ interval.hour = 11
275
+ interval.day = 12
276
+ interval.month = 3
277
+ expect(interval.yearly.to_s).to eq('10 11 12 3 *')
251
278
  end
252
279
  end
253
280
 
254
281
  describe "every(x).minutes" do
255
282
  it "should output interval for list of minutes differing by arg value" do
256
- interval.every(15).minutes.to_s.should == '0,15,30,45 * * * *'
283
+ expect(interval.every(15).minutes.to_s).to eq('0,15,30,45 * * * *')
257
284
  end
258
285
 
259
286
  it "should raise error if x not a divisor of 60" do
260
- lambda { interval.every(13).minutes }.should raise_error
287
+ expect { interval.every(13).minutes }.to raise_error(ArgumentError)
261
288
  end
262
289
  end
263
290
 
264
291
  describe "every(x).hours" do
265
292
  it "should output interval for 0 minute and list of hours differing by arg value" do
266
- interval.every(6).hours.to_s.should == '0 0,6,12,18 * * *'
293
+ expect(interval.every(6).hours.to_s).to eq('0 0,6,12,18 * * *')
267
294
  end
268
295
 
269
296
  it "should raise error if x not a divisor of 24" do
270
- lambda { interval.every(13).minutes }.should raise_error
297
+ expect { interval.every(13).minutes }.to raise_error(ArgumentError)
271
298
  end
272
299
  end
273
300
 
274
301
  describe "every(x).months" do
275
302
  it "should output interval for 00:00 on 1st day of month and list of months differing by arg value" do
276
- interval.every(6).hours.to_s.should == '0 0,6,12,18 * * *'
303
+ expect(interval.every(6).hours.to_s).to eq('0 0,6,12,18 * * *')
277
304
  end
278
305
 
279
306
  it "should raise error if x not a divisor of 12" do
280
- lambda { interval.every(7).minutes }.should raise_error
307
+ expect { interval.every(7).minutes }.to raise_error(ArgumentError)
281
308
  end
282
309
  end
283
310
 
284
311
  describe "every(day_name)" do
285
312
  it "should output interval for day symbol as day of week" do
286
- interval.every(:sunday).to_s.should == '* * * * 0'
313
+ expect(interval.every(:sunday).to_s).to eq('* * * * 0')
287
314
  end
288
315
 
289
316
  it "should output interval for list of days as days of week" do
290
- interval.every(:thursay, 'Friday').to_s.should == '* * * * 4,5'
317
+ expect(interval.every(:thursay, 'Friday').to_s).to eq('* * * * 4,5')
291
318
  end
292
319
  end
293
320
 
294
321
  describe "every(month_name)" do
295
322
  it "should output interval for month symbol as month" do
296
- interval.every(:january).to_s.should == '* * * 1 *'
323
+ expect(interval.every(:january).to_s).to eq('* * * 1 *')
297
324
  end
298
325
 
299
326
  it "should output interval for list of months as months" do
300
- interval.every(:february, 'March').to_s.should == '* * * 2,3 *'
327
+ expect(interval.every(:february, 'March').to_s).to eq('* * * 2,3 *')
301
328
  end
302
329
  end
303
330
 
304
331
  describe "combinations" do
305
332
  it "weekly.at(3.30) should output '30 3 * * 0'" do
306
- interval.weekly.at(3.30).to_s.should == '30 3 * * 0'
333
+ expect(interval.weekly.at(3.30).to_s).to eq('30 3 * * 0')
307
334
  end
308
335
 
309
336
  it "monthly.at(3.30) should output '30 3 * * *'" do
310
- interval.monthly.at(3.30).to_s.should == '30 3 1 * *'
337
+ expect(interval.monthly.at(3.30).to_s).to eq('30 3 1 * *')
311
338
  end
312
339
 
313
340
  it "monthly.on_the('15th').at(3.30) should output '30 3 15 * *'" do
314
- interval.monthly.on_the('15th').at(3.30).to_s.should == '30 3 15 * *'
341
+ expect(interval.monthly.on_the('15th').at(3.30).to_s).to eq('30 3 15 * *')
315
342
  end
316
343
 
317
344
  it "at('11pm').on_days(:monday, :tuesday) should output '0 11 * * 1,2'" do
318
- interval.at('11pm').on_days(:monday, :tuesday).to_s.should == '0 23 * * 1,2'
345
+ expect(interval.at('11pm').on_days(:monday, :tuesday).to_s).to eq('0 23 * * 1,2')
319
346
  end
320
347
 
321
348
  it "on(15).of(:january) should output '* * 15 1 *'" do
322
- interval.on(15).of(:january).to_s.should == '* * 15 1 *'
349
+ expect(interval.on(15).of(:january).to_s).to eq('* * 15 1 *')
323
350
  end
324
351
 
325
352
  it "on(15, 16, 17).of(:january) should output '* * 15,16,17 1 *'" do
326
- interval.on(15, 16, 17).of(:january).to_s.should == '* * 15,16,17 1 *'
353
+ expect(interval.on(15, 16, 17).of(:january).to_s).to eq('* * 15,16,17 1 *')
327
354
  end
328
355
 
329
356
  it "on(15..17).of(:january) should output '* * 15-17 1 *'" do
330
- interval.on(15..17).of(:january).to_s.should == '* * 15-17 1 *'
357
+ expect(interval.on(15..17).of(:january).to_s).to eq('* * 15-17 1 *')
331
358
  end
332
359
 
333
360
  it "on(15, 16, 17).of(:january) should output '* * 15 1,6,12 *'" do
334
- interval.on(15).of(:jan, :jun, :dec).to_s.should == '* * 15 1,6,12 *'
361
+ expect(interval.on(15).of(:jan, :jun, :dec).to_s).to eq('* * 15 1,6,12 *')
335
362
  end
336
363
 
337
364
  it "at('2.13pm').on_the_('15th').of(:january) should output '13 14 15 1'" do
338
- interval.at('2.13pm').on_the(15).of(:january).to_s.should == '13 14 15 1 *'
365
+ expect(interval.at('2.13pm').on_the(15).of(:january).to_s).to eq('13 14 15 1 *')
339
366
  end
340
367
 
341
368
  it "every(15).minutes.on_the('15th').of(:january) should output '0,15,30,45 * 15 1 *'" do
342
- interval.every(15).minutes.on_the('15th').of(:january).to_s.should == '0,15,30,45 * 15 1 *'
369
+ expect(interval.every(15).minutes.on_the('15th').of(:january).to_s).to eq('0,15,30,45 * 15 1 *')
370
+ end
371
+ end
372
+
373
+ describe "cron string parser" do
374
+
375
+ it "should parse '* * * * *'" do
376
+ value = '* * * * *'
377
+ expect(parse(value)).to eq(value)
378
+ end
379
+
380
+ it "should parse '1 2 3 4 5'" do
381
+ value = '1 2 3 4 5'
382
+ expect(parse(value)).to eq(value)
383
+ end
384
+
385
+ # it "should parse ''" do
386
+ # value = ''
387
+ # parse(value).should == value
388
+ # end
389
+
390
+ def parse(cron)
391
+ Cronos::Interval.new(cron).to_s
343
392
  end
344
393
  end
345
394
 
@@ -351,7 +400,7 @@ end
351
400
  describe Cronos::TaskInterval do
352
401
 
353
402
  it "should output task at end of interval string" do
354
- Cronos::TaskInterval.new('ls').at('12pm').to_s.should == '0 12 * * * ls'
403
+ expect(Cronos::TaskInterval.new('ls').at('12pm').to_s).to eq('0 12 * * * ls')
355
404
  end
356
405
 
357
406
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
- $TESTING=true
2
1
  $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
2
 
4
3
  require 'rubygems'
5
- require 'spec'
4
+ require 'rspec'
6
5
  require 'cronos'
metadata CHANGED
@@ -1,63 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cronos
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Adam Meehan
8
8
  autorequire: cronos
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-03-12 00:00:00 +11:00
13
- default_executable:
14
- dependencies: []
15
-
11
+ date: 2009-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
16
27
  description: Tool for generating cron intervals using a natural syntax
17
28
  email: adam.meehan@gmail.com
18
29
  executables: []
19
-
20
30
  extensions: []
21
-
22
- extra_rdoc_files:
31
+ extra_rdoc_files:
23
32
  - README.rdoc
24
33
  - LICENSE
25
34
  - TODO
26
35
  - CHANGELOG
27
- files:
36
+ files:
37
+ - CHANGELOG
28
38
  - LICENSE
29
39
  - README.rdoc
30
40
  - Rakefile
31
41
  - TODO
32
- - CHANGELOG
33
42
  - lib/cronos.rb
34
- - spec/spec_helper.rb
35
43
  - spec/cronos_spec.rb
36
- has_rdoc: true
44
+ - spec/spec_helper.rb
37
45
  homepage: http://github.com/adzap/cronos
38
- post_install_message:
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
39
49
  rdoc_options: []
40
-
41
- require_paths:
50
+ require_paths:
42
51
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
44
- requirements:
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
45
54
  - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- version:
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- requirements:
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
51
59
  - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
55
62
  requirements: []
56
-
57
- rubyforge_project:
58
- rubygems_version: 1.3.1
59
- signing_key:
60
- specification_version: 2
63
+ rubygems_version: 3.0.3.1
64
+ signing_key:
65
+ specification_version: 4
61
66
  summary: Tool for generating cron intervals using a natural syntax
62
67
  test_files: []
63
-