spec/job_spec.rb in rufus-scheduler-3.0.7 vs spec/job_spec.rb in rufus-scheduler-3.0.8
- old
+ new
@@ -36,39 +36,39 @@
it 'returns nil if the job never fired' do
job = @scheduler.schedule_in '10d' do; end
- job.last_time.should == nil
+ expect(job.last_time).to eq(nil)
end
it 'returns the last time the job fired' do
job = @scheduler.schedule_in '0s' do; end
sleep 0.4
- job.last_time.should_not == nil
+ expect(job.last_time).not_to eq(nil)
end
end
describe '#threads' do
it 'returns an empty list when the job is not running' do
job = @scheduler.in('1d', :job => true) {}
- job.threads.size.should == 0
+ expect(job.threads.size).to eq(0)
end
it 'returns an empty list after the job terminated' do
job = @scheduler.in('0s', :job => true) {}
sleep 0.8
- job.threads.size.should == 0
+ expect(job.threads.size).to eq(0)
end
it 'lists the threads the job currently runs in' do
job =
@@ -76,14 +76,14 @@
sleep(1)
end
sleep 0.4
- job.threads.size.should == 1
+ expect(job.threads.size).to eq(1)
t = job.threads.first
- t[:rufus_scheduler_job].should == job
+ expect(t[:rufus_scheduler_job]).to eq(job)
end
end
describe '#kill' do
@@ -93,11 +93,11 @@
tls = Thread.list.size
job.kill
- Thread.list.size.should == tls
+ expect(Thread.list.size).to eq(tls)
end
it 'makes the threads vacant' do
counter = 0
@@ -118,65 +118,65 @@
sleep 2
v1 = @scheduler.work_threads(:vacant).size
a1 = @scheduler.work_threads(:active).size
- counter.should == 0
+ expect(counter).to eq(0)
- v0.should == 0
- a0.should == 1
+ expect(v0).to eq(0)
+ expect(a0).to eq(1)
- v1.should == 1
- a1.should == 0
+ expect(v1).to eq(1)
+ expect(a1).to eq(0)
end
end
describe '#running?' do
it 'returns false when the job is not running in any thread' do
job = @scheduler.in('1d', :job => true) {}
- job.running?.should == false
+ expect(job.running?).to eq(false)
end
it 'returns true when the job is running in at least one thread' do
job = @scheduler.in('0s', :job => true) { sleep(1) }
sleep 0.4
- job.running?.should == true
+ expect(job.running?).to eq(true)
end
end
describe '#scheduled?' do
it 'returns true when the job is scheduled' do
job = @scheduler.schedule_in('1d') {}
- job.scheduled?.should == true
+ expect(job.scheduled?).to eq(true)
end
it 'returns false when the job is not scheduled' do
job = @scheduler.schedule_in('0.1s') {}
sleep 0.4
- job.scheduled?.should == false
+ expect(job.scheduled?).to eq(false)
end
it 'returns true for repeat jobs that are running' do
job = @scheduler.schedule_interval('0.4s') { sleep(10) }
sleep 1
- job.running?.should == true
- job.scheduled?.should == true
+ expect(job.running?).to eq(true)
+ expect(job.scheduled?).to eq(true)
end
end
describe '#call' do
@@ -190,11 +190,11 @@
end
job.call
sleep 0.8
- counter.should == 2
+ expect(counter).to eq(2)
end
end
describe '#call(true)' do
@@ -213,11 +213,11 @@
fail 'again'
end
job.call(true)
- $err.should == 'Rufus::Scheduler::InJob 1d again'
+ expect($err).to eq('Rufus::Scheduler::InJob 1d again')
end
end
describe '#call(false)' do
@@ -231,15 +231,15 @@
begin
#job.call(false)
job.call # false is the default
- false.should == true
+ expect(false).to eq(true)
rescue => ex
- ex.message.should == 'fast'
+ expect(ex.message).to eq('fast')
end
end
end
context 'job-local variables' do
@@ -254,40 +254,40 @@
job[:counter] += 1
end
sleep 3
- job[:counter].should > 1
+ expect(job[:counter]).to be > 1
end
end
describe '#[]' do
it 'returns nil if there is no such entry' do
job = @scheduler.schedule_in '1s' do; end
- job[:nada].should == nil
+ expect(job[:nada]).to eq(nil)
end
it 'returns the value of a job-local variable' do
job = @scheduler.schedule_in '1s' do; end
job[:x] = :y
- job[:x].should == :y
+ expect(job[:x]).to eq(:y)
end
end
describe '#key?' do
it 'returns true if there is an entry with the given key' do
job = @scheduler.schedule_in '1s' do; end
job[:x] = :y
- job.key?(:x).should == true
+ expect(job.key?(:x)).to eq(true)
end
end
describe '#keys' do
@@ -296,36 +296,36 @@
job = @scheduler.schedule_in '1s' do; end
job[:x] = :y
job['hello'] = :z
job[123] = {}
- job.keys.sort_by { |k| k.to_s }.should == [ 123, 'hello', :x ]
+ expect(job.keys.sort_by { |k| k.to_s }).to eq([ 123, 'hello', :x ])
end
end
end
context ':tag / :tags => [ t0, t1 ]' do
it 'accepts one tag' do
job = @scheduler.in '10d', :job => true, :tag => 't0' do; end
- job.tags.should == %w[ t0 ]
+ expect(job.tags).to eq(%w[ t0 ])
end
it 'accepts an array of tags' do
job = @scheduler.in '10d', :job => true, :tag => %w[ t0 t1 ] do; end
- job.tags.should == %w[ t0 t1 ]
+ expect(job.tags).to eq(%w[ t0 t1 ])
end
it 'turns tags into strings' do
job = @scheduler.in '10d', :job => true, :tags => [ 1, 2 ] do; end
- job.tags.should == %w[ 1 2 ]
+ expect(job.tags).to eq(%w[ 1 2 ])
end
end
context ':blocking => true' do
@@ -336,15 +336,15 @@
sleep(1)
end
sleep 0.4
- job.threads.first.should == @scheduler.thread
+ expect(job.threads.first).to eq(@scheduler.thread)
sleep 1.4
- job.threads.size.should == 0
+ expect(job.threads.size).to eq(0)
end
end
context 'default one thread per job behaviour' do
@@ -355,15 +355,15 @@
sleep(1)
end
sleep 0.4
- job.threads.first.should_not == @scheduler.thread
+ expect(job.threads.first).not_to eq(@scheduler.thread)
sleep 1.4
- job.threads.size.should == 0
+ expect(job.threads.size).to eq(0)
end
end
context ':allow_overlapping / :allow_overlap / :overlap' do
@@ -376,11 +376,11 @@
sleep(5)
end
sleep 3
- job.threads.size.should > 1
+ expect(job.threads.size).to be > 1
end
end
context 'when :overlap => false' do
@@ -391,11 +391,11 @@
sleep(5)
end
sleep 3
- job.threads.size.should == 1
+ expect(job.threads.size).to eq(1)
end
end
end
context ':mutex' do
@@ -414,18 +414,18 @@
end
sleep 0.7
if j0.threads.any?
- j0.threads.size.should == 1
- j1.threads.size.should == 0
+ expect(j0.threads.size).to eq(1)
+ expect(j1.threads.size).to eq(0)
else
- j0.threads.size.should == 0
- j1.threads.size.should == 1
+ expect(j0.threads.size).to eq(0)
+ expect(j1.threads.size).to eq(1)
end
- @scheduler.mutexes.keys.should == %w[ vladivostok ]
+ expect(@scheduler.mutexes.keys).to eq(%w[ vladivostok ])
end
end
context ':mutex => mutex_instance' do
@@ -437,18 +437,18 @@
j1 = @scheduler.in('0s', :job => true, :mutex => m) { sleep(3) }
sleep 0.7
if j0.threads.any?
- j0.threads.size.should == 1
- j1.threads.size.should == 0
+ expect(j0.threads.size).to eq(1)
+ expect(j1.threads.size).to eq(0)
else
- j0.threads.size.should == 0
- j1.threads.size.should == 1
+ expect(j0.threads.size).to eq(0)
+ expect(j1.threads.size).to eq(1)
end
- @scheduler.mutexes.keys.should == []
+ expect(@scheduler.mutexes.keys).to eq([])
end
end
context ':mutex => [ array_of_mutex_names_or_instances ]' do
@@ -464,18 +464,18 @@
end
sleep 0.7
if j0.threads.any?
- j0.threads.size.should == 1
- j1.threads.size.should == 0
+ expect(j0.threads.size).to eq(1)
+ expect(j1.threads.size).to eq(0)
else
- j0.threads.size.should == 0
- j1.threads.size.should == 1
+ expect(j0.threads.size).to eq(0)
+ expect(j1.threads.size).to eq(1)
end
- @scheduler.mutexes.keys.sort.should == %w[ a b ]
+ expect(@scheduler.mutexes.keys.sort).to eq(%w[ a b ])
end
end
end
context ':timeout => duration_or_point_in_time' do
@@ -496,12 +496,12 @@
end
end
sleep(3)
- counter.should == 1
- toe.class.should == Rufus::Scheduler::TimeoutError
+ expect(counter).to eq(1)
+ expect(toe.class).to eq(Rufus::Scheduler::TimeoutError)
end
it 'interrupts the job it is stashed to (point in time)' do
counter = 0
@@ -516,11 +516,11 @@
end
end
sleep(3)
- counter.should == 1
+ expect(counter).to eq(1)
end
it 'starts timing when the job enters successfully all its mutexes' do
t0, t1, t2 = nil
@@ -540,26 +540,26 @@
end
end
sleep 3
- t0.should <= t1
+ expect(t0).to be <= t1
d = t2 - t1
- d.should >= 1.0
- d.should < 1.5
+ expect(d).to be >= 1.0
+ expect(d).to be < 1.5
end
it 'emits the timeout information to $stderr (default #on_error)' do
@scheduler.every('1s', :timeout => '0.5s') do
sleep 0.9
end
sleep 2
- $stderr.string.should match(/Rufus::Scheduler::TimeoutError/)
+ expect($stderr.string).to match(/Rufus::Scheduler::TimeoutError/)
end
it 'does not prevent a repeat job from recurring' do
counter = 0
@@ -569,11 +569,11 @@
sleep 0.9
end
sleep 3
- counter.should > 1
+ expect(counter).to be > 1
end
end
context 'work time' do
@@ -581,11 +581,11 @@
it 'starts at 0' do
job = @scheduler.schedule_every '5m' do; end
- job.last_work_time.should == 0.0
+ expect(job.last_work_time).to eq(0.0)
end
it 'keeps track of how long the work was upon last trigger' do
job =
@@ -593,22 +593,22 @@
sleep 0.7
end
sleep 2
- job.last_work_time.should >= 0.7
- job.last_work_time.should < 0.8
+ expect(job.last_work_time).to be >= 0.7
+ expect(job.last_work_time).to be < 0.8
end
end
describe '#mean_work_time' do
it 'starts at 0' do
job = @scheduler.schedule_every '5m' do; end
- job.mean_work_time.should == 0.0
+ expect(job.mean_work_time).to eq(0.0)
end
it 'gathers work times and computes the mean' do
job =
@@ -618,13 +618,13 @@
sleep 0.01 * (j.count + 1)
end
sleep 4.6
- job.last_work_time.should >= 0.08
- job.last_work_time.should < 0.099
- job.mean_work_time.should > 0.05
- job.mean_work_time.should < 0.06
+ expect(job.last_work_time).to be >= 0.08
+ expect(job.last_work_time).to be < 0.099
+ expect(job.mean_work_time).to be > 0.05
+ expect(job.mean_work_time).to be < 0.06
end
end
end
end