diff --git a/spec/cron_spec.lua b/spec/cron_spec.lua index 9b7287e..ff1a7e1 100644 --- a/spec/cron_spec.lua +++ b/spec/cron_spec.lua @@ -109,6 +109,37 @@ describe( 'cron', function() 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() it('Cancels timed entries', function() local id = cron.after(1, count)