ice_cube_cron 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,13 @@ describe ::IceCubeCron::ExpressionParser do
4
4
  let(:expression) do
5
5
  described_class.new(
6
6
  nil,
7
- :repeat_interval => 2,
8
- :repeat_day => 3,
9
- :repeat_month => 4,
10
- :repeat_year => 1990,
11
- :repeat_weekday => 0
7
+ :interval => 2,
8
+ :day_of_month => 3,
9
+ :month => 4,
10
+ :year => 1990,
11
+ :day_of_week => 0,
12
+ :hour => 5,
13
+ :minute => 6
12
14
  )
13
15
  end
14
16
 
@@ -18,49 +20,86 @@ describe ::IceCubeCron::ExpressionParser do
18
20
  # rubocop:enable Style/SymbolProc
19
21
  let(:expression) { described_class.new(expression_str) }
20
22
 
21
- it '* * 2 * *' do
22
- expect(expression.expression_hash[:repeat_interval]).to eq(1)
23
- expect(expression.expression_hash[:repeat_year]).to eq(nil)
24
- expect(expression.expression_hash[:repeat_month]).to eq(nil)
25
- expect(expression.expression_hash[:repeat_day]).to eq([2])
26
- expect(expression.expression_hash[:repeat_weekday]).to eq(nil)
23
+ it '1 * 2 * *' do
24
+ expect(expression.interval).to eq(1)
25
+ expect(expression.year).to eq(nil)
26
+ expect(expression.month).to eq(nil)
27
+ expect(expression.day).to eq([2])
28
+ expect(expression.day_of_week).to eq(nil)
29
+ expect(expression.hour).to eq(nil)
30
+ expect(expression.minute).to eq([1])
27
31
  end
28
32
 
29
- it '* * 1,15 * *' do
30
- expect(expression.expression_hash[:repeat_interval]).to eq(1)
31
- expect(expression.expression_hash[:repeat_year]).to eq(nil)
32
- expect(expression.expression_hash[:repeat_month]).to eq(nil)
33
- expect(expression.expression_hash[:repeat_day]).to eq([1, 15])
34
- expect(expression.expression_hash[:repeat_weekday]).to eq(nil)
33
+ it '* 12 1,15 * *' do
34
+ expect(expression.interval).to eq(1)
35
+ expect(expression.year).to eq(nil)
36
+ expect(expression.month).to eq(nil)
37
+ expect(expression.day_of_month).to eq([1, 15])
38
+ expect(expression.day_of_week).to eq(nil)
39
+ expect(expression.hour).to eq([12])
40
+ expect(expression.minute).to eq(nil)
35
41
  end
36
42
 
37
43
  it '* * 1 6,12 *' do
38
- expect(expression.expression_hash[:repeat_interval]).to eq(1)
39
- expect(expression.expression_hash[:repeat_year]).to eq(nil)
40
- expect(expression.expression_hash[:repeat_month]).to eq([6, 12])
41
- expect(expression.expression_hash[:repeat_day]).to eq([1])
42
- expect(expression.expression_hash[:repeat_weekday]).to eq(nil)
44
+ expect(expression.interval).to eq(1)
45
+ expect(expression.year).to eq(nil)
46
+ expect(expression.month).to eq([6, 12])
47
+ expect(expression.day_of_month).to eq([1])
48
+ expect(expression.day_of_week).to eq(nil)
49
+ expect(expression.hour).to eq(nil)
50
+ expect(expression.minute).to eq(nil)
43
51
  end
44
52
 
45
53
  it '* * 1 6 * 2015' do
46
- expect(expression.expression_hash[:repeat_interval]).to eq(1)
47
- expect(expression.expression_hash[:repeat_year]).to eq([2015])
48
- expect(expression.expression_hash[:repeat_month]).to eq([6])
49
- expect(expression.expression_hash[:repeat_day]).to eq([1])
50
- expect(expression.expression_hash[:repeat_weekday]).to eq(nil)
54
+ expect(expression.interval).to eq(1)
55
+ expect(expression.year).to eq([2015])
56
+ expect(expression.month).to eq([6])
57
+ expect(expression.day_of_month).to eq([1])
58
+ expect(expression.day_of_week).to eq(nil)
59
+ expect(expression.hour).to eq(nil)
60
+ expect(expression.minute).to eq(nil)
51
61
  end
