rufus-scheduler 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,9 +21,9 @@ describe Rufus::Scheduler do
21
21
 
22
22
  it 'raises if the block to schedule is missing' do
23
23
 
24
- lambda {
24
+ expect {
25
25
  @scheduler.at(Time.now + 3600)
26
- }.should raise_error(ArgumentError)
26
+ }.to raise_error(ArgumentError)
27
27
  end
28
28
 
29
29
  it 'returns a job id' do
@@ -32,8 +32,8 @@ describe Rufus::Scheduler do
32
32
  @scheduler.at(Time.now + 3600) do
33
33
  end
34
34
 
35
- job_id.class.should == String
36
- job_id.should match(/^at_/)
35
+ expect(job_id.class).to eq(String)
36
+ expect(job_id).to match(/^at_/)
37
37
  end
38
38
 
39
39
  it 'returns a job if :job => true' do
@@ -42,7 +42,7 @@ describe Rufus::Scheduler do
42
42
  @scheduler.at(Time.now + 3600, :job => true) do
43
43
  end
44
44
 
45
- job.class.should == Rufus::Scheduler::AtJob
45
+ expect(job.class).to eq(Rufus::Scheduler::AtJob)
46
46
  end
47
47
 
48
48
  it 'adds a job' do
@@ -52,9 +52,9 @@ describe Rufus::Scheduler do
52
52
  @scheduler.at(t) do
53
53
  end
54
54
 
55
- @scheduler.jobs.size.should == 1
56
- @scheduler.jobs.first.class.should == Rufus::Scheduler::AtJob
57
- @scheduler.jobs.first.time.should == t
55
+ expect(@scheduler.jobs.size).to eq(1)
56
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::AtJob)
57
+ expect(@scheduler.jobs.first.time).to eq(t)
58
58
  end
59
59
 
60
60
  it 'triggers a job' do
@@ -67,7 +67,7 @@ describe Rufus::Scheduler do
67
67
 
68
68
  sleep 0.4
69
69
 
70
- a.should == true
70
+ expect(a).to eq(true)
71
71
  end
72
72
 
73
73
  it 'removes the job after execution' do
@@ -77,7 +77,7 @@ describe Rufus::Scheduler do
77
77
 
78
78
  sleep 0.4
79
79
 
80
- @scheduler.jobs.size.should == 0
80
+ expect(@scheduler.jobs.size).to eq(0)
81
81
  end
82
82
 
83
83
  it 'accepts a Time instance' do
@@ -86,31 +86,60 @@ describe Rufus::Scheduler do
86
86
 
87
87
  job = @scheduler.at(t, :job => true) {}
88
88
 
89
- job.time.should == t
89
+ expect(job.time).to eq(t)
90
90
  end
91
91
 
92
92
  it 'accepts a time string' do
93
93
 
94
94
  job = @scheduler.at('2100-12-12 20:30', :job => true) {}
95
95
 
96
- job.time.should == Time.parse('2100-12-12 20:30')
96
+ expect(job.time).to eq(Time.parse('2100-12-12 20:30'))
97
97
  end
98
98
 
99
99
  it 'accepts a time string with a delta timezone' do
100
100
 
101
101
  job = @scheduler.at('2100-12-12 20:30 -0200', :job => true) {}
102
102
 
103
- job.time.should == Time.parse('2100-12-12 20:30 -0200')
103
+ expect(job.time).to eq(Time.parse('2100-12-12 20:30 -0200'))
104
104
  end
105
105
 
106
106
  it 'accepts a time string with a named timezone' do
107
107
 
108
108
  job = @scheduler.at('2050-12-12 20:30 Europe/Berlin', :job => true) {}
109
109
 
110
- job.time.strftime('%c %z').should == 'Mon Dec 12 19:30:00 2050 +0000'
110
+ expect(job.time.strftime('%c %z')).to eq('Mon Dec 12 19:30:00 2050 +0000')
111
+ end
112
+
113
+ it 'accepts a Chronic string (if Chronic is present)' do
114
+
115
+ with_chronic do
116
+
117
+ job = @scheduler.schedule_at('next tuesday at 12:00') {}
118
+
119
+ expect(job.time.wday).to eq(2)
120
+ expect(job.time.hour).to eq(12)
121
+ expect(job.time.min).to eq(0)
122
+ expect(job.time).to be > Time.now
123
+ end
124
+ end
125
+
126
+ it 'accepts a Chronic string and Chronic options (if Chronic present)' do
127
+
128
+ with_chronic do
129
+
130
+ job =
131
+ @scheduler.schedule_at(
132
+ 'may 27th at 12:00', :now => Time.local(Time.now.year + 2, 1, 1)
133
+ ) {}
134
+
135
+ expect(job.time.year).to eq(Time.now.year + 2)
136
+ expect(job.time.month).to eq(5)
137
+ expect(job.time.day).to eq(27)
138
+ expect(job.time.hour).to eq(12)
139
+ expect(job.time.min).to eq(0)
140
+ end
111
141
  end
112
142
 
113
- it 'accepts a Chronic time string (if Chronic is present)'
114
143
  it 'accepts an ActiveSupport time thinggy'
115
144
  end
116
145
 
@@ -121,8 +150,8 @@ describe Rufus::Scheduler do
121
150
  job = @scheduler.schedule_at(Time.now + 3600) do
122
151
  end
123
152
 
124
- job.class.should == Rufus::Scheduler::AtJob
125
- job.id.should match(/^at_/)
153
+ expect(job.class).to eq(Rufus::Scheduler::AtJob)
154
+ expect(job.id).to match(/^at_/)
126
155
  end
127
156
  end
128
157
  end
@@ -38,16 +38,16 @@ describe Rufus::Scheduler do
38
38
  sleep_until_next_second
