Write some tests for the new function.

This commit is contained in:
Tanner Rogalsky 2013-06-11 12:41:58 -04:00
parent 0c1f7a5e88
commit 0f4bc8fd53

View File

@ -109,6 +109,37 @@ describe( 'cron', function()
end) end)
end) end)
describe('.doFor', function()
it('Throws errors if time is not a positive number, or callback is not function', function()
assert_error(function() cron.every('error', count) end)
assert_error(function() cron.every(2, 'error') end)
assert_error(function() cron.every(-2, count) end)
assert_error(function() cron.every(-2, {}) end)
assert_not_error(function() cron.every(2, count) end)
assert_not_error(function() cron.every(2, countable) end)
end)
it('Executes actions on every update until the timer expires', function()
cron.doFor(5, count)
assert_equal(counter, 0)
cron.update(1)
assert_equal(counter, 1)
cron.update(3)
assert_equal(counter, 2)
cron.update(3)
assert_equal(counter, 3)
cron.update(1)
assert_equal(counter, 3)
end)
it('Respects parameters', function()
cron.doFor(4, count, 2)
cron.update(1)
cron.update(1)
assert_equal(counter, 4)
end)
end)
describe('.cancel', function() describe('.cancel', function()
it('Cancels timed entries', function() it('Cancels timed entries', function()
local id = cron.after(1, count) local id = cron.after(1, count)