52
62
 
53
63
  it '* * * 6 1L *' do
54
- expect(expression.expression_hash[:repeat_interval]).to eq(1)
55
- expect(expression.expression_hash[:repeat_year]).to eq(nil)
56
- expect(expression.expression_hash[:repeat_month]).to eq([6])
57
- expect(expression.expression_hash[:repeat_day]).to eq(nil)
58
- expect(expression.expression_hash[:repeat_weekday]).to eq([1 => [-1]])
64
+ expect(expression.interval).to eq(1)
65
+ expect(expression.year).to eq(nil)
66
+ expect(expression.month).to eq([6])
67
+ expect(expression.day_of_month).to eq(nil)
68
+ expect(expression.day_of_week).to eq([1 => [-1]])
69
+ expect(expression.hour).to eq(nil)
70
+ expect(expression.minute).to eq(nil)
71
+ end
72
+
73
+ it '*/5 * * * * *' do
74
+ expect(expression.interval).to eq(5)
75
+ expect(expression.year).to eq(nil)
76
+ expect(expression.month).to eq(nil)
77
+ expect(expression.day_of_month).to eq(nil)
78
+ expect(expression.day_of_week).to eq(nil)
79
+ expect(expression.hour).to eq(nil)
80
+ expect(expression.minute).to eq(nil)
81
+ end
82
+
83
+ it '1 */12 * * * *' do
84
+ expect(expression.interval).to eq(12)
85
+ expect(expression.year).to eq(nil)
86
+ expect(expression.month).to eq(nil)
87
+ expect(expression.day_of_month).to eq(nil)
88
+ expect(expression.day_of_week).to eq(nil)
89
+ expect(expression.hour).to eq(nil)
90
+ expect(expression.minute).to eq([1])
91
+ end
92
+
93
+ # Only one interval is supported
94
+ it '*/1 */12 * * * *' do
95
+ expect(expression.interval).to eq(12)
96
+ expect(expression.hour).to eq(nil)
97
+ expect(expression.minute).to eq(nil)
59
98
  end
60
99
  end
61
100
 
62
101
  describe 'parses ::Hash expression' do
63
- describe 'repeat_interval' do
102
+ describe 'interval' do
64
103
  it '[]' do
65
104
  expect(expression.interval).to eq(2)
66
105
  end
@@ -82,49 +121,123 @@ describe ::IceCubeCron::ExpressionParser do
82
121
  end
83
122
  end
84
123
 
85
- describe 'repeat_day' do
124
+ describe 'minute' do
86
125
  it '[]' do
87
- expect(expression.day).to eq([3])
126
+ expect(expression.minute).to eq([6])
88
127
  end
89
128
 
90
129
  it '[]=' do
91
- expression.day = 6
92
- expect(expression.day).to eq([6])
130
+ expression.minute = 6
131
+ expect(expression.minute).to eq([6])
93
132
  end
94
133
 
95
134
  it 'sanitizes' do
96
- expression.day = 2
97
- expect(expression.day).to eq([2])
135
+ expression.minute = 2
136
+ expect(expression.minute).to eq([2])
98
137
 
99
- expression.day = nil
100
- expect(expression.day).to eq(nil)
138
+ expression.minute = nil
139
+ expect(expression.minute).to eq(nil)
101
140
 