39
39
  sleep 0.3 # be sure to be well into the second
40
40
 
41
- counter.should == 2
41
+ expect(counter).to eq(2)
42
42
  end
43
43
 
44
44
  it 'raises if the job frequency is higher than the scheduler frequency' do
45
45
 
46
46
  @scheduler.frequency = 10
47
47
 
48
- lambda {
48
+ expect {
49
49
  @scheduler.cron '* * * * * *' do; end
50
- }.should raise_error(ArgumentError)
50
+ }.to raise_error(ArgumentError)
51
51
  end
52
52
  end
53
53
 
@@ -57,9 +57,9 @@ describe Rufus::Scheduler do
57
57
 
58
58
  job = @scheduler.schedule_cron '* * * * *' do; end
59
59
 
60
- job.class.should == Rufus::Scheduler::CronJob
61
- job.original.should == '* * * * *'
62
- job.job_id.should match(/^cron_/)
60
+ expect(job.class).to eq(Rufus::Scheduler::CronJob)
61
+ expect(job.original).to eq('* * * * *')
62
+ expect(job.job_id).to match(/^cron_/)
63
63
  end
64
64
  end
65
65
  end
@@ -24,8 +24,8 @@ describe Rufus::Scheduler do
24
24
  @scheduler.every(10) do
25
25
  end
26
26
 
27
- @scheduler.jobs.size.should == 1
28
- @scheduler.jobs.first.class.should == Rufus::Scheduler::EveryJob
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::EveryJob)
29
29
  end
30
30
 
31
31
  it 'triggers a job (2 times)' do
@@ -38,7 +38,7 @@ describe Rufus::Scheduler do
38
38
 
39
39
  sleep 2.0
40
40
 
41
- counter.should > 2
41
+ expect(counter).to be > 2
42
42
  end
43
43
 
44
44
  it 'does not remove the job after execution' do
@@ -48,23 +48,23 @@ describe Rufus::Scheduler do
48
48
 
49
49
  sleep 0.9
50
50
 
51
- @scheduler.jobs.size.should == 1
51
+ expect(@scheduler.jobs.size).to eq(1)
52
52
  end
53
53
 
54
54
  it 'raises on negative frequencies' do
55
55
 
56
- lambda {
56
+ expect {
57
57
  @scheduler.every(-1) do
58
58
  end
59
- }.should raise_error(ArgumentError)
59
+ }.to raise_error(ArgumentError)
60
60
  end
61
61
 
62
62
  it 'raises on zero frequencies' do
63
63
 
64
- lambda {
64
+ expect {
65
65
  @scheduler.every(0) do
66
66
  end
67
- }.should raise_error(ArgumentError)
67
+ }.to raise_error(ArgumentError)
68
68
  end
69
69
 
70
70
  it 'does not reschedule if the job was unscheduled' do
@@ -83,16 +83,16 @@ describe Rufus::Scheduler do
83
83
 
84
84
  sleep 1.6
85
85
 
86
- counter.should == c
86
+ expect(counter).to eq(c)
87
87
  end
88
88
 
89
89
  it 'raises if the job frequency is higher than the scheduler frequency' do
90
90
 
91
91
  @scheduler.frequency = 10
92
92
 
93
- lambda {
93
+ expect {
94
94
  @scheduler.every '1s' do; end
95
- }.should raise_error(ArgumentError)
95
+ }.to raise_error(ArgumentError)
96
96
  end
97
97
  end
98
98
 
@@ -102,7 +102,7 @@ describe Rufus::Scheduler do
102
102
 
103
103
  job = @scheduler.schedule_every('1h') do; end
104
104
 
105
- job.frequency.should == 3600.0
105
+ expect(job.frequency).to eq(3600.0)
106
106
  end
107
107
  end
108
108
  end
@@ -24,8 +24,8 @@ describe Rufus::Scheduler do
24
24
  @scheduler.in(3600) do
25
25
  end
26
26
 
27
- @scheduler.jobs.size.should == 1
28
- @scheduler.jobs.first.class.should == Rufus::Scheduler::InJob
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::InJob)
29
29
  end
30
30
 
31
31
  it 'triggers a job' do
@@ -38,7 +38,7 @@ describe Rufus::Scheduler do
38
38
 
39
39
  sleep 0.9
40
40
 
41
- a.should == true
41
+ expect(a).to eq(true)
42
42
  end
43
43
 
44
44
  it 'removes the job after execution' do
@@ -48,7 +48,7 @@ describe Rufus::Scheduler do
48
48
 
49
49
  sleep 0.700
50
50
 
51
- @scheduler.jobs.size.should == 0
51
+ expect(@scheduler.jobs.size).to eq(0)
52
52
  end
53
53
  end
54
54
 
@@ -58,16 +58,16 @@ describe Rufus::Scheduler do
58
58
 
59
59
  job = @scheduler.schedule_in(3600) {}
60
60
 
61
- job.original.should == 3600
61
+ expect(job.original).to eq(3600)
62
62
  end
63
63
 
64
64
  it 'accepts a duration string' do
65
65
 
66
66
  job = @scheduler.schedule_in('1h') {}
67
67
 
68
- job.original.should == '1h'
69
- job.time.should >= job.scheduled_at + 3509
70
- job.time.should <= job.scheduled_at + 3601
68
+ expect(job.original).to eq('1h')
69
+ expect(job.time).to be >= job.scheduled_at + 3509
70
+ expect(job.time).to be <= job.scheduled_at + 3601
71
71
  end
72
72
 
73
73
  it 'accepts an ActiveSupport .from_now thinggy'
@@ -24,8 +24,8 @@ describe Rufus::Scheduler do
24
24
  @scheduler.interval(10) do
25
25
  end
26
26
 
