diff --git a/spec/perfect_sched_spec.rb b/spec/perfect_sched_spec.rb index cd5e606..165215e 100644 --- a/spec/perfect_sched_spec.rb +++ b/spec/perfect_sched_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe PerfectSched do - context '.open' do + describe '.open' do let (:config){ double('config') } let (:client){ double('client') } let (:schedule_collection){ double('schedule_collection') } @@ -24,27 +24,51 @@ end end - context 'cron_time' do + describe '.cron_time' do it do - ts = PerfectSched.cron_time('0 * * * *', 0, nil) - expect(ts).not_to be_nil + ts = PerfectSched.cron_time('0 * * * *', 1, nil) + expect(ts).to eq 3600 end it do expect{PerfectSched.cron_time('0 * * * *', 0, 'JST-9')}.to raise_error(ArgumentError) end + it do + ts = PerfectSched.cron_time('0,30 * * * *', 1, nil) + expect(ts).to eq 1800 + end + it do + ts = PerfectSched.cron_time('*/7 * * * *', 1, nil) + expect(ts).to eq 420 + end + it do + ts = PerfectSched.cron_time('0-59/7 * * * *', 421, nil) + expect(ts).to eq 840 + end + it 'supports @hourly' do + ts = PerfectSched.cron_time('@hourly', 1, nil) + expect(ts).to eq 3600 + end + it 'supports @daily' do + ts = PerfectSched.cron_time('@daily', 1, nil) + expect(ts).to eq 86400 + end + it 'supports @monthly' do + ts = PerfectSched.cron_time('@monthly', 1, nil) + expect(ts).to eq 2678400 + end end - context '.next_time' do - it do - ts = PerfectSched.next_time('0 * * * *', 0, nil) - expect(ts).not_to be_nil + describe '.next_time' do + it 'can run hourly cron' do + ts = PerfectSched.next_time(' 0 * * * * ', 0, nil) + expect(ts).to eq 3600 end it 'calculates 4 years quickly' do t = Time.utc(2012,2,29) ts = PerfectSched.next_time('0 0 29 2 *', t.to_i, nil) expect(ts).to eq(Time.utc(2016,2,29).to_i) end - it do + it 'raises error on unsupported timezone' do expect{PerfectSched.next_time('0 * * * *', 0, 'JST-9')}.to raise_error(ArgumentError) end it 'returns next run time of given time' do