102
- expression.day = '3'
103
- expect(expression.day).to eq([3])
141
+ expression.minute = '3'
142
+ expect(expression.minute).to eq([3])
143
+ end
144
+
145
+ it 'should accept single minute expression' do
146
+ expression.minute = '1'
147
+ expect(expression.minute).to eq([1])
148
+ end
149
+
150
+ it 'should accept series expression' do
151
+ expression.minute = '1,3'
152
+ expect(expression.minute).to eq([1, 3])
153
+ end
154
+
155
+ it 'should accept range expression' do
156
+ expression.minute = '1-3'
157
+ expect(expression.minute).to eq([1, 2, 3])
158
+ end
159
+ end
160
+
161
+ describe 'hour' do
162
+ it '[]' do
163
+ expect(expression.hour).to eq([5])
164
+ end
165
+
166
+ it '[]=' do
167
+ expression.hour = 6
168
+ expect(expression.hour).to eq([6])
169
+ end
170
+
171
+ it 'sanitizes' do
172
+ expression.hour = 2
173
+ expect(expression.hour).to eq([2])
174
+
175
+ expression.hour = nil
176
+ expect(expression.hour).to eq(nil)
177
+
178
+ expression.hour = '3'
179
+ expect(expression.hour).to eq([3])
180
+ end
181
+
182
+ it 'should accept single hour expression' do
183
+ expression.hour = '1'
184
+ expect(expression.hour).to eq([1])
185
+ end
186
+
187
+ it 'should accept series expression' do
188
+ expression.hour = '1,3'
189
+ expect(expression.hour).to eq([1, 3])
190
+ end
191
+
192
+ it 'should accept range expression' do
193
+ expression.hour = '1-3'
194
+ expect(expression.hour).to eq([1, 2, 3])
195
+ end
196
+ end
197
+
198
+ describe 'day_of_month' do
199
+ it '[]' do
200
+ expect(expression.day_of_month).to eq([3])
201
+ end
202
+
203
+ it '[]=' do
204
+ expression.day_of_month = 6
205
+ expect(expression.day_of_month).to eq([6])
206
+ end
207
+
208
+ it 'sanitizes' do
209
+ expression.day_of_month = 2
210
+ expect(expression.day_of_month).to eq([2])
211
+
212
+ expression.day_of_month = nil
213
+ expect(expression.day_of_month).to eq(nil)
214
+
215
+ expression.day_of_month = '3'
216
+ expect(expression.day_of_month).to eq([3])
104
217
  end
105
218
 
106
219
  it 'should accept single day expression' do
107
- expression.day = '1'
108
- expect(expression.day).to eq([1])
220
+ expression.day_of_month = '1'
221
+ expect(expression.day_of_month).to eq([1])
109
222
  end
110
223
 
111
224
  it 'should accept series expression' do
112
- expression.day = '1,3'
113
- expect(expression.day).to eq([1, 3])
225
+ expression.day_of_month = '1,3'
226
+ expect(expression.day_of_month).to eq([1, 3])
114
227
  end
115
228
 
116
229
  it 'should accept range expression' do
117
- expression.day = '1-3'
118
- expect(expression.day).to eq([1, 2, 3])
230
+ expression.day_of_month = '1-3'
231
+ expect(expression.day_of_month).to eq([1, 2, 3])
119
232
  end
120
233
 
121
234
  it 'should accept last day expression' do
122
- expression.day = 'L'
123
- expect(expression.day).to eq([-1])
235
+ expression.day_of_month = 'L'
236
+ expect(expression.day_of_month).to eq([-1])
124
237
  end
125
238
  end
126
239
 
127
- describe 'repeat_month' do
240
+ describe 'month' do
128
241
  it '[]' do
129
242
  expect(expression.month).to eq([4])
130
243
  end
@@ -146,7 +259,7 @@ describe ::IceCubeCron::ExpressionParser do
146
259
  end
147
260
  end
148
261
 
149
- describe 'repeat_year' do
262
+ describe 'year' do
150
263
  it '[]' do
151
264
  expect(expression.year).to eq([1990])
152
265
  end
@@ -168,41 +281,49 @@ describe ::IceCubeCron::ExpressionParser do
168
281
  end
169
282
  end
170
283
 
171
- describe 'repeat_weekday' do
284
+ describe 'day_of_week' do
172
285
  it '[]' do
173
- expect(expression.weekday).to eq([0])
286
+ expect(expression.day_of_week).to eq([0])
174
287
  end
175
288
 
176
289
  it '[]=' do
177
- expression.weekday = 4
178
- expect(expression.weekday).to eq([4])
290
+ expression.day_of_week = 4
291
+ expect(expression.day_of_week).to eq([4])
179
292
  end
180
293
 
181
294
  it 'sanitizes' do
182
- expression.weekday = 2
183
- expect(expression.weekday).to eq([2])
295
+ expression.day_of_week = 2
296
+ expect(expression.day_of_week).to eq([2])
184
297
 
185
- expression.weekday = nil
186
- expect(expression.weekday).to eq(nil)
298
+ expression.day_of_week = nil
299
+ expect(expression.day_of_week).to eq(nil)
187
300
 