27
- @scheduler.jobs.size.should == 1
28
- @scheduler.jobs.first.class.should == Rufus::Scheduler::IntervalJob
27
+ expect(@scheduler.jobs.size).to eq(1)
28
+ expect(@scheduler.jobs.first.class).to eq(Rufus::Scheduler::IntervalJob)
29
29
  end
30
30
 
31
31
  it 'triggers a job (2 times)' do
@@ -38,7 +38,7 @@ describe Rufus::Scheduler do
38
38
 
39
39
  sleep 2.0
40
40
 
41
- counter.should > 2
41
+ expect(counter).to be > 2
42
42
  end
43
43
 
44
44
  it 'triggers, but reschedules after the trigger execution' do
@@ -55,7 +55,7 @@ describe Rufus::Scheduler do
55
55
  t = Time.now
56
56
  sleep 0.1 while chronos.size < 4 && Time.now < t + 5
57
57
 
58
- chronos.size.should == 4
58
+ expect(chronos.size).to eq(4)
59
59
 
60
60
  deltas = chronos.collect(&:last).compact
61
61
 
@@ -63,7 +63,7 @@ describe Rufus::Scheduler do
63
63
  #pp deltas
64
64
 
65
65
  deltas.each do |d|
66
- d.should >= 0.9
66
+ expect(d).to be >= 0.9
67
67
  end
68
68
  end
69
69
 
@@ -78,31 +78,31 @@ describe Rufus::Scheduler do
78
78
 
79
79
  sleep 1.6
80
80
 
81
- @scheduler.jobs(:all).size.should == 1
81
+ expect(@scheduler.jobs(:all).size).to eq(1)
82
82
 
83
83
  job.unschedule
84
84
  c = counter
85
85
 
86
86
  sleep 1.6
87
87
 
88
- counter.should == c
89
- @scheduler.jobs(:all).size.should == 0
88
+ expect(counter).to eq(c)
89
+ expect(@scheduler.jobs(:all).size).to eq(0)
90
90
  end
91
91
 
92
92
  it 'raises on negative intervals' do
93
93
 
94
- lambda {
94
+ expect {
95
95
  @scheduler.interval(-1) do
96
96
  end
97
- }.should raise_error(ArgumentError)
97
+ }.to raise_error(ArgumentError)
98
98
  end
99
99
 
100
100
  it 'raises on zero intervals' do
101
101
 
102
- lambda {
102
+ expect {
103
103
  @scheduler.interval(0) do
104
104
  end
105
- }.should raise_error(ArgumentError)
105
+ }.to raise_error(ArgumentError)
106
106
  end
107
107
 
108
108
  #it 'raises if the job frequency is higher than the scheduler frequency' do
@@ -121,7 +121,7 @@ describe Rufus::Scheduler do
121
121
 
122
122
  job = @scheduler.schedule_interval('1h') do; end
123
123
 
124
- job.interval.should == 3600
124
+ expect(job.interval).to eq(3600)
125
125
  end
126
126
  end
127
127
  end
@@ -20,31 +20,33 @@ describe Rufus::Scheduler do
20
20
  t[:name] == "rufus_scheduler_#{scheduler.object_id}_scheduler"
21
21
  }
22
22
 
23
- t[:rufus_scheduler].should == scheduler
23
+ expect(t[:rufus_scheduler]).to eq(scheduler)
24
24
  end
25
25
 
26
26
  it 'sets :name and :rufus_scheduler in the scheduler thread local vars' do
27
27
 
28
28
  scheduler = Rufus::Scheduler.new
29
29
 
30
- scheduler.thread[:name].should ==
30
+ expect(scheduler.thread[:name]).to eq(
31
31
  "rufus_scheduler_#{scheduler.object_id}_scheduler"
32
- scheduler.thread[:rufus_scheduler].should ==
32
+ )
33
+ expect(scheduler.thread[:rufus_scheduler]).to eq(
33
34
  scheduler
35
+ )
34
36
  end
35
37
 
36
38
  it 'accepts a :frequency => integer option' do
37
39
 
38
40
  scheduler = Rufus::Scheduler.new(:frequency => 2)
39
41
 
40
- scheduler.frequency.should == 2
42
+ expect(scheduler.frequency).to eq(2)
41
43
  end
42
44
 
43
45
  it 'accepts a :frequency => "2h1m" option' do
44
46
 
45
47
  scheduler = Rufus::Scheduler.new(:frequency => '2h1m')
46
48
 
47
- scheduler.frequency.should == 3600 * 2 + 60
49
+ expect(scheduler.frequency).to eq(3600 * 2 + 60)
48
50
  end
49
51
 
50
52
  it 'accepts a :thread_name option' do
@@ -53,7 +55,7 @@ describe Rufus::Scheduler do
53
55
 
54
56
  t = Thread.list.find { |t| t[:name] == 'oliphant' }
55
57
 
56
- t[:rufus_scheduler].should == scheduler
58
+ expect(t[:rufus_scheduler]).to eq(scheduler)
57
59
  end
58
60
 
59
61
  #it 'accepts a :min_work_threads option' do
@@ -65,7 +67,7 @@ describe Rufus::Scheduler do
65
67
 
66
68
  scheduler = Rufus::Scheduler.new(:max_work_threads => 9)
67
69
 
68
- scheduler.max_work_threads.should == 9
70
+ expect(scheduler.max_work_threads).to eq(9)
69
71
  end
70
72
  end
71
73
 
@@ -85,7 +87,7 @@ describe Rufus::Scheduler do
85
87
 
86
88
  sleep 0.4
87
89
 
88
- j.should == job
90
+ expect(j).to eq(job)
89
91
  end
90
92
 
91
93
  it 'passes the trigger time as second block argument' do
