spec/job_repeat_spec.rb in rufus-scheduler-3.0.7 vs spec/job_repeat_spec.rb in rufus-scheduler-3.0.8

- old
+ new

@@ -26,19 +26,19 @@ job = @scheduler.schedule_every('0.5s') do counter += 1 end - counter.should == 0 + expect(counter).to eq(0) while counter < 1; sleep(0.1); end job.pause sleep(1) - counter.should == 1 + expect(counter).to eq(1) end end describe '#paused?' do @@ -46,18 +46,18 @@ job = @scheduler.schedule_every('10s') do; end job.pause - job.paused?.should == true + expect(job.paused?).to eq(true) end it 'returns false if the job is not paused' do job = @scheduler.schedule_every('10s') do; end - job.paused?.should == false + expect(job.paused?).to eq(false) end end describe '#resume' do @@ -73,20 +73,20 @@ job.pause job.resume sleep(1.5) - counter.should > 1 + expect(counter).to be > 1 end it 'has no effect on a not paused job' do job = @scheduler.schedule_every('10s') do; end job.resume - job.paused?.should == false + expect(job.paused?).to eq(false) end end describe ':times => i' do @@ -99,11 +99,11 @@ counter = counter + 1 end sleep(2.6) - counter.should == 3 + expect(counter).to eq(3) end it 'is OK when passed a nil instead of an integer' do counter = 0 @@ -113,18 +113,18 @@ counter = counter + 1 end sleep(2.5) - counter.should > 3 + expect(counter).to be > 3 end it 'raises when passed something else than nil or an integer' do - lambda { + expect { @scheduler.schedule_every '0.5s', :times => 'nada' do; end - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe ':first/:first_in/:first_at => point in time' do @@ -132,21 +132,21 @@ t = Time.now + 10 job = @scheduler.schedule_every '0.5s', :first => t do; end - job.first_at.should == t + expect(job.first_at).to eq(t) end it 'accepts a time string' do t = Time.now + 10 job = @scheduler.schedule_every '0.5s', :first => t.to_s do; end - job.first_at.to_s.should == t.to_s - job.first_at.zone.should == t.zone + expect(job.first_at.to_s).to eq(t.to_s) + expect(job.first_at.zone).to eq(t.zone) end it 'only lets the job trigger after the :first' do t = Time.now + 1.4 @@ -157,24 +157,24 @@ counter = counter + 1 end sleep(1) - counter.should == 0 + expect(counter).to eq(0) sleep(1) - counter.should > 0 + expect(counter).to be > 0 end it 'raises on points in the past' do - lambda { + expect { @scheduler.schedule_every '0.5s', :first => Time.now - 60 do; end - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end context ':first_time => :now/:immediately' do it 'schedules the first execution immediately' do @@ -185,18 +185,18 @@ job = @scheduler.schedule_every '7s', :first => :now do ft ||= Time.now end - sleep 0.5 + sleep 0.7 #p n.to_f #p job.first_at.to_f #p ft.to_f - job.first_at.should < n + 0.5 - ft.should < job.first_at + @scheduler.frequency + 0.1 + expect(job.first_at).to be < n + 0.7 + expect(ft).to be < job.first_at + @scheduler.frequency + 0.1 end end end describe ':first/:first_in/:first_at => duration' do @@ -205,40 +205,40 @@ t = Time.now job = @scheduler.schedule_every '0.5s', :first => '1h' do; end - job.first_at.should >= t + 3600 - job.first_at.should < t + 3601 + expect(job.first_at).to be >= t + 3600 + expect(job.first_at).to be < t + 3601 end it 'accepts a duration in seconds (integer)' do t = Time.now job = @scheduler.schedule_every '0.5s', :first => 3600 do; end - job.first_at.should >= t + 3600 - job.first_at.should < t + 3601 + expect(job.first_at).to be >= t + 3600 + expect(job.first_at).to be < t + 3601 end it 'raises if the argument cannot be used' do - lambda { + expect { @scheduler.every '0.5s', :first => :nada do; end - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe '#first_at=' do it 'can be used to set first_at directly' do job = @scheduler.schedule_every '0.5s', :first => 3600 do; end job.first_at = '2030-12-12 12:00:30' - job.first_at.strftime('%c').should == 'Thu Dec 12 12:00:30 2030' + expect(job.first_at.strftime('%c')).to eq('Thu Dec 12 12:00:30 2030') end end describe ':last/:last_in/:last_at => point in time' do @@ -246,11 +246,11 @@ t = Time.now + 10 job = @scheduler.schedule_every '0.5s', :last => t do; end - job.last_at.should == t + expect(job.last_at).to eq(t) end it 'unschedules the job after the last_at time' do t = Time.now + 2 @@ -265,32 +265,32 @@ end sleep 3 #counter.should == 3 - [ 3, 4 ].should include(counter) - tt.should < t - @scheduler.jobs.should_not include(job) + expect([ 3, 4 ]).to include(counter) + expect(tt).to be < t + expect(@scheduler.jobs).not_to include(job) end it 'accepts a time string' do t = Time.now + 10 job = @scheduler.schedule_every '0.5s', :last => t.to_s do; end - job.last_at.to_s.should == t.to_s - job.last_at.zone.should == t.zone + expect(job.last_at.to_s).to eq(t.to_s) + expect(job.last_at.zone).to eq(t.zone) end it 'raises on a point in the past' do - lambda { + expect { @scheduler.every '0.5s', :last => Time.now - 60 do; end - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe ':last/:last_in/:last_at => duration' do @@ -298,58 +298,59 @@ t = Time.now job = @scheduler.schedule_every '0.5s', :last_in => '2s' do; end - job.last_at.should >= t + 2 - job.last_at.should < t + 2.5 + expect(job.last_at).to be >= t + 2 + expect(job.last_at).to be < t + 2.5 end it 'accepts a duration in seconds (integer)' do t = Time.now job = @scheduler.schedule_every '0.5s', :last_in => 2.0 do; end - job.last_at.should >= t + 2 - job.last_at.should < t + 2.5 + expect(job.last_at).to be >= t + 2 + expect(job.last_at).to be < t + 2.5 end it 'raises if the argument is worthless' do - lambda { + expect { @scheduler.every '0.5s', :last => :nada do; end - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe '#last_at=' do it 'can be used to set last_at directly' do job = @scheduler.schedule_every '0.5s', :last_in => 10.0 do; end job.last_at = '2030-12-12 12:00:30' - job.last_at.strftime('%c').should == 'Thu Dec 12 12:00:30 2030' + expect(job.last_at.strftime('%c')).to eq('Thu Dec 12 12:00:30 2030') end end describe '#count' do it 'starts at 0' do job = @scheduler.schedule_every '5m' do; end - job.count.should == 0 + expect(job.count).to eq(0) end it 'keeps track of how many times the job fired' do job = @scheduler.schedule_every '0.5s' do; end sleep(2.0) - job.count.should == 3 + expect(job.count).to be >= 3 + expect(job.count).to be <= 4 end end end