From 0f4bc8fd5391491921f8e0fda3f231564460b6a1 Mon Sep 17 00:00:00 2001 From: Tanner Rogalsky Date: Tue, 11 Jun 2013 12:41:58 -0400 Subject: [PATCH] Write some tests for the new function. --- spec/cron_spec.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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)