@@ -95,7 +97,7 @@ describe Rufus::Scheduler do
95
97
 
96
98
  sleep 0.4
97
99
 
98
- t.class.should == Time
100
+ expect(t.class).to eq(Time)
99
101
  end
100
102
 
101
103
  class MyHandler
@@ -116,7 +118,7 @@ describe Rufus::Scheduler do
116
118
 
117
119
  sleep 0.4
118
120
 
119
- mh.counter.should == 1
121
+ expect(mh.counter).to eq(1)
120
122
  end
121
123
 
122
124
  class MyOtherHandler
@@ -135,7 +137,7 @@ describe Rufus::Scheduler do
135
137
 
136
138
  sleep 0.4
137
139
 
138
- job.handler.counter.should == 1
140
+ expect(job.handler.counter).to eq(1)
139
141
  end
140
142
 
141
143
  it 'accepts a class as callable' do
@@ -150,16 +152,16 @@ describe Rufus::Scheduler do
150
152
 
151
153
  sleep 0.4
152
154
 
153
- job.handler.value.should == 7
155
+ expect(job.handler.value).to eq(7)
154
156
  end
155
157
 
156
158
  it 'raises if the scheduler is shutting down' do
157
159
 
158
160
  @scheduler.shutdown
159
161
 
160
- lambda {
162
+ expect {
161
163
  @scheduler.in('0s') { puts 'hhhhhhhhhhhello!!' }
162
- }.should raise_error(Rufus::Scheduler::NotRunningError)
164
+ }.to raise_error(Rufus::Scheduler::NotRunningError)
163
165
  end
164
166
  end
165
167
 
@@ -196,23 +198,23 @@ describe Rufus::Scheduler do
196
198
 
197
199
  j = @scheduler.schedule '1s' do; end
198
200
 
199
- j.class.should == Rufus::Scheduler::InJob
200
- j.original.should == '1s'
201
+ expect(j.class).to eq(Rufus::Scheduler::InJob)
202
+ expect(j.original).to eq('1s')
201
203
  end
202
204
 
203
205
  it 'accepts a point in time and schedules an AtJob' do
204
206
 
205
207
  j = @scheduler.schedule '2070/12/24 23:00' do; end
206
208
 
207
- j.class.should == Rufus::Scheduler::AtJob
208
- j.next_time.strftime('%Y %m %d').should == '2070 12 24'
209
+ expect(j.class).to eq(Rufus::Scheduler::AtJob)
210
+ expect(j.next_time.strftime('%Y %m %d')).to eq('2070 12 24')
209
211
  end
210
212
 
211
213
  it 'accepts a cron string and schedules a CronJob' do
212
214
 
213
215
  j = @scheduler.schedule '* * * * *' do; end
214
216
 
215
- j.class.should == Rufus::Scheduler::CronJob
217
+ expect(j.class).to eq(Rufus::Scheduler::CronJob)
216
218
  end
217
219
  end
218
220
 
@@ -222,14 +224,14 @@ describe Rufus::Scheduler do
222
224
 
223
225
  j = @scheduler.repeat '1s' do; end
224
226
 
225
- j.class.should == Rufus::Scheduler::EveryJob
227
+ expect(j.class).to eq(Rufus::Scheduler::EveryJob)
226
228
  end
227
229
 
228
230
  it 'accepts a cron string and schedules a CronJob' do
229
231
 
230
232
  j = @scheduler.repeat '* * * * *' do; end
231
233
 
232
- j.class.should == Rufus::Scheduler::CronJob
234
+ expect(j.class).to eq(Rufus::Scheduler::CronJob)
233
235
  end
234
236
  end
235
237
 
@@ -239,22 +241,22 @@ describe Rufus::Scheduler do
239
241
 
240
242
  job = @scheduler.schedule_in '10d' do; end
241
243
 
242
- job.unscheduled_at.should == nil
244
+ expect(job.unscheduled_at).to eq(nil)
243
245
 
244
246
  @scheduler.unschedule(job.id)
245
247
 
246
- job.unscheduled_at.should_not == nil
248
+ expect(job.unscheduled_at).not_to eq(nil)
247
249
  end
248
250
 
249
251
  it 'accepts jobs' do
250
252
 
251
253
  job = @scheduler.schedule_in '10d' do; end
252
254
 
253
- job.unscheduled_at.should == nil
255
+ expect(job.unscheduled_at).to eq(nil)
254
256
 
255
257
  @scheduler.unschedule(job)
256
258
 
257
- job.unscheduled_at.should_not == nil
259
+ expect(job.unscheduled_at).not_to eq(nil)
258
260
  end
259
261
 
260
262
  it 'carefully unschedules repeat jobs' do
@@ -272,7 +274,7 @@ describe Rufus::Scheduler do
272
274
  @scheduler.unschedule(job)
273
275
 
274
276
  sleep 1.5
275
- counter.should == c
277
+ expect(counter).to eq(c)
276
278
  end
277
279
  end
278
280
 
@@ -280,7 +282,7 @@ describe Rufus::Scheduler do
280
282
 
281
283
  it 'returns the uptime as a float' do
282
284
 
283
- @scheduler.uptime.should >= 0.0
285
+ expect(@scheduler.uptime).to be >= 0.0
284
286
  end
285
287
  end
286
288
 
@@ -290,7 +292,7 @@ describe Rufus::Scheduler do
290
292
 
291
293
  sleep 1
292
294
 
293
- @scheduler.uptime_s.should match(/^[12]s\d+$/)
295
+ expect(@scheduler.uptime_s).to match(/^[12]s\d+$/)
294
296
  end
295
297
  end
296
298
 
@@ -300,13 +302,13 @@ describe Rufus::Scheduler do
300
302
 
301
303
  t = Thread.new { @scheduler.join; Thread.current['a'] = 'over' }