188
- expression.weekday = '3'
189
- expect(expression.weekday).to eq([3])
301
+ expression.day_of_week = '3'
302
+ expect(expression.day_of_week).to eq([3])
190
303
  end
191
304
 
192
305
  it 'should accept non-nth weekday expression' do
193
- expression.weekday = '1'
194
- expect(expression.weekday).to eq([1])
306
+ expression.day_of_week = '1'
307
+ expect(expression.day_of_week).to eq([1])
195
308
  end
196
309
 
197
310
  it 'should accept nth weekday expression' do
198
- expression.weekday = '1#3'
199
- expect(expression.weekday).to eq([{ 1 => [3] }])
311
+ expression.day_of_week = '1#3'
312
+ expect(expression.day_of_week).to eq([{ 1 => [3] }])
200
313
  end
201
314
 
202
315
  it 'should accept last weekday expression' do
203
- expression.weekday = '1L'
204
- expect(expression.weekday).to eq([{ 1 => [-1] }])
316
+ expression.day_of_week = '1L'
317
+ expect(expression.day_of_week).to eq([{ 1 => [-1] }])
205
318
  end
206
319
  end
207
320
  end
321
+
322
+ describe 'invalid parameters' do
323
+ it 'should raise helpful error' do
324
+ expect do
325
+ described_class.new(:invalid_param => 1)
326
+ end.to raise_error(ArgumentError)
327
+ end
328
+ end
208
329
  end
@@ -8,25 +8,117 @@ describe ::IceCubeCron::RuleBuilder do
8
8
  let(:rule_builder) { described_class.new }
9
9
 
10
10
  describe 'builds correct root rule' do
11
- it 'monthly' do
12
- expression.day = 5
13
- expect(rule_builder.build_rule(expression)).to be_a(IceCube::MonthlyRule)
11
+ # rubocop:disable Style/SymbolProc
12
+ let(:expression_str) { |example| example.description }
13
+ # rubocop:enable Style/SymbolProc
14
+ let(:expression) { ::IceCubeCron::ExpressionParser.new(expression_str) }
15
+ let(:rule) { rule_builder.build_rule(expression) }
16
+
17
+ context 'minutely' do
18
+ it '* * * * *' do
19
+ expect(rule).to be_a(IceCube::MinutelyRule)
20
+ end
21
+
22
+ it '* 1 1 1 1 2015' do
23
+ expect(rule).to be_a(IceCube::MinutelyRule)
24
+ end
14
25
  end
15
26
 
16
- it 'weekly' do
17
- expression.weekday = 2
18
- expect(rule_builder.build_rule(expression)).to be_a(IceCube::WeeklyRule)
27
+ context 'hourly' do
28
+ it '1 * * * *' do
29
+ expect(rule).to be_a(IceCube::HourlyRule)
30
+ end
31
+
32
+ it '1 * 1 1 1 2015' do
33
+ expect(rule).to be_a(IceCube::HourlyRule)
34
+ end
19
35
  end
20
36
 
21
- it 'monthly (last week day of month)' do
22
- expression.weekday = '2L'
23
- expect(rule_builder.build_rule(expression)).to be_a(IceCube::MonthlyRule)
37
+ context 'daily' do
38
+ it '1 2 * * *' do
39
+ expect(rule).to be_a(IceCube::DailyRule)
40
+ end
41
+
42
+ it '1 2 * 1 * 2015' do
43
+ expect(rule).to be_a(IceCube::DailyRule)
44
+ end
24
45
  end
25
46
 
26
- it 'yearly' do
27
- expression.month = 2
28
- expect(rule_builder.build_rule(expression)).to be_a(IceCube::YearlyRule)
47
+ context 'monthly' do
48
+ it '0 0 1 * *' do
49
+ expect(rule).to be_a(IceCube::MonthlyRule)
50
+ end
51
+
52
+ it '1 2 1 * * 2015' do
53
+ expect(rule).to be_a(IceCube::MonthlyRule)
54
+ end
55
+
56
+ it '1 2 1 * * 2015' do
57
+ expect(rule).to be_a(IceCube::MonthlyRule)
58
+ end
59
+
60
+ it '1 2 * * 1L 2015' do
61
+ expect(rule).to be_a(IceCube::MonthlyRule)
62
+ end
29
63
  end
