1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
require 'clockwork'
require "minitest/autorun"
describe Clockwork::Event do
describe '#thread?' do
before do
@manager = Class.new
end
describe 'manager config thread option set to true' do
before do
@manager.stubs(:config).returns({ :thread => true })
end
it 'is true' do
event = Clockwork::Event.new(@manager, nil, nil, nil)
assert_equal true, event.thread?
end
it 'is false when event thread option set' do
event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => false)
assert_equal false, event.thread?
end
end
describe 'manager config thread option not set' do
before do
@manager.stubs(:config).returns({})
end
it 'is true if event thread option is true' do
event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => true)
assert_equal true, event.thread?
end
end
end
describe '#run_now?' do
before do
@manager = Class.new
@manager.stubs(:config).returns({})
end
describe 'event skip_first_run option set to true' do
it 'returns false on first attempt' do
event = Clockwork::Event.new(@manager, 1, nil, nil, :skip_first_run => true)
assert_equal false, event.run_now?(Time.now)
end
it 'returns true on subsequent attempts' do
event = Clockwork::Event.new(@manager, 1, nil, nil, :skip_first_run => true)
# first run
event.run_now?(Time.now)
# second run
assert_equal true, event.run_now?(Time.now + 1)
end
end
describe 'event skip_first_run option not set' do
it 'returns true on first attempt' do
event = Clockwork::Event.new(@manager, 1, nil, nil)
assert_equal true, event.run_now?(Time.now + 1)
end
end
describe 'event skip_first_run option set to false' do
it 'returns true on first attempt' do
event = Clockwork::Event.new(@manager, 1, nil, nil, :skip_first_run => false)
assert_equal true, event.run_now?(Time.now)
end
end
end
end
|