302
304
 
303
- t['a'].should == nil
305
+ expect(t['a']).to eq(nil)
304
306
 
305
307
  @scheduler.shutdown
306
308
 
307
309
  sleep(1)
308
310
 
309
- t['a'].should == 'over'
311
+ expect(t['a']).to eq('over')
310
312
  end
311
313
  end
312
314
 
@@ -314,7 +316,7 @@ describe Rufus::Scheduler do
314
316
 
315
317
  it 'returns nil if there is no corresponding Job instance' do
316
318
 
317
- @scheduler.job('nada').should == nil
319
+ expect(@scheduler.job('nada')).to eq(nil)
318
320
  end
319
321
 
320
322
  it 'returns the corresponding Job instance' do
@@ -323,7 +325,7 @@ describe Rufus::Scheduler do
323
325
 
324
326
  sleep(1) # give it some time to get scheduled
325
327
 
326
- @scheduler.job(job_id).job_id.should == job_id
328
+ expect(@scheduler.job(job_id).job_id).to eq(job_id)
327
329
  end
328
330
  end
329
331
 
@@ -353,7 +355,7 @@ describe Rufus::Scheduler do
353
355
 
354
356
  it 'just lists the main thread (scheduler thread) when no job is scheduled' do
355
357
 
356
- @scheduler.threads.should == [ @scheduler.thread ]
358
+ expect(@scheduler.threads).to eq([ @scheduler.thread ])
357
359
  end
358
360
 
359
361
  it 'lists all the threads a scheduler uses' do
@@ -364,7 +366,7 @@ describe Rufus::Scheduler do
364
366
 
365
367
  sleep 0.4
366
368
 
367
- @scheduler.threads.size.should == 2
369
+ expect(@scheduler.threads.size).to eq(2)
368
370
  end
369
371
  end
370
372
 
@@ -372,9 +374,9 @@ describe Rufus::Scheduler do
372
374
 
373
375
  it 'returns an empty array when the scheduler has not yet done anything' do
374
376
 
375
- @scheduler.work_threads.should == []
376
- @scheduler.work_threads(:all).should == []
377
- @scheduler.work_threads(:vacant).should == []
377
+ expect(@scheduler.work_threads).to eq([])
378
+ expect(@scheduler.work_threads(:all)).to eq([])
379
+ expect(@scheduler.work_threads(:vacant)).to eq([])
378
380
  end
379
381
 
380
382
  it 'lists the [vacant] work threads in the pool' do
@@ -389,13 +391,13 @@ describe Rufus::Scheduler do
389
391
  sleep 0.7
390
392
 
391
393
  if @scheduler.work_threads.size == 1
392
- @scheduler.work_threads.size.should == 1
393
- @scheduler.work_threads(:all).size.should == 1
394
- @scheduler.work_threads(:vacant).size.should == 0
394
+ expect(@scheduler.work_threads.size).to eq(1)
395
+ expect(@scheduler.work_threads(:all).size).to eq(1)
396
+ expect(@scheduler.work_threads(:vacant).size).to eq(0)
395
397
  else
396
- @scheduler.work_threads.size.should == 2
397
- @scheduler.work_threads(:all).size.should == 2
398
- @scheduler.work_threads(:vacant).size.should == 1
398
+ expect(@scheduler.work_threads.size).to eq(2)
399
+ expect(@scheduler.work_threads(:all).size).to eq(2)
400
+ expect(@scheduler.work_threads(:vacant).size).to eq(1)
399
401
  end
400
402
  end
401
403
  end
@@ -404,7 +406,7 @@ describe Rufus::Scheduler do
404
406
 
405
407
  it 'returns [] when there are no jobs running' do
406
408
 
407
- @scheduler.work_threads(:active).should == []
409
+ expect(@scheduler.work_threads(:active)).to eq([])
408
410
  end
409
411
 
410
412
  it 'returns the list of threads of the running jobs' do
@@ -416,14 +418,14 @@ describe Rufus::Scheduler do
416
418
 
417
419
  sleep 0.4
418
420
 
419
- @scheduler.work_threads(:active).size.should == 1
421
+ expect(@scheduler.work_threads(:active).size).to eq(1)
420
422
 
421
423
  t = @scheduler.work_threads(:active).first
422
424
 
423
- t.class.should == Thread
424
- t[@scheduler.thread_key].should == true
425
- t[:rufus_scheduler_job].should == job
426
- t[:rufus_scheduler_time].should_not == nil
425
+ expect(t.class).to eq(Thread)
426
+ expect(t[@scheduler.thread_key]).to eq(true)
427
+ expect(t[:rufus_scheduler_job]).to eq(job)
428
+ expect(t[:rufus_scheduler_time]).not_to eq(nil)
427
429
  end
428
430
 
429
431
  it 'does not return threads from other schedulers' do
@@ -437,7 +439,7 @@ describe Rufus::Scheduler do
437
439
 
438
440
  sleep 0.4
439
441
 
440
- scheduler.work_threads(:active).should == []
442
+ expect(scheduler.work_threads(:active)).to eq([])
441
443
 
442
444
  scheduler.shutdown
443
445
  end
@@ -459,7 +461,7 @@ describe Rufus::Scheduler do
459
461
 
460
462
  it 'returns the max job thread count' do
461
463
 
462
- @scheduler.max_work_threads.should == 28
464
+ expect(@scheduler.max_work_threads).to eq(28)
463
465
  end
464
466
  end
465
467
 
@@ -469,7 +471,7 @@ describe Rufus::Scheduler do
469
471
 
470
472
  @scheduler.max_work_threads = 14
471
473
 
472
- @scheduler.max_work_threads.should == 14
474
+ expect(@scheduler.max_work_threads).to eq(14)
473
475
  end
