Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nurse committed Dec 8, 2015
1 parent 41006de commit 3a7d8f2
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions spec/perfect_sched_spec.rb
Original file line number Diff line number Diff line change
@@ -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') }
Expand All @@ -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
Expand Down

0 comments on commit 3a7d8f2

Please sign in to comment.