64
+
65
+ context 'weekly' do
66
+ it '0 0 * * 1' do
67
+ expect(rule).to be_a(IceCube::WeeklyRule)
68
+ end
69
+
70
+ it '1 2 * * 1 2015' do
71
+ expect(rule).to be_a(IceCube::WeeklyRule)
72
+ end
73
+ end
74
+
75
+ context 'yearly' do
76
+ it '0 0 1 1 *' do
77
+ expect(rule).to be_a(IceCube::YearlyRule)
78
+ end
79
+
80
+ it '1 2 1 1 * 2015' do
81
+ expect(rule).to be_a(IceCube::YearlyRule)
82
+ end
83
+ end
84
+
85
+ # it '1 * 2 * *' do
86
+ # expect(rule).to be_a(IceCube::MonthlyRule)
87
+ # end
88
+
89
+ # it '1 2 2 * *' do
90
+ # expect(rule).to be_a(IceCube::MonthlyRule)
91
+ # end
92
+
93
+ # it 'monthly' do
94
+ # expression.day = 5
95
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::MonthlyRule)
96
+ # end
97
+
98
+ # it 'weekly' do
99
+ # expression.weekday = 2
100
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::WeeklyRule)
101
+ # end
102
+
103
+ # it 'monthly (last week day of month)' do
104
+ # expression.weekday = '2L'
105
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::MonthlyRule)
106
+ # end
107
+
108
+ # it 'yearly' do
109
+ # expression.month = 2
110
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::YearlyRule)
111
+ # end
112
+
113
+ # it 'daily' do
114
+ # expression.hour = 2
115
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::DailyRule)
116
+ # end
117
+
118
+ # it 'hourly' do
119
+ # expression.minute = 2
120
+ # expect(rule_builder.build_rule(expression)).to be_a(IceCube::HourlyRule)
121
+ # end
30
122
  end
31
123
 
32
124
  describe '#nth_day?' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube_cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Nichols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_cube
@@ -107,7 +107,6 @@ files:
107
107
  - ".rspec"
108
108
  - ".rubocop.yml"
109
109
  - Gemfile
110
- - Gemfile.lock
111
110
  - Guardfile
112
111
  - LICENSE
113
112
  - README.md
data/Gemfile.lock DELETED
@@ -1,72 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ice_cube_cron (0.0.4)
5
- activesupport (~> 4)
6
- ice_cube (~> 0.13)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (4.2.4)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- ast (2.1.0)
18
- astrolabe (1.3.1)
19
- parser (~> 2.2)
20
- coderay (1.1.0)
21
- diff-lcs (1.2.5)
22
- i18n (0.7.0)
23
- ice_cube (0.13.0)
24
- json (1.8.3)
25
- method_source (0.8.2)
26
- minitest (5.8.2)
27
- parser (2.2.3.0)
28
- ast (>= 1.1, < 3.0)
29
- powerpack (0.1.1)
30
- pry (0.10.3)
31
- coderay (~> 1.1.0)
32
- method_source (~> 0.8.1)
33
- slop (~> 3.4)
34
- rainbow (2.0.0)
35
- rake (10.4.2)
36
- rspec (3.3.0)
37
- rspec-core (~> 3.3.0)
38
- rspec-expectations (~> 3.3.0)
39
- rspec-mocks (~> 3.3.0)
40
- rspec-core (3.3.2)
41
- rspec-support (~> 3.3.0)
42
- rspec-expectations (3.3.1)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.3.0)
45
- rspec-mocks (3.3.2)
46
- diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.3.0)
48
- rspec-support (3.3.0)
49
- rubocop (0.34.2)
50
- astrolabe (~> 1.3)
51
- parser (>= 2.2.2.5, < 3.0)
52
- powerpack (~> 0.1)
53
- rainbow (>= 1.99.1, < 3.0)
54
- ruby-progressbar (~> 1.4)
55
- ruby-progressbar (1.7.5)
56
- slop (3.6.0)
57
- thread_safe (0.3.5)
58
- tzinfo (1.2.2)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- ice_cube_cron!
66
- pry (~> 0)
67
- rake (~> 10)
68
- rspec (~> 3.3)
69
- rubocop (~> 0.34)
70
-
71
- BUNDLED WITH
72
- 1.10.6