474
476
  end
475
477
 
@@ -497,7 +499,7 @@ describe Rufus::Scheduler do
497
499
 
498
500
  it 'returns [] when there are no running jobs' do
499
501
 
500
- @scheduler.running_jobs.should == []
502
+ expect(@scheduler.running_jobs).to eq([])
501
503
  end
502
504
 
503
505
  it 'returns a list of running Job instances' do
@@ -509,8 +511,8 @@ describe Rufus::Scheduler do
509
511
 
510
512
  sleep 0.4
511
513
 
512
- job.running?.should == true
513
- @scheduler.running_jobs.should == [ job ]
514
+ expect(job.running?).to eq(true)
515
+ expect(@scheduler.running_jobs).to eq([ job ])
514
516
  end
515
517
 
516
518
  it 'does not return twice the same job' do
@@ -522,8 +524,8 @@ describe Rufus::Scheduler do
522
524
 
523
525
  sleep 1.5
524
526
 
525
- job.running?.should == true
526
- @scheduler.running_jobs.should == [ job ]
527
+ expect(job.running?).to eq(true)
528
+ expect(@scheduler.running_jobs).to eq([ job ])
527
529
  end
528
530
  end
529
531
 
@@ -540,12 +542,15 @@ describe Rufus::Scheduler do
540
542
 
541
543
  sleep 0.4
542
544
 
543
- @scheduler.running_jobs(:tag => 't0').map(&:original).should ==
545
+ expect(@scheduler.running_jobs(:tag => 't0').map(&:original)).to eq(
544
546
  %w[ 0.1s ]
545
- @scheduler.running_jobs(:tag => 't1').map(&:original).should ==
547
+ )
548
+ expect(@scheduler.running_jobs(:tag => 't1').map(&:original)).to eq(
546
549
  %w[ 0.2s ]
547
- @scheduler.running_jobs(:tags => %w[ t0 t1 ]).map(&:original).should ==
550
+ )
551
+ expect(@scheduler.running_jobs(:tags => %w[ t0 t1 ]).map(&:original)).to eq(
548
552
  []
553
+ )
549
554
  end
550
555
  end
551
556
 
@@ -561,12 +566,12 @@ describe Rufus::Scheduler do
561
566
 
562
567
  h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 11 * 60)
563
568
 
564
- h.size.should == 5
565
- h[j0].should == [ j0.next_time ]
566
- h[j1].should == [ j1.next_time ]
567
- h[j2].size.should == 2
568
- h[j3].size.should == 2
569
- h[j4].size.should == 7
569
+ expect(h.size).to eq(5)
570
+ expect(h[j0]).to eq([ j0.next_time ])
571
+ expect(h[j1]).to eq([ j1.next_time ])
572
+ expect(h[j2].size).to eq(2)
573
+ expect(h[j3].size).to eq(2)
574
+ expect(h[j4].size).to eq(7)
570
575
  end
571
576
 
572
577
  it 'returns a [ [ time, job ], ... ] of job occurrences when :timeline' do
@@ -577,10 +582,10 @@ describe Rufus::Scheduler do
577
582
  a =
578
583
  @scheduler.occurrences(Time.now + 4 * 60, Time.now + 11 * 60, :timeline)
579
584
 
580
- a[0][0].should be_within_1s_of(Time.now + 5 * 60)
581
- a[0][1].should == j0
582
- a[1][0].should be_within_1s_of(Time.now + 10 * 60)
583
- a[1][1].should == j1
585
+ expect(a[0][0]).to be_within_1s_of(Time.now + 5 * 60)
586
+ expect(a[0][1]).to eq(j0)
587
+ expect(a[1][0]).to be_within_1s_of(Time.now + 10 * 60)
588
+ expect(a[1][1]).to eq(j1)
584
589
  end
585
590
 
586
591
  it 'respects :first_at for repeat jobs' do
@@ -589,8 +594,8 @@ describe Rufus::Scheduler do
589
594
 
590
595
  h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 16 * 60)
591
596
 
592
- h[j0][0].should be_within_1s_of(Time.now + 10 * 60)
593
- h[j0][1].should be_within_1s_of(Time.now + 15 * 60)
597
+ expect(h[j0][0]).to be_within_1s_of(Time.now + 10 * 60)
598
+ expect(h[j0][1]).to be_within_1s_of(Time.now + 15 * 60)
594
599
  end
595
600
 
596
601
  it 'respects :times for repeat jobs' do
@@ -599,7 +604,7 @@ describe Rufus::Scheduler do
599
604
 
600
605
  h = @scheduler.occurrences(Time.now + 4 * 60, Time.now + 16 * 60)
601
606
 
602
- h[j0].size.should == 6
607
+ expect(h[j0].size).to eq(6)
603
608
  end
604
609
  end
605
610
 
@@ -612,10 +617,10 @@ describe Rufus::Scheduler do
612
617
 
613
618
  a = @scheduler.timeline(Time.now + 4 * 60, Time.now + 11 * 60)
614
619
 
615
- a[0][0].should be_within_1s_of(Time.now + 5 * 60)
616
- a[0][1].should == j0
617
- a[1][0].should be_within_1s_of(Time.now + 10 * 60)
618
- a[1][1].should == j1
620
+ expect(a[0][0]).to be_within_1s_of(Time.now + 5 * 60)
621
+ expect(a[0][1]).to eq(j0)
622
+ expect(a[1][0]).to be_within_1s_of(Time.now + 10 * 60)
623
+ expect(a[1][1]).to eq(j1)
619
624
  end
620
625
  end
621
626
 
@@ -629,7 +634,7 @@ describe Rufus::Scheduler do
629
634
 
630
635
  @scheduler.shutdown
631
636
 
632
- @scheduler.uptime.should == nil
637
+ expect(@scheduler.uptime).to eq(nil)
633
638
  end
634
639
 
635
640
  it 'shuts the scheduler down' do
@@ -643,14 +648,14 @@ describe Rufus::Scheduler do
643
648
  t[:name] == "rufus_scheduler_#{@scheduler.object_id}"
644
649
  }
645
650
 
646
- t.should == nil
651
+ expect(t).to eq(nil)
647
652
  end
648
653
 
649
654
  it 'has a #stop alias' do
650
655
 
651
656
  @scheduler.stop
652
657
 
653
- @scheduler.uptime.should == nil
658
+ expect(@scheduler.uptime).to eq(nil)
654
659
  end
655
660
 
656
661
  #it 'has a #close alias'
@@ -671,10 +676,10 @@ describe Rufus::Scheduler do
671
676
 
672
677
  @scheduler.shutdown(:wait)
673
678
 
674
- counter.should == 1
675
- @scheduler.uptime.should == nil
676
- @scheduler.running_jobs.should == []
677
- @scheduler.threads.should == []
679
+ expect(counter).to eq(1)
680
+ expect(@scheduler.uptime).to eq(nil)
681
+ expect(@scheduler.running_jobs).to eq([])
682
+ expect(@scheduler.threads).to eq([])
678
683
  end
679
684
  end
680
685
 
@@ -699,10 +704,10 @@ describe Rufus::Scheduler do
699
704
 
700
705
  sleep 1.4
701
706
 
702
- counter.should == 0
703
- @scheduler.uptime.should == nil
704
- @scheduler.running_jobs.should == []
705
- @scheduler.threads.should == []
707
+ expect(counter).to eq(0)
708
+ expect(@scheduler.uptime).to eq(nil)
709
+ expect(@scheduler.running_jobs).to eq([])
710
+ expect(@scheduler.threads).to eq([])
706
711
  end
707
712
  end
708
713
 
@@ -716,7 +721,7 @@ describe Rufus::Scheduler do
716
721
 
717
722
  sleep(3)
718
723
 
719
- job.last_time.should == nil
724
+ expect(job.last_time).to eq(nil)
720
725
  end
721
726
  end
722
727
 
@@ -731,7 +736,7 @@ describe Rufus::Scheduler do
731
736
  @scheduler.resume
732
737
  sleep(2)
733
738
 
734
- job.last_time.should_not == nil
739
+ expect(job.last_time).not_to eq(nil)
735
740
  end
736
741
  end
737
742
 
@@ -740,17 +745,17 @@ describe Rufus::Scheduler do
740
745
  it 'returns true if the scheduler is paused' do
741
746
 
742
747
  @scheduler.pause
743
- @scheduler.paused?.should == true
748
+ expect(@scheduler.paused?).to eq(true)
744
749
  end
745
750
 
746
751
  it 'returns false if the scheduler is not paused' do
747
752
 
748
- @scheduler.paused?.should == false
753
+ expect(@scheduler.paused?).to eq(false)
749
754
 
750
755
  @scheduler.pause
751
756
  @scheduler.resume
752
757
 
753
- @scheduler.paused?.should == false
758
+ expect(@scheduler.paused?).to eq(false)
754
759
  end
755
760
  end
756
761
 
@@ -760,12 +765,20 @@ describe Rufus::Scheduler do
760
765
 
761
766
  @scheduler.shutdown
762
767
 
763
- @scheduler.down?.should == true
768
+ expect(@scheduler.down?).to eq(true)
764
769
  end
765
770
 
766
771
  it 'returns false when the scheduler is up' do
767
772
 
768
- @scheduler.down?.should == false
773
+ expect(@scheduler.down?).to eq(false)
774
+ end
775
+ end
776
+
777
+ describe '#up?' do
778
+
779
+ it 'returns true when the scheduler is up' do
780
+
781
+ expect(@scheduler.up?).to eq(true)
769
782
  end
770
783
  end
771
784
 
@@ -777,7 +790,7 @@ describe Rufus::Scheduler do
777
790
 
778
791
  it 'is empty at the beginning' do
779
792
 
780
- @scheduler.jobs.should == []
793
+ expect(@scheduler.jobs).to eq([])
781
794
  end
782
795
 
783
796
  it 'returns the list of scheduled jobs' do
@@ -789,7 +802,7 @@ describe Rufus::Scheduler do
789
802
 
790
803
  jobs = @scheduler.jobs
791
804
 
792
- jobs.collect { |j| j.original }.sort.should == %w[ 10d 1w ]
805
+ expect(jobs.collect { |j| j.original }.sort).to eq(%w[ 10d 1w ])
793
806
  end
794
807
 
795
808
  it 'returns all the jobs (even those pending reschedule)' do
@@ -800,7 +813,7 @@ describe Rufus::Scheduler do
800
813
 
801
814
  sleep 0.4
802
815
 
803
- @scheduler.jobs.size.should == 1
816
+ expect(@scheduler.jobs.size).to eq(1)
804
817
  end
805
818
 
806
819
  it 'does not return unscheduled jobs' do
@@ -814,7 +827,7 @@ describe Rufus::Scheduler do
814
827
 
815
828
  job.unschedule
816
829
 
817
- @scheduler.jobs.size.should == 0
830
+ expect(@scheduler.jobs.size).to eq(0)
818
831
  end
819
832
  end
820
833
 
@@ -822,8 +835,8 @@ describe Rufus::Scheduler do
822
835
 
823
836
  it 'returns [] when there are no jobs with the corresponding tag' do
824
837
 
825
- @scheduler.jobs(:tag => 'nada').should == []
826
- @scheduler.jobs(:tags => %w[ nada hello ]).should == []
838
+ expect(@scheduler.jobs(:tag => 'nada')).to eq([])
839
+ expect(@scheduler.jobs(:tags => %w[ nada hello ])).to eq([])
827
840
  end
828
841
 
829
842
  it 'returns the jobs with the corresponding tag' do
@@ -832,12 +845,15 @@ describe Rufus::Scheduler do
832
845
  @scheduler.every '2h', :tag => %w[ t0 t1 ] do; end
833
846
  @scheduler.every '3h' do; end
834
847
 
835
- @scheduler.jobs(:tags => 't0').map(&:original).sort.should ==
848
+ expect(@scheduler.jobs(:tags => 't0').map(&:original).sort).to eq(
836
849
  %w[ 10d 2h ]
837
- @scheduler.jobs(:tags => 't1').map(&:original).sort.should ==
850
+ )
851
+ expect(@scheduler.jobs(:tags => 't1').map(&:original).sort).to eq(
838
852
  %w[ 2h ]
839
- @scheduler.jobs(:tags => [ 't1', 't0' ]).map(&:original).sort.should ==
853
+ )
854
+ expect(@scheduler.jobs(:tags => [ 't1', 't0' ]).map(&:original).sort).to eq(
840
855
  %w[ 2h ]
856
+ )
841
857
  end
842
858
  end
843
859
 
@@ -851,7 +867,7 @@ describe Rufus::Scheduler do
851
867
 
852
868
  jobs = @scheduler.every_jobs
853
869
 
854
- jobs.collect { |j| j.original }.sort.should == %w[ 5m ]
870
+ expect(jobs.collect { |j| j.original }.sort).to eq(%w[ 5m ])
855
871
  end
856
872
  end
857
873
 
@@ -865,7 +881,7 @@ describe Rufus::Scheduler do
865
881
 
866
882
  jobs = @scheduler.at_jobs
867
883
 
868
- jobs.collect { |j| j.original }.sort.should == [ '2030/12/12 12:10:00' ]
884
+ expect(jobs.collect { |j| j.original }.sort).to eq([ '2030/12/12 12:10:00' ])
869
885
  end
870
886
  end
871
887
 
@@ -879,7 +895,7 @@ describe Rufus::Scheduler do
879
895
 
880
896
  jobs = @scheduler.in_jobs
881
897
 
882
- jobs.collect { |j| j.original }.sort.should == %w[ 10d ]
898
+ expect(jobs.collect { |j| j.original }.sort).to eq(%w[ 10d ])
883
899
  end
884
900
  end
885
901
 
@@ -894,7 +910,7 @@ describe Rufus::Scheduler do
894
910
 
895
911
  jobs = @scheduler.cron_jobs
896
912
 
897
- jobs.collect { |j| j.original }.sort.should == [ '* * * * *' ]
913
+ expect(jobs.collect { |j| j.original }.sort).to eq([ '* * * * *' ])
898
914
  end
899
915
  end
900
916
 
@@ -910,7 +926,7 @@ describe Rufus::Scheduler do
910
926
 
911
927
  jobs = @scheduler.interval_jobs
912
928
 
913
- jobs.collect { |j| j.original }.sort.should == %w[ 7m ]
929
+ expect(jobs.collect { |j| j.original }.sort).to eq(%w[ 7m ])
914
930
  end
915
931
  end
916
932
 
@@ -935,7 +951,7 @@ describe Rufus::Scheduler do
935
951
 
936
952
  sleep 0.7
937
953
 
938
- $out.should == [ "pre #{job_id}", job_id ]
954
+ expect($out).to eq([ "pre #{job_id}", job_id ])
939
955
  end
940
956
 
941
957
  it 'accepts the job and the triggerTime as argument' do
@@ -952,9 +968,9 @@ describe Rufus::Scheduler do
952
968
 
953
969
  sleep 0.7
954
970
 
955
- $tt.class.should == Time
956
- $tt.should > start
957
- $tt.should < Time.now
971
+ expect($tt.class).to eq(Time)
972
+ expect($tt).to be > start
973
+ expect($tt).to be < Time.now
958
974
  end
959
975
 
960
976
  context 'when it returns false' do
@@ -975,7 +991,7 @@ describe Rufus::Scheduler do
975
991
 
976
992
  sleep 0.7
977
993
 
978
- $out.should == [ "pre #{job_id}" ]
994
+ expect($out).to eq([ "pre #{job_id}" ])
979
995
  end
980
996
  end
981
997
  end
@@ -997,7 +1013,7 @@ describe Rufus::Scheduler do
997
1013
 
998
1014
  sleep 0.7
999
1015
 
1000
- $out.should == [ job_id, "post #{job_id}" ]
1016
+ expect($out).to eq([ job_id, "post #{job_id}" ])
1001
1017
  end
1002
1018
  end
1003
1019
 
@@ -1017,8 +1033,8 @@ describe Rufus::Scheduler do
1017
1033
  s0 = Rufus::Scheduler.singleton
1018
1034
  s1 = Rufus::Scheduler.s
1019
1035
 
1020
- s0.class.should == Rufus::Scheduler
1021
- s1.object_id.should == s0.object_id
1036
+ expect(s0.class).to eq(Rufus::Scheduler)
1037
+ expect(s1.object_id).to eq(s0.object_id)
1022
1038
  end
1023
1039
 
1024
1040
  it 'accepts initialization parameters' do
@@ -1026,7 +1042,7 @@ describe Rufus::Scheduler do
1026
1042
  s = Rufus::Scheduler.singleton(:max_work_threads => 77)
1027
1043
  s = Rufus::Scheduler.singleton(:max_work_threads => 42)
1028
1044
 
1029
- s.max_work_threads.should == 77
1045
+ expect(s.max_work_threads).to eq(77)
1030
1046
  end
1031
1047
  end
1032